Skip to content

Commit

Permalink
Merge pull request #209 from Open-MBEE/feature/208
Browse files Browse the repository at this point in the history
feat(groups): allow all printable ASCII characters in group name
  • Loading branch information
HuiJun authored Oct 7, 2022
2 parents 5bd2995 + 501e5d2 commit 2ac9a98
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
@Service
public class GroupValidationService {

private static final Set<String> RESTRICTED_NAMES = Set.of(MMSADMIN, EVERYONE);
private Pattern VALID_GROUP_NAME_PATTERN = Pattern.compile("^[\\w-]+");
private static final Set<String> 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());
}
Expand Down

0 comments on commit 2ac9a98

Please sign in to comment.