Search in sources :

Example 16 with GroupReference

use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.

the class GroupReferenceTest method testEquals.

@Test
public void testEquals() {
    AccountGroup.UUID uuid1 = AccountGroup.uuid("uuid-foo");
    AccountGroup.UUID uuid2 = AccountGroup.uuid("uuid-bar");
    String name1 = "foo";
    String name2 = "bar";
    GroupReference groupReference1 = GroupReference.create(uuid1, name1);
    GroupReference groupReference2 = GroupReference.create(uuid1, name2);
    GroupReference groupReference3 = GroupReference.create(uuid2, name1);
    assertThat(groupReference1.equals(groupReference2)).isTrue();
    assertThat(groupReference1.equals(groupReference3)).isFalse();
    assertThat(groupReference2.equals(groupReference3)).isFalse();
}
Also used : AccountGroup(com.google.gerrit.entities.AccountGroup) GroupReference(com.google.gerrit.entities.GroupReference) UUID(com.google.gerrit.entities.AccountGroup.UUID) Test(org.junit.Test)

Example 17 with GroupReference

use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.

the class ProjectConfig method savePluginSections.

private void savePluginSections(Config rc, Set<AccountGroup.UUID> keepGroups) {
    unsetSection(rc, PLUGIN);
    for (Map.Entry<String, Config> e : pluginConfigs.entrySet()) {
        String plugin = e.getKey();
        Config pluginConfig = e.getValue();
        for (String name : pluginConfig.getNames(PLUGIN, plugin)) {
            String value = pluginConfig.getString(PLUGIN, plugin, name);
            String groupName = GroupReference.extractGroupName(value);
            if (groupName != null) {
                GroupReference ref = groupList.byName(groupName);
                if (ref != null && ref.getUUID() != null) {
                    keepGroups.add(ref.getUUID());
                    pluginConfig.setString(PLUGIN, plugin, name, "group " + ref.getName());
                }
            }
            rc.setStringList(PLUGIN, plugin, name, Arrays.asList(pluginConfig.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) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 18 with GroupReference

use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.

the class ProjectConfig method loadNotifySections.

/**
 * Parses the [notify] sections out of the configuration file.
 *
 * <pre>
 *   [notify "reviewers"]
 *     email = group Reviewers
 *     type = new_changes
 *
 *   [notify "dev-team"]
 *     email = dev-team@example.com
 *     filter = branch:master
 *
 *   [notify "qa"]
 *     email = qa@example.com
 *     filter = branch:\"^(maint|stable)-.*\"
 *     type = submitted_changes
 * </pre>
 */
private void loadNotifySections(Config rc) {
    notifySections = new HashMap<>();
    for (String sectionName : rc.getSubsections(NOTIFY)) {
        NotifyConfig.Builder n = NotifyConfig.builder();
        n.setName(sectionName);
        n.setFilter(rc.getString(NOTIFY, sectionName, KEY_FILTER));
        EnumSet<NotifyType> types = EnumSet.noneOf(NotifyType.class);
        types.addAll(ConfigUtil.getEnumList(rc, NOTIFY, sectionName, KEY_TYPE, NotifyType.ALL));
        n.setNotify(types);
        n.setHeader(rc.getEnum(NOTIFY, sectionName, KEY_HEADER, NotifyConfig.Header.BCC));
        for (String dst : rc.getStringList(NOTIFY, sectionName, KEY_EMAIL)) {
            String groupName = GroupReference.extractGroupName(dst);
            if (groupName != null) {
                GroupReference ref = groupList.byName(groupName);
                if (ref == null) {
                    ref = groupList.resolve(GroupReference.create(groupName));
                }
                if (ref.getUUID() != null) {
                    n.addGroup(ref);
                } else {
                    error(String.format("group \"%s\" not in %s", ref.getName(), GroupList.FILE_NAME));
                }
            } else if (dst.startsWith("user ")) {
                error(String.format("%s not supported", dst));
            } else {
                try {
                    n.addAddress(Address.parse(dst));
                } catch (IllegalArgumentException err) {
                    error(String.format("notify section \"%s\" has invalid email \"%s\"", sectionName, dst));
                }
            }
        }
        notifySections.put(sectionName, n.build());
    }
}
Also used : NotifyType(com.google.gerrit.entities.NotifyConfig.NotifyType) NotifyConfig(com.google.gerrit.entities.NotifyConfig) GroupReference(com.google.gerrit.entities.GroupReference)

Example 19 with GroupReference

use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.

the class ProjectCreator method createProjectConfig.

private void createProjectConfig(CreateProjectArgs args) throws IOException, ConfigInvalidException {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(args.getProject())) {
        ProjectConfig config = projectConfigFactory.read(md);
        config.updateProject(newProject -> {
            newProject.setDescription(Strings.nullToEmpty(args.projectDescription));
            newProject.setSubmitType(MoreObjects.firstNonNull(args.submitType, repositoryCfg.getDefaultSubmitType(args.getProject())));
            newProject.setBooleanConfig(BooleanProjectConfig.USE_CONTRIBUTOR_AGREEMENTS, args.contributorAgreements);
            newProject.setBooleanConfig(BooleanProjectConfig.USE_SIGNED_OFF_BY, args.signedOffBy);
            newProject.setBooleanConfig(BooleanProjectConfig.USE_CONTENT_MERGE, args.contentMerge);
            newProject.setBooleanConfig(BooleanProjectConfig.CREATE_NEW_CHANGE_FOR_ALL_NOT_IN_TARGET, args.newChangeForAllNotInTarget);
            newProject.setBooleanConfig(BooleanProjectConfig.REQUIRE_CHANGE_ID, args.changeIdRequired);
            newProject.setBooleanConfig(BooleanProjectConfig.REJECT_EMPTY_COMMIT, args.rejectEmptyCommit);
            newProject.setMaxObjectSizeLimit(args.maxObjectSizeLimit);
            newProject.setBooleanConfig(BooleanProjectConfig.ENABLE_SIGNED_PUSH, args.enableSignedPush);
            newProject.setBooleanConfig(BooleanProjectConfig.REQUIRE_SIGNED_PUSH, args.requireSignedPush);
            if (args.newParent != null) {
                newProject.setParent(args.newParent);
            }
        });
        if (!args.ownerIds.isEmpty()) {
            config.upsertAccessSection(AccessSection.ALL, all -> {
                for (AccountGroup.UUID ownerId : args.ownerIds) {
                    GroupDescription.Basic g = groupBackend.get(ownerId);
                    if (g != null) {
                        GroupReference group = config.resolve(GroupReference.forGroup(g));
                        all.upsertPermission(Permission.OWNER).add(PermissionRule.builder(group));
                    }
                }
            });
        }
        md.setMessage("Created project\n");
        config.commit(md);
        md.getRepository().setGitwebDescription(args.projectDescription);
    }
    projectCache.onCreateProject(args.getProject());
}
Also used : BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) GroupDescription(com.google.gerrit.entities.GroupDescription) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupReference(com.google.gerrit.entities.GroupReference) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 20 with GroupReference

use of com.google.gerrit.entities.GroupReference in project gerrit by GerritCodeReview.

the class GroupList method resolve.

/**
 * Returns the {@link GroupReference} instance that {@link GroupList} holds on to that has the
 * same {@link com.google.gerrit.entities.AccountGroup.UUID} as the argument. Will store the
 * argument internally, if no group with this {@link com.google.gerrit.entities.AccountGroup.UUID}
 * was stored previously.
 */
public GroupReference resolve(GroupReference group) {
    if (group != null) {
        if (group.getUUID() == null || group.getUUID().get() == null) {
            // results, nor return null the set from #uuids.
            return group;
        }
        GroupReference ref = byUUID.get(group.getUUID());
        if (ref != null) {
            return ref;
        }
        byUUID.put(group.getUUID(), group);
    }
    return group;
}
Also used : 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