apps.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. visible_if=can_delete_own_account,
  57. )
  58. def register_default_users_list_pages(self):
  59. users_list.add_section(
  60. link="misago:users-active-posters",
  61. component="active-posters",
  62. name=_("Active poster"),
  63. )
  64. def register_default_user_profile_pages(self):
  65. def can_see_names_history(request, profile):
  66. if request.user.is_authenticated:
  67. is_account_owner = profile.pk == request.user.pk
  68. has_permission = request.user_acl["can_see_users_name_history"]
  69. return is_account_owner or has_permission
  70. return False
  71. def can_see_ban_details(request, profile):
  72. if request.user.is_authenticated:
  73. if request.user_acl["can_see_ban_details"]:
  74. from .bans import get_user_ban
  75. return bool(get_user_ban(profile, request.cache_versions))
  76. return False
  77. return False
  78. user_profile.add_section(
  79. link="misago:user-posts", name=_("Posts"), icon="message", component="posts"
  80. )
  81. user_profile.add_section(
  82. link="misago:user-threads",
  83. name=_("Threads"),
  84. icon="forum",
  85. component="threads",
  86. )
  87. user_profile.add_section(
  88. link="misago:user-followers",
  89. name=_("Followers"),
  90. icon="favorite",
  91. component="followers",
  92. )
  93. user_profile.add_section(
  94. link="misago:user-follows",
  95. name=_("Follows"),
  96. icon="favorite_border",
  97. component="follows",
  98. )
  99. user_profile.add_section(
  100. link="misago:user-details",
  101. name=_("Details"),
  102. icon="person_outline",
  103. component="details",
  104. )
  105. user_profile.add_section(
  106. link="misago:username-history",
  107. name=_("Username history"),
  108. icon="card_membership",
  109. component="username-history",
  110. visible_if=can_see_names_history,
  111. )
  112. user_profile.add_section(
  113. link="misago:user-ban",
  114. name=_("Ban details"),
  115. icon="remove_circle_outline",
  116. component="ban-details",
  117. visible_if=can_see_ban_details,
  118. )