privatethreads.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from django.utils.translation import ugettext_lazy as _
  2. from misago.acl import add_acl, algebra
  3. from misago.acl.decorators import return_boolean
  4. from misago.acl.models import Role
  5. from misago.core import forms
  6. __all__ = [
  7. ]
  8. """
  9. Admin Permissions Form
  10. """
  11. class PermissionsForm(forms.Form):
  12. legend = _("Private threads")
  13. can_use_private_threads = forms.YesNoSwitch(
  14. label=_("Can use private threads"))
  15. can_start_private_threads = forms.YesNoSwitch(
  16. label=_("Can start private threads"))
  17. max_private_thread_participants = forms.IntegerField(
  18. label=_("Max number of users invited to private thread"),
  19. help_text=_("Enter 0 to don't limit number of participants."),
  20. initial=3,
  21. min_value=0)
  22. can_add_everyone_to_private_threads = forms.YesNoSwitch(
  23. label=_("Can add everyone to threads"),
  24. help_text=_("Allows user to add users that are "
  25. "blocking him to private threads."))
  26. can_report_private_threads = forms.YesNoSwitch(
  27. label=_("Can report private threads"),
  28. help_text=_("Allows user to report private threads they are "
  29. "participating in, making them accessible to moderators."))
  30. can_moderate_private_threads = forms.YesNoSwitch(
  31. label=_("Allows user to read, reply, edit and delete "
  32. "content in reported private threads."))
  33. def change_permissions_form(role):
  34. if isinstance(role, Role) and role.special_role != 'anonymous':
  35. return PermissionsForm
  36. else:
  37. return None
  38. """
  39. ACL Builder
  40. """
  41. def build_acl(acl, roles, key_name):
  42. new_acl = {
  43. 'can_use_private_threads': 0,
  44. 'can_start_private_threads': 0,
  45. 'max_private_thread_participants': 3,
  46. 'can_add_everyone_to_private_threads': 0,
  47. 'can_report_private_threads': 0,
  48. 'can_moderate_private_threads': 0,
  49. }
  50. new_acl.update(acl)
  51. algebra.sum_acls(new_acl, roles=roles, key=key_name,
  52. can_use_private_threads=algebra.greater,
  53. can_start_private_threads=algebra.greater,
  54. max_private_thread_participants=algebra.greater_or_zero,
  55. can_add_everyone_to_private_threads=algebra.greater,
  56. can_report_private_threads=algebra.greater,
  57. can_moderate_private_threads=algebra.greater
  58. )
  59. return new_acl