Add method to extract group name from a configured value

Change-Id: I4c78383f1a71670fe0c3cc68d88e40e5e849cf97
This commit is contained in:
Hugo Arès
2017-06-19 11:21:08 -04:00
parent 2c8f60591a
commit 9aba030311
3 changed files with 14 additions and 5 deletions

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.common.data;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.reviewdb.client.AccountGroup;
/** Describes a group within a projects {@link AccessSection}s. */
@@ -34,6 +35,14 @@ public class GroupReference implements Comparable<GroupReference> {
return configValue != null && configValue.startsWith(PREFIX);
}
@Nullable
public static String extractGroupName(String configValue) {
if (!isGroupReference(configValue)) {
return null;
}
return configValue.substring(PREFIX.length()).trim();
}
public static GroupReference fromString(String ref) {
String name = ref.substring(ref.indexOf("[") + 1, ref.lastIndexOf("/")).trim();
String uuid = ref.substring(ref.lastIndexOf("/") + 1, ref.lastIndexOf("]")).trim();

View File

@@ -254,10 +254,10 @@ public class PermissionRule implements Comparable<PermissionRule> {
src = src.substring(sp + 1).trim();
}
if (GroupReference.isGroupReference(src)) {
src = src.substring(6).trim();
String groupName = GroupReference.extractGroupName(src);
if (groupName != null) {
GroupReference group = new GroupReference();
group.setName(src);
group.setName(groupName);
rule.setGroup(group);
} else {
throw new IllegalArgumentException("Rule must include group: " + orig);

View File

@@ -640,8 +640,8 @@ public class ProjectConfig extends VersionedMetaData implements ValidationError.
n.setHeader(rc.getEnum(NOTIFY, sectionName, KEY_HEADER, NotifyConfig.Header.BCC));
for (String dst : rc.getStringList(NOTIFY, sectionName, KEY_EMAIL)) {
if (GroupReference.isGroupReference(dst)) {
String groupName = dst.substring(6).trim();
String groupName = GroupReference.extractGroupName(dst);
if (groupName != null) {
GroupReference ref = groupsByName.get(groupName);
if (ref == null) {
ref = new GroupReference(null, groupName);