privatethreads.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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=_("Can moderate private threads"),
  32. help_text=_("Allows user to read, reply, edit and delete "
  33. "content in reported private threads."))
  34. def change_permissions_form(role):
  35. if isinstance(role, Role) and role.special_role != 'anonymous':
  36. return PermissionsForm
  37. else:
  38. return None
  39. """
  40. ACL Builder
  41. """
  42. def build_acl(acl, roles, key_name):
  43. new_acl = {
  44. 'can_use_private_threads': 0,
  45. 'can_start_private_threads': 0,
  46. 'max_private_thread_participants': 3,
  47. 'can_add_everyone_to_private_threads': 0,
  48. 'can_report_private_threads': 0,
  49. 'can_moderate_private_threads': 0,
  50. }
  51. new_acl.update(acl)
  52. algebra.sum_acls(new_acl, roles=roles, key=key_name,
  53. can_use_private_threads=algebra.greater,
  54. can_start_private_threads=algebra.greater,
  55. max_private_thread_participants=algebra.greater_or_zero,
  56. can_add_everyone_to_private_threads=algebra.greater,
  57. can_report_private_threads=algebra.greater,
  58. can_moderate_private_threads=algebra.greater
  59. )
  60. return new_acl