account.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. from django import forms
  2. from django.utils.translation import ugettext_lazy as _
  3. from misago.acl import algebra
  4. from misago.acl.models import Role
  5. from misago.core.forms import YesNoSwitch
  6. """
  7. Admin Permissions Form
  8. """
  9. class PermissionsForm(forms.Form):
  10. legend = _("Account settings")
  11. name_changes_allowed = forms.IntegerField(
  12. label=_("Allowed username changes number"), min_value=0, initial=1
  13. )
  14. name_changes_expire = forms.IntegerField(
  15. label=_("Don't count username changes older than"),
  16. help_text=_(
  17. "Number of days since name change that makes "
  18. "that change no longer count to limit. Enter "
  19. "zero to make all changes count."
  20. ),
  21. min_value=0,
  22. initial=0
  23. )
  24. can_have_signature = YesNoSwitch(label=_("Can have signature"))
  25. allow_signature_links = YesNoSwitch(label=_("Can put links in signature"))
  26. allow_signature_images = YesNoSwitch(label=_("Can put images in signature"))
  27. allow_signature_blocks = YesNoSwitch(
  28. label=_("Can use text blocks in signature"),
  29. help_text=_(
  30. "Controls whether or not users can put quote, code, "
  31. "spoiler blocks and horizontal lines in signatures."
  32. )
  33. )
  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. 'name_changes_allowed': 0,
  45. 'name_changes_expire': 0,
  46. 'can_have_signature': 0,
  47. 'allow_signature_links': 0,
  48. 'allow_signature_images': 0,
  49. 'allow_signature_blocks': 0,
  50. }
  51. new_acl.update(acl)
  52. return algebra.sum_acls(
  53. new_acl,
  54. roles=roles,
  55. key=key_name,
  56. name_changes_allowed=algebra.greater,
  57. name_changes_expire=algebra.lower_non_zero,
  58. can_have_signature=algebra.greater,
  59. allow_signature_links=algebra.greater,
  60. allow_signature_images=algebra.greater,
  61. allow_signature_blocks=algebra.greater
  62. )