account.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from django import forms
  2. from django.utils.translation import gettext_lazy as _
  3. from misago.acl import algebra
  4. from misago.acl.models import Role
  5. from misago.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. else:
  35. return None
  36. def build_acl(acl, roles, key_name):
  37. new_acl = {
  38. "name_changes_allowed": 0,
  39. "name_changes_expire": 0,
  40. "can_have_signature": 0,
  41. "allow_signature_links": 0,
  42. "allow_signature_images": 0,
  43. "allow_signature_blocks": 0,
  44. }
  45. new_acl.update(acl)
  46. return algebra.sum_acls(
  47. new_acl,
  48. roles=roles,
  49. key=key_name,
  50. name_changes_allowed=algebra.greater,
  51. name_changes_expire=algebra.lower_non_zero,
  52. can_have_signature=algebra.greater,
  53. allow_signature_links=algebra.greater,
  54. allow_signature_images=algebra.greater,
  55. allow_signature_blocks=algebra.greater,
  56. )