models: Use COMMON_POLICY_TYPES for user_group_edit_policy.

This commit adds moderators and full members options for
user_group_edit_policy by using COMMON_POLICY_TYPES.

Moderators do not require to be a member of user group in
order to edit or remove the user group if they are allowed
to do so according to user_group_edit_policy.
But full members need to be a member of user group to edit
or remove the user group.
This commit is contained in:
sahil839
2021-05-21 10:32:43 +05:30
committed by Tim Abbott
parent 93a1479286
commit 50240ca71b
8 changed files with 310 additions and 223 deletions

View File

@@ -11,7 +11,11 @@ def access_user_group_by_id(user_group_id: int, user_profile: UserProfile) -> Us
try:
user_group = UserGroup.objects.get(id=user_group_id, realm=user_profile.realm)
group_member_ids = get_user_group_members(user_group)
if not user_profile.is_realm_admin and user_profile.id not in group_member_ids:
if (
not user_profile.is_realm_admin
and not user_profile.is_moderator
and user_profile.id not in group_member_ids
):
raise JsonableError(_("Insufficient permission"))
except UserGroup.DoesNotExist:
raise JsonableError(_("Invalid user group"))