account.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from django import forms
  2. from django.utils.translation import gettext_lazy as _
  3. from ...acl import algebra
  4. from ...acl.models import Role
  5. from ...admin.forms import YesNoSwitch
  6. class PermissionsForm(forms.Form):
  7. legend = _("Account settings")
  8. name_changes_allowed = forms.IntegerField(
  9. label=_("Allowed username changes number"), min_value=0, initial=1
  10. )
  11. name_changes_expire = forms.IntegerField(
  12. label=_("Don't count username changes older than"),
  13. help_text=_(
  14. "Number of days since name change that makes "
  15. "that change no longer count to limit. Enter "
  16. "zero to make all changes count."
  17. ),
  18. min_value=0,
  19. initial=0,
  20. )
  21. can_have_signature = YesNoSwitch(label=_("Can have signature"))
  22. allow_signature_links = YesNoSwitch(label=_("Can put links in signature"))
  23. allow_signature_images = YesNoSwitch(label=_("Can put images in signature"))
  24. allow_signature_blocks = YesNoSwitch(
  25. label=_("Can use text blocks in signature"),
  26. help_text=_(
  27. "Controls whether or not users can put quote, code, "
  28. "spoiler blocks and horizontal lines in signatures."
  29. ),
  30. )
  31. def change_permissions_form(role):
  32. if isinstance(role, Role) and role.special_role != "anonymous":
  33. return PermissionsForm
  34. def build_acl(acl, roles, key_name):
  35. new_acl = {
  36. "name_changes_allowed": 0,
  37. "name_changes_expire": 0,
  38. "can_have_signature": 0,
  39. "allow_signature_links": 0,
  40. "allow_signature_images": 0,
  41. "allow_signature_blocks": 0,
  42. }
  43. new_acl.update(acl)
  44. return algebra.sum_acls(
  45. new_acl,
  46. roles=roles,
  47. key=key_name,
  48. name_changes_allowed=algebra.greater,
  49. name_changes_expire=algebra.lower_non_zero,
  50. can_have_signature=algebra.greater,
  51. allow_signature_links=algebra.greater,
  52. allow_signature_images=algebra.greater,
  53. allow_signature_blocks=algebra.greater,
  54. )