user_groups: Add API restrictions for long user group names.

Previously we had database level restriction on length of
user group names. Now we add the same restriction to API
level as well, so we can return a better error response.
This commit is contained in:
Sahil Batra
2023-07-03 11:31:01 +05:30
committed by Tim Abbott
parent 89381a8072
commit ea3a7a9e6f
4 changed files with 29 additions and 1 deletions

View File

@@ -101,6 +101,15 @@ def access_user_group_for_setting(
return user_group
def check_user_group_name(group_name: str) -> str:
if len(group_name) > UserGroup.MAX_NAME_LENGTH:
raise JsonableError(
_("User group name cannot exceed {} characters.").format(UserGroup.MAX_NAME_LENGTH)
)
return group_name
def user_groups_in_realm_serialized(realm: Realm) -> List[UserGroupDict]:
"""This function is used in do_events_register code path so this code
should be performant. We need to do 2 database queries because