use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class ProjectConfig method updateGroupNames.
/**
* Check all GroupReferences use current group name, repairing stale ones.
*
* @param groupBackend cache to use when looking up group information by UUID.
* @return true if one or more group names was stale.
*/
public boolean updateGroupNames(GroupBackend groupBackend) {
boolean dirty = false;
for (GroupReference ref : groupList.references()) {
GroupDescription.Basic g = groupBackend.get(ref.getUUID());
if (g != null && !g.getName().equals(ref.getName())) {
dirty = true;
groupList.renameGroup(ref.getUUID(), g.getName());
}
}
return dirty;
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class ProjectConfig method loadPluginSections.
private void loadPluginSections(Config rc) {
pluginConfigs = new HashMap<>();
for (String plugin : rc.getSubsections(PLUGIN)) {
Config pluginConfig = new Config();
pluginConfigs.put(plugin, pluginConfig);
for (String name : rc.getNames(PLUGIN, plugin)) {
String value = rc.getString(PLUGIN, plugin, name);
String groupName = GroupReference.extractGroupName(value);
if (groupName != null) {
GroupReference ref = groupList.byName(groupName);
if (ref == null) {
error(String.format("group \"%s\" not in %s", groupName, GroupList.FILE_NAME));
}
rc.setString(PLUGIN, plugin, name, value);
}
pluginConfig.setStringList(PLUGIN, plugin, name, Arrays.asList(rc.getStringList(PLUGIN, plugin, name)));
}
}
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class ProjectConfig method loadPermissionRules.
private void loadPermissionRules(Config rc, String section, String subsection, String varName, Permission.Builder perm, boolean useRange) {
for (String ruleString : rc.getStringList(section, subsection, varName)) {
PermissionRule rule;
try {
rule = PermissionRule.fromString(ruleString, useRange);
} catch (IllegalArgumentException notRule) {
error(String.format("Invalid rule in %s.%s: %s", section + (subsection != null ? "." + subsection : ""), varName, notRule.getMessage()));
continue;
}
GroupReference ref = groupList.byName(rule.getGroup().getName());
if (ref == null) {
// The group wasn't mentioned in the groups table, so there is
// no valid UUID for it. Pool the reference anyway so at least
// all rules in the same file share the same GroupReference.
//
ref = groupList.resolve(rule.getGroup());
error(String.format("group \"%s\" not in %s", ref.getName(), GroupList.FILE_NAME));
}
perm.add(rule.toBuilder().setGroup(ref));
}
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class ProjectConfig method saveAccessSections.
private void saveAccessSections(Config rc, Set<AccountGroup.UUID> keepGroups) {
unsetSection(rc, CAPABILITY);
AccessSection capability = accessSections.get(AccessSection.GLOBAL_CAPABILITIES);
if (capability != null) {
Set<String> have = new HashSet<>();
for (Permission permission : sort(capability.getPermissions())) {
have.add(permission.getName().toLowerCase());
boolean needRange = GlobalCapability.hasRange(permission.getName());
List<String> rules = new ArrayList<>();
for (PermissionRule rule : sort(permission.getRules())) {
GroupReference group = resolve(rule.getGroup());
if (group.getUUID() != null) {
keepGroups.add(group.getUUID());
}
rules.add(rule.toBuilder().setGroup(group).build().asString(needRange));
}
rc.setStringList(CAPABILITY, null, permission.getName(), rules);
}
for (String varName : rc.getNames(CAPABILITY)) {
if (!have.contains(varName.toLowerCase())) {
rc.unset(CAPABILITY, null, varName);
}
}
} else {
rc.unsetSection(CAPABILITY, null);
}
for (AccessSection as : sort(accessSections.values())) {
String refName = as.getName();
if (AccessSection.GLOBAL_CAPABILITIES.equals(refName)) {
continue;
}
StringBuilder doNotInherit = new StringBuilder();
for (Permission perm : sort(as.getPermissions())) {
if (perm.getExclusiveGroup()) {
if (0 < doNotInherit.length()) {
doNotInherit.append(' ');
}
doNotInherit.append(perm.getName());
}
}
if (0 < doNotInherit.length()) {
rc.setString(ACCESS, refName, KEY_GROUP_PERMISSIONS, doNotInherit.toString());
} else {
rc.unset(ACCESS, refName, KEY_GROUP_PERMISSIONS);
}
Set<String> have = new HashSet<>();
for (Permission permission : sort(as.getPermissions())) {
have.add(permission.getName().toLowerCase());
boolean needRange = Permission.hasRange(permission.getName());
List<String> rules = new ArrayList<>();
for (PermissionRule rule : sort(permission.getRules())) {
GroupReference group = resolve(rule.getGroup());
if (group.getUUID() != null) {
keepGroups.add(group.getUUID());
}
rules.add(rule.toBuilder().setGroup(group).build().asString(needRange));
}
rc.setStringList(ACCESS, refName, permission.getName(), rules);
}
for (String varName : rc.getNames(ACCESS, refName)) {
if (isCoreOrPluginPermission(convertLegacyPermission(varName)) && !have.contains(varName.toLowerCase())) {
rc.unset(ACCESS, refName, varName);
}
}
}
for (String name : rc.getSubsections(ACCESS)) {
if (AccessSection.isValidRefSectionName(name) && !accessSections.containsKey(name)) {
rc.unsetSection(ACCESS, name);
}
}
}
use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.
the class GroupList method parse.
public static GroupList parse(Project.NameKey project, String text, ValidationError.Sink errors) throws IOException {
List<Row> rows = parse(text, FILE_NAME, TRIM, TRIM, errors);
Map<AccountGroup.UUID, GroupReference> groupsByUUID = new HashMap<>(rows.size());
for (Row row : rows) {
if (row.left == null) {
logger.atWarning().log("null field in group list for %s:\n%s", project, text);
continue;
}
AccountGroup.UUID uuid = AccountGroup.uuid(row.left);
String name = row.right;
GroupReference ref = GroupReference.create(uuid, name);
groupsByUUID.put(uuid, ref);
}
return new GroupList(groupsByUUID);
}
Aggregations