|
@@ -21,6 +21,9 @@ class PermissionsForm(forms.Form):
|
|
|
legend = _("Users moderation")
|
|
|
|
|
|
can_rename_users = forms.YesNoSwitch(label=_("Can rename users"))
|
|
|
+ can_moderate_avatars = forms.YesNoSwitch(label=_("Can moderate avatars"))
|
|
|
+ can_moderate_signatures = forms.YesNoSwitch(
|
|
|
+ label=_("Can moderate signatures"))
|
|
|
can_ban_users = forms.YesNoSwitch(label=_("Can ban users"))
|
|
|
max_ban_length = forms.IntegerField(
|
|
|
label=_("Max length, in days, of imposed ban"),
|
|
@@ -48,6 +51,8 @@ ACL Builder
|
|
|
def build_acl(acl, roles, key_name):
|
|
|
new_acl = {
|
|
|
'can_rename_users': 0,
|
|
|
+ 'can_moderate_avatars': 0,
|
|
|
+ 'can_moderate_signatures': 0,
|
|
|
'can_ban_users': 0,
|
|
|
'max_ban_length': 2,
|
|
|
'can_lift_bans': 0,
|
|
@@ -58,6 +63,8 @@ def build_acl(acl, roles, key_name):
|
|
|
return algebra.sum_acls(
|
|
|
new_acl, roles=roles, key=key_name,
|
|
|
can_rename_users=algebra.greater,
|
|
|
+ can_moderate_avatars=algebra.greater,
|
|
|
+ can_moderate_signatures=algebra.greater,
|
|
|
can_ban_users=algebra.greater,
|
|
|
max_ban_length=algebra.greater_or_zero,
|
|
|
can_lift_bans=algebra.greater,
|
|
@@ -70,14 +77,25 @@ ACL's for targets
|
|
|
"""
|
|
|
@require_target_type(get_user_model())
|
|
|
def add_acl_to_target(user, acl, target):
|
|
|
- target.acl_['can_rename'] = can_rename_user(user, target)
|
|
|
- target.acl_['can_ban'] = can_ban_user(user, target)
|
|
|
- target.acl_['max_ban_length'] = user.acl['max_ban_length']
|
|
|
- target.acl_['can_lift_ban'] = can_lift_ban(user, target)
|
|
|
-
|
|
|
- for permission in ('can_rename', 'can_ban'):
|
|
|
- if target.acl_[permission]:
|
|
|
- target.acl_['can_moderate'] = True
|
|
|
+ target_acl = target.acl_
|
|
|
+
|
|
|
+ target_acl['can_rename'] = can_rename_user(user, target)
|
|
|
+ target_acl['can_moderate_avatar'] = can_moderate_avatar(user, target)
|
|
|
+ target_acl['can_moderate_signature'] = can_moderate_signature(user, target)
|
|
|
+ target_acl['can_ban'] = can_ban_user(user, target)
|
|
|
+ target_acl['max_ban_length'] = user.acl['max_ban_length']
|
|
|
+ target_acl['can_lift_ban'] = can_lift_ban(user, target)
|
|
|
+
|
|
|
+ mod_permissions = (
|
|
|
+ 'can_rename',
|
|
|
+ 'can_moderate_avatar',
|
|
|
+ 'can_moderate_signature',
|
|
|
+ 'can_ban',
|
|
|
+ )
|
|
|
+
|
|
|
+ for permission in mod_permissions:
|
|
|
+ if target_acl[permission]:
|
|
|
+ target_acl['can_moderate'] = True
|
|
|
break
|
|
|
|
|
|
|
|
@@ -92,6 +110,23 @@ def allow_rename_user(user, target):
|
|
|
can_rename_user = return_boolean(allow_rename_user)
|
|
|
|
|
|
|
|
|
+def allow_moderate_avatar(user, target):
|
|
|
+ if not user.acl['can_moderate_avatars']:
|
|
|
+ raise PermissionDenied(_("You can't moderate avatars."))
|
|
|
+ if not user.is_superuser and (target.is_staff or target.is_superuser):
|
|
|
+ raise PermissionDenied(_("You can't moderate administrators avatars."))
|
|
|
+can_moderate_avatar = return_boolean(allow_moderate_avatar)
|
|
|
+
|
|
|
+
|
|
|
+def allow_moderate_signature(user, target):
|
|
|
+ if not user.acl['can_moderate_signatures']:
|
|
|
+ raise PermissionDenied(_("You can't moderate signatures."))
|
|
|
+ if not user.is_superuser and (target.is_staff or target.is_superuser):
|
|
|
+ message = _("You can't moderate administrators signatures.")
|
|
|
+ raise PermissionDenied(message)
|
|
|
+can_moderate_signature = return_boolean(allow_moderate_signature)
|
|
|
+
|
|
|
+
|
|
|
def allow_ban_user(user, target):
|
|
|
if not user.acl['can_ban_users']:
|
|
|
raise PermissionDenied(_("You can't ban users."))
|