Search in sources :

Example 6 with GroupReference

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

the class GroupNameNotes method ensureOldNameIsPresent.

private void ensureOldNameIsPresent(NoteMap noteMap) throws IOException, ConfigInvalidException {
    if (oldGroupName.isPresent()) {
        AccountGroup.NameKey oldName = oldGroupName.get();
        ObjectId noteKey = getNoteKey(oldName);
        ObjectId noteDataBlobId = noteMap.get(noteKey);
        if (noteDataBlobId == null) {
            throw new ConfigInvalidException(String.format("Group name '%s' doesn't exist in the list of all names", oldName));
        }
        GroupReference group = getGroupReference(reader, noteDataBlobId);
        AccountGroup.UUID foundUuid = group.getUUID();
        if (!Objects.equals(groupUuid, foundUuid)) {
            throw new ConfigInvalidException(String.format("Name '%s' points to UUID '%s' and not to '%s'", oldName, foundUuid, groupUuid));
        }
    }
}
Also used : AccountGroup(com.google.gerrit.entities.AccountGroup) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ObjectId(org.eclipse.jgit.lib.ObjectId) GroupReference(com.google.gerrit.entities.GroupReference)

Example 7 with GroupReference

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

the class RenameGroupOp method rename.

private void rename(MetaDataUpdate md) throws IOException, ConfigInvalidException {
    boolean success = false;
    for (int attempts = 0; !success && attempts < MAX_TRIES; attempts++) {
        ProjectConfig config = projectConfigFactory.read(md);
        // The group isn't referenced, or its name has been fixed already.
        // 
        GroupReference ref = config.getGroup(uuid);
        if (ref == null || newName.equals(ref.getName())) {
            projectCache.evictAndReindex(config.getProject());
            return;
        }
        config.renameGroup(uuid, newName);
        md.getCommitBuilder().setAuthor(author);
        md.setMessage("Rename group " + oldName + " to " + newName + "\n");
        try {
            config.commit(md);
            projectCache.evictAndReindex(config.getProject());
            success = true;
        } catch (IOException e) {
            logger.atSevere().withCause(e).log("Could not commit rename of group %s to %s in %s", oldName, newName, md.getProjectName().get());
            try {
                Thread.sleep(25);
            } catch (InterruptedException wakeUp) {
                continue;
            }
        }
    }
    if (!success) {
        if (tryingAgain) {
            logger.atWarning().log("Could not rename group %s to %s in %s", oldName, newName, md.getProjectName().get());
        } else {
            retryOn.add(md.getProjectName());
        }
    }
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) CachedProjectConfig(com.google.gerrit.entities.CachedProjectConfig) GroupReference(com.google.gerrit.entities.GroupReference) IOException(java.io.IOException)

Example 8 with GroupReference

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

the class ReviewersUtil method suggestAccountGroups.

private List<SuggestedReviewerInfo> suggestAccountGroups(SuggestReviewers suggestReviewers, ProjectState projectState, VisibilityControl visibilityControl, int limit) throws IOException {
    try (Timer0.Context ctx = metrics.queryGroupsLatency.start()) {
        List<SuggestedReviewerInfo> groups = new ArrayList<>();
        for (GroupReference g : suggestAccountGroups(suggestReviewers, projectState)) {
            GroupAsReviewer result = suggestGroupAsReviewer(suggestReviewers, projectState.getProject(), g, visibilityControl);
            if (result.allowed || result.allowedWithConfirmation) {
                GroupBaseInfo info = new GroupBaseInfo();
                info.id = Url.encode(g.getUUID().get());
                info.name = g.getName();
                SuggestedReviewerInfo suggestedReviewerInfo = new SuggestedReviewerInfo();
                suggestedReviewerInfo.group = info;
                suggestedReviewerInfo.count = result.size;
                if (result.allowedWithConfirmation) {
                    suggestedReviewerInfo.confirm = true;
                }
                groups.add(suggestedReviewerInfo);
                if (groups.size() >= limit) {
                    break;
                }
            }
        }
        return groups;
    }
}
Also used : SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) ArrayList(java.util.ArrayList) GroupBaseInfo(com.google.gerrit.extensions.common.GroupBaseInfo) Timer0(com.google.gerrit.metrics.Timer0) GroupReference(com.google.gerrit.entities.GroupReference)

Example 9 with GroupReference

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

the class AgreementJson method format.

public AgreementInfo format(ContributorAgreement ca) throws PermissionBackendException {
    AgreementInfo info = new AgreementInfo();
    info.name = ca.getName();
    info.description = ca.getDescription();
    info.url = ca.getAgreementUrl();
    GroupReference autoVerifyGroup = ca.getAutoVerify();
    if (autoVerifyGroup != null && self.get().isIdentifiedUser()) {
        IdentifiedUser user = identifiedUserFactory.create(self.get().getAccountId());
        try {
            GroupControl gc = genericGroupControlFactory.controlFor(user, autoVerifyGroup.getUUID());
            GroupResource group = new GroupResource(gc);
            info.autoVerifyGroup = groupJson.format(group);
        } catch (NoSuchGroupException | StorageException e) {
            logger.atWarning().log("autoverify group \"%s\" does not exist, referenced in CLA \"%s\"", autoVerifyGroup.getName(), ca.getName());
        }
    }
    return info;
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) AgreementInfo(com.google.gerrit.extensions.common.AgreementInfo) GroupReference(com.google.gerrit.entities.GroupReference) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) StorageException(com.google.gerrit.exceptions.StorageException) GroupResource(com.google.gerrit.server.group.GroupResource) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Example 10 with GroupReference

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

the class GroupNameNotesTest method emptyGroupName.

@Test
public void emptyGroupName() throws Exception {
    GroupReference g = newGroup("");
    updateAllGroups(newPersonIdent(), g);
    assertThat(GroupNameNotes.loadAllGroups(repo)).containsExactly(g);
    assertThat(readNameNote(g)).isEqualTo("[group]\n\tuuid = -1\n\tname = \n");
}
Also used : GroupReference(com.google.gerrit.entities.GroupReference) Test(org.junit.Test)

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