user_group: Change error message to "Insufficient permission".

There is no need to have a error message which specifies the
roles having permission to edit user-groups, we can simply
have error message as "Insufficient permission" as we already
show the roles having permission clearly in UI.
This commit is contained in:
sahil839 2021-06-30 12:43:19 +05:30 committed by Tim Abbott
parent 1148937c7b
commit 93a1479286
2 changed files with 5 additions and 14 deletions

View File

@ -11,9 +11,8 @@ 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)
msg = _("Only group members and organization administrators can administer this group.")
if not user_profile.is_realm_admin and user_profile.id not in group_member_ids:
raise JsonableError(msg)
raise JsonableError(_("Insufficient permission"))
except UserGroup.DoesNotExist:
raise JsonableError(_("Invalid user group"))
return user_group

View File

@ -178,9 +178,7 @@ class UserGroupAPITestCase(ZulipTestCase):
"description": "Troubleshooting",
}
result = self.client_patch(f"/json/user_groups/{user_group.id}", info=params)
self.assert_json_error(
result, "Only group members and organization administrators can administer this group."
)
self.assert_json_error(result, "Insufficient permission")
self.logout()
# Test when organization admin tries to modify group
@ -264,9 +262,7 @@ class UserGroupAPITestCase(ZulipTestCase):
self.login_user(cordelia)
result = self.client_delete(f"/json/user_groups/{user_group.id}")
self.assert_json_error(
result, "Only group members and organization administrators can administer this group."
)
self.assert_json_error(result, "Insufficient permission")
self.assertEqual(UserGroup.objects.count(), 2)
self.logout()
@ -333,9 +329,7 @@ class UserGroupAPITestCase(ZulipTestCase):
add = [cordelia.id]
params = {"add": orjson.dumps(add).decode()}
result = self.client_post(f"/json/user_groups/{user_group.id}/members", info=params)
self.assert_json_error(
result, "Only group members and organization administrators can administer this group."
)
self.assert_json_error(result, "Insufficient permission")
self.assertEqual(UserGroupMembership.objects.count(), 4)
self.logout()
@ -380,9 +374,7 @@ class UserGroupAPITestCase(ZulipTestCase):
self.login_user(cordelia)
params = {"delete": orjson.dumps([hamlet.id]).decode()}
result = self.client_post(f"/json/user_groups/{user_group.id}/members", info=params)
self.assert_json_error(
result, "Only group members and organization administrators can administer this group."
)
self.assert_json_error(result, "Insufficient permission")
self.assertEqual(UserGroupMembership.objects.count(), 4)
self.logout()