From 501e5d28c53a8658d100179ea3de7c42ba29a8ff Mon Sep 17 00:00:00 2001 From: Ivan Gomes Date: Thu, 6 Oct 2022 23:04:51 -0400 Subject: [PATCH] feat(groups): allow all printable ASCII characters in group name --- .../org/openmbee/mms/groups/constants/GroupConstants.java | 2 +- .../mms/groups/services/GroupValidationService.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/groups/src/main/java/org/openmbee/mms/groups/constants/GroupConstants.java b/groups/src/main/java/org/openmbee/mms/groups/constants/GroupConstants.java index 1df64f07b..2e75c4027 100644 --- a/groups/src/main/java/org/openmbee/mms/groups/constants/GroupConstants.java +++ b/groups/src/main/java/org/openmbee/mms/groups/constants/GroupConstants.java @@ -6,7 +6,7 @@ public class GroupConstants { public static final String GROUP_NOT_EMPTY = "Group is not empty"; public static final String GROUP_NOT_FOUND = "Group not found"; public static final String INVALID_ACTION = "Invalid action"; - public static final String INVALID_GROUP_NAME= "Invalid group name"; + public static final String INVALID_GROUP_NAME = "Invalid group name"; public static final String NAME = "name"; public static final String NO_USERS_PROVIDED = "No users provided"; public static final String RESTRICTED_GROUP = "Restricted group"; diff --git a/groups/src/main/java/org/openmbee/mms/groups/services/GroupValidationService.java b/groups/src/main/java/org/openmbee/mms/groups/services/GroupValidationService.java index 6e6251d5c..ae40f307c 100644 --- a/groups/src/main/java/org/openmbee/mms/groups/services/GroupValidationService.java +++ b/groups/src/main/java/org/openmbee/mms/groups/services/GroupValidationService.java @@ -12,20 +12,20 @@ @Service public class GroupValidationService { - private static final Set RESTRICTED_NAMES = Set.of(MMSADMIN, EVERYONE); - private Pattern VALID_GROUP_NAME_PATTERN = Pattern.compile("^[\\w-]+"); + private static final Set RESTRICTED_NAMES = Set.of(MMSADMIN, EVERYONE); + private final Pattern VALID_GROUP_NAME_PATTERN = Pattern.compile("^[ -~]+"); public boolean isRestrictedGroup(String groupName) { return RESTRICTED_NAMES.contains(groupName); } - public boolean isValidGroupName(String groupName){ + public boolean isValidGroupName(String groupName) { return groupName != null && !isRestrictedGroup(groupName) && VALID_GROUP_NAME_PATTERN.matcher(groupName).matches(); } - public boolean canDeleteGroup(Group group){ + public boolean canDeleteGroup(Group group) { return !isRestrictedGroup(group.getName()) && (group.getUsers() == null || group.getUsers().isEmpty()); }