apps.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. from django.apps import AppConfig
  2. from django.utils.translation import gettext_lazy as _
  3. from ..conf import settings
  4. from .pages import user_profile, usercp, users_list
  5. class MisagoUsersConfig(AppConfig):
  6. name = "misago.users"
  7. label = "misago_users"
  8. verbose_name = "Misago Auth"
  9. def ready(self):
  10. from . import signals as _
  11. from .admin import tasks # pylint: disable=unused-import
  12. self.register_default_usercp_pages()
  13. self.register_default_users_list_pages()
  14. self.register_default_user_profile_pages()
  15. def register_default_usercp_pages(self):
  16. usercp.add_section(
  17. link="misago:usercp-change-forum-options",
  18. name=_("Forum options"),
  19. component="forum-options",
  20. icon="settings",
  21. )
  22. usercp.add_section(
  23. link="misago:usercp-edit-details",
  24. name=_("Edit details"),
  25. component="edit-details",
  26. icon="person_outline",
  27. )
  28. usercp.add_section(
  29. link="misago:usercp-change-username",
  30. name=_("Change username"),
  31. component="change-username",
  32. icon="card_membership",
  33. )
  34. usercp.add_section(
  35. link="misago:usercp-change-email-password",
  36. name=_("Change email or password"),
  37. component="sign-in-credentials",
  38. icon="vpn_key",
  39. )
  40. def can_download_own_data(request):
  41. return request.settings.allow_data_downloads
  42. usercp.add_section(
  43. link="misago:usercp-download-data",
  44. name=_("Download data"),
  45. component="download-data",
  46. icon="save_alt",
  47. visible_if=can_download_own_data,
  48. )
  49. def can_delete_own_account(request):
  50. return request.settings.allow_delete_own_account
  51. usercp.add_section(
  52. link="misago:usercp-delete-account",
  53. name=_("Delete account"),
  54. component="delete-account",
  55. icon="cancel",
  56. )
  57. def register_default_users_list_pages(self):
  58. users_list.add_section(
  59. link="misago:users-active-posters",
  60. component="active-posters",
  61. name=_("Top posters"),
  62. )
  63. def register_default_user_profile_pages(self):
  64. def can_see_names_history(request, profile):
  65. if request.user.is_authenticated:
  66. is_account_owner = profile.pk == request.user.pk
  67. has_permission = request.user_acl["can_see_users_name_history"]
  68. return is_account_owner or has_permission
  69. return False
  70. def can_see_ban_details(request, profile):
  71. if request.user.is_authenticated:
  72. if request.user_acl["can_see_ban_details"]:
  73. from .bans import get_user_ban
  74. return bool(get_user_ban(profile, request.cache_versions))
  75. return False
  76. return False
  77. user_profile.add_section(
  78. link="misago:user-posts", name=_("Posts"), icon="message", component="posts"
  79. )
  80. user_profile.add_section(
  81. link="misago:user-threads",
  82. name=_("Threads"),
  83. icon="forum",
  84. component="threads",
  85. )
  86. user_profile.add_section(
  87. link="misago:user-followers",
  88. name=_("Followers"),
  89. icon="favorite",
  90. component="followers",
  91. )
  92. user_profile.add_section(
  93. link="misago:user-follows",
  94. name=_("Follows"),
  95. icon="favorite_border",
  96. component="follows",
  97. )
  98. user_profile.add_section(
  99. link="misago:user-details",
  100. name=_("Details"),
  101. icon="person_outline",
  102. component="details",
  103. )
  104. user_profile.add_section(
  105. link="misago:username-history",
  106. name=_("Username history"),
  107. icon="card_membership",
  108. component="username-history",
  109. visible_if=can_see_names_history,
  110. )
  111. user_profile.add_section(
  112. link="misago:user-ban",
  113. name=_("Ban details"),
  114. icon="remove_circle_outline",
  115. component="ban-details",
  116. visible_if=can_see_ban_details,
  117. )