Search in sources :

Example 31 with GroupReference

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;
}
Also used : GroupDescription(com.google.gerrit.entities.GroupDescription) GroupReference(com.google.gerrit.entities.GroupReference)

Example 32 with GroupReference

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)));
        }
    }
}
Also used : Config(org.eclipse.jgit.lib.Config) PluginConfig(com.google.gerrit.server.config.PluginConfig) NotifyConfig(com.google.gerrit.entities.NotifyConfig) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) CachedProjectConfig(com.google.gerrit.entities.CachedProjectConfig) StoredConfig(org.eclipse.jgit.lib.StoredConfig) GroupReference(com.google.gerrit.entities.GroupReference)

Example 33 with GroupReference

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));
    }
}
Also used : PermissionRule(com.google.gerrit.entities.PermissionRule) GroupReference(com.google.gerrit.entities.GroupReference)

Example 34 with GroupReference

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);
        }
    }
}
Also used : PermissionRule(com.google.gerrit.entities.PermissionRule) Permission.isPermission(com.google.gerrit.entities.Permission.isPermission) PluginPermissionsUtil.isValidPluginPermission(com.google.gerrit.server.permissions.PluginPermissionsUtil.isValidPluginPermission) Permission(com.google.gerrit.entities.Permission) ArrayList(java.util.ArrayList) GroupReference(com.google.gerrit.entities.GroupReference) AccessSection(com.google.gerrit.entities.AccessSection) HashSet(java.util.HashSet)

Example 35 with GroupReference

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);
}
Also used : AccountGroup(com.google.gerrit.entities.AccountGroup) HashMap(java.util.HashMap) GroupReference(com.google.gerrit.entities.GroupReference)

Aggregations

GroupReference (com.google.gerrit.entities.GroupReference)59 Test (org.junit.Test)24 AccountGroup (com.google.gerrit.entities.AccountGroup)18 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)8 GroupDescription (com.google.gerrit.entities.GroupDescription)8 InternalGroup (com.google.gerrit.entities.InternalGroup)7 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)7 IOException (java.io.IOException)7 Repository (org.eclipse.jgit.lib.Repository)7 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)6 Config (org.eclipse.jgit.lib.Config)6 CachedProjectConfig (com.google.gerrit.entities.CachedProjectConfig)5 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)5 NotifyConfig (com.google.gerrit.entities.NotifyConfig)4 ArrayList (java.util.ArrayList)4 Account (com.google.gerrit.entities.Account)3 BooleanProjectConfig (com.google.gerrit.entities.BooleanProjectConfig)3 Permission (com.google.gerrit.entities.Permission)3 PermissionRule (com.google.gerrit.entities.PermissionRule)3 ProjectAccessInfo (com.google.gerrit.extensions.api.access.ProjectAccessInfo)3