destroying.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from django.utils.translation import ugettext_lazy as _
  2. from misago.acl import algebra
  3. from misago.acl.models import Role
  4. from misago.core import forms
  5. """
  6. Admin Permissions Form
  7. """
  8. class PermissionsForm(forms.Form):
  9. legend = _("Destroying user accounts")
  10. can_destroy_user_newer_than = forms.IntegerField(
  11. label=_("Maximum age of destroyed account (in days)"),
  12. help_text=_("Enter zero to disable this check."),
  13. min_value=0,
  14. initial=0)
  15. can_destroy_users_with_less_posts_than = forms.IntegerField(
  16. label=_("Maximum number of posts on destroyed account"),
  17. help_text=_("Enter zero to disable this check."),
  18. min_value=0,
  19. initial=0)
  20. def change_permissions_form(role):
  21. if isinstance(role, Role) and role.special_role != 'anonymous':
  22. return PermissionsForm
  23. else:
  24. return None
  25. """
  26. ACL Builder
  27. """
  28. def build_acl(acl, roles, key_name):
  29. new_acl = {
  30. 'can_destroy_user_newer_than': 0,
  31. 'can_destroy_users_with_less_posts_than': 0,
  32. }
  33. new_acl.update(acl)
  34. return algebra.sum_acls(
  35. new_acl, roles=roles, key=key_name,
  36. can_destroy_user_newer_than=algebra.greater,
  37. can_destroy_users_with_less_posts_than=algebra.greater
  38. )