Search in sources :

Example 36 with GroupReference

use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.

the class ProjectConfig method mapGroupReferences.

private Map<String, GroupReference> mapGroupReferences() {
    Collection<GroupReference> references = groupList.references();
    Map<String, GroupReference> result = new HashMap<>(references.size());
    for (GroupReference ref : references) {
        result.put(ref.getName(), ref);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GroupReference(com.google.gerrit.common.data.GroupReference)

Example 37 with GroupReference

use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.

the class ProjectConfig method saveNotifySections.

private void saveNotifySections(Config rc, Set<AccountGroup.UUID> keepGroups) {
    for (NotifyConfig nc : sort(notifySections.values())) {
        List<String> email = new ArrayList<>();
        for (GroupReference gr : nc.getGroups()) {
            if (gr.getUUID() != null) {
                keepGroups.add(gr.getUUID());
            }
            email.add(new PermissionRule(gr).asString(false));
        }
        Collections.sort(email);
        List<String> addrs = new ArrayList<>();
        for (Address addr : nc.getAddresses()) {
            addrs.add(addr.toString());
        }
        Collections.sort(addrs);
        email.addAll(addrs);
        set(rc, NOTIFY, nc.getName(), KEY_HEADER, nc.getHeader(), NotifyConfig.Header.BCC);
        if (email.isEmpty()) {
            rc.unset(NOTIFY, nc.getName(), KEY_EMAIL);
        } else {
            rc.setStringList(NOTIFY, nc.getName(), KEY_EMAIL, email);
        }
        if (nc.getNotify().equals(EnumSet.of(NotifyType.ALL))) {
            rc.unset(NOTIFY, nc.getName(), KEY_TYPE);
        } else {
            List<String> types = Lists.newArrayListWithCapacity(4);
            for (NotifyType t : NotifyType.values()) {
                if (nc.isNotify(t)) {
                    types.add(StringUtils.toLowerCase(t.name()));
                }
            }
            rc.setStringList(NOTIFY, nc.getName(), KEY_TYPE, types);
        }
        set(rc, NOTIFY, nc.getName(), KEY_FILTER, nc.getFilter());
    }
}
Also used : NotifyType(com.google.gerrit.server.account.WatchConfig.NotifyType) Address(com.google.gerrit.server.mail.Address) PermissionRule(com.google.gerrit.common.data.PermissionRule) ArrayList(java.util.ArrayList) GroupReference(com.google.gerrit.common.data.GroupReference)

Example 38 with GroupReference

use of com.google.gerrit.common.data.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;
            ref.setName(g.getName());
        }
    }
    return dirty;
}
Also used : GroupDescription(com.google.gerrit.common.data.GroupDescription) GroupReference(com.google.gerrit.common.data.GroupReference)

Example 39 with GroupReference

use of com.google.gerrit.common.data.GroupReference in project gerrit by GerritCodeReview.

the class RenameGroupOp method run.

@Override
public void run() {
    Iterable<Project.NameKey> names = tryingAgain ? retryOn : projectCache.all();
    for (Project.NameKey projectName : names) {
        ProjectConfig config = projectCache.get(projectName).getConfig();
        GroupReference ref = config.getGroup(uuid);
        if (ref == null || newName.equals(ref.getName())) {
            continue;
        }
        try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
            rename(md);
        } catch (RepositoryNotFoundException noProject) {
            continue;
        } catch (ConfigInvalidException | IOException err) {
            log.error("Cannot rename group " + oldName + " in " + projectName, err);
        }
    }
    // another attempt. If it doesn't update after that, give up.
    if (!retryOn.isEmpty() && !tryingAgain) {
        tryingAgain = true;
        @SuppressWarnings("unused") Future<?> possiblyIgnoredError = start(5, TimeUnit.MINUTES);
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException) Project(com.google.gerrit.reviewdb.client.Project) GroupReference(com.google.gerrit.common.data.GroupReference)

Example 40 with GroupReference

use of com.google.gerrit.common.data.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, Map<String, GroupReference> groupsByName) {
    notifySections = new HashMap<>();
    for (String sectionName : rc.getSubsections(NOTIFY)) {
        NotifyConfig n = new NotifyConfig();
        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.setTypes(types);
        n.setHeader(rc.getEnum(NOTIFY, sectionName, KEY_HEADER, NotifyConfig.Header.BCC));
        for (String dst : rc.getStringList(NOTIFY, sectionName, KEY_EMAIL)) {
            if (dst.startsWith("group ")) {
                String groupName = dst.substring(6).trim();
                GroupReference ref = groupsByName.get(groupName);
                if (ref == null) {
                    ref = new GroupReference(null, groupName);
                    groupsByName.put(ref.getName(), ref);
                }
                if (ref.getUUID() != null) {
                    n.addEmail(ref);
                } else {
                    error(new ValidationError(PROJECT_CONFIG, "group \"" + ref.getName() + "\" not in " + GroupList.FILE_NAME));
                }
            } else if (dst.startsWith("user ")) {
                error(new ValidationError(PROJECT_CONFIG, dst + " not supported"));
            } else {
                try {
                    n.addEmail(Address.parse(dst));
                } catch (IllegalArgumentException err) {
                    error(new ValidationError(PROJECT_CONFIG, "notify section \"" + sectionName + "\" has invalid email \"" + dst + "\""));
                }
            }
        }
        notifySections.put(sectionName, n);
    }
}
Also used : NotifyType(com.google.gerrit.server.account.WatchConfig.NotifyType) GroupReference(com.google.gerrit.common.data.GroupReference)

Aggregations

GroupReference (com.google.gerrit.common.data.GroupReference)41 PermissionRule (com.google.gerrit.common.data.PermissionRule)11 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)9 AccessSection (com.google.gerrit.common.data.AccessSection)6 Permission (com.google.gerrit.common.data.Permission)6 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)6 IOException (java.io.IOException)6 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)5 OrmException (com.google.gwtorm.server.OrmException)5 Test (org.junit.Test)5 GroupDescription (com.google.gerrit.common.data.GroupDescription)4 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)4 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)4 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)3 Project (com.google.gerrit.reviewdb.client.Project)3 PluginConfig (com.google.gerrit.server.config.PluginConfig)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Config (org.eclipse.jgit.lib.Config)3 Repository (org.eclipse.jgit.lib.Repository)3