Search in sources :

Example 16 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class PostReviewers method addWholeGroup.

@Nullable
private Addition addWholeGroup(String reviewer, ChangeResource rsrc, ReviewerState state, NotifyHandling notify, ListMultimap<RecipientType, Account.Id> accountsToNotify, boolean confirmed, boolean allowGroup, boolean allowByEmail) throws OrmException, IOException, PermissionBackendException {
    if (!allowGroup) {
        return null;
    }
    GroupDescription.Basic group = null;
    try {
        group = groupsCollection.parseInternal(reviewer);
    } catch (UnprocessableEntityException e) {
        if (!allowByEmail) {
            return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerNotFoundUserOrGroup, reviewer));
        }
        return null;
    }
    if (!isLegalReviewerGroup(group.getGroupUUID())) {
        return fail(reviewer, MessageFormat.format(ChangeMessages.get().groupIsNotAllowed, group.getName()));
    }
    Set<Account.Id> reviewers = new HashSet<>();
    ChangeControl control = rsrc.getControl();
    Set<Account> members;
    try {
        members = groupMembersFactory.create(control.getUser()).listAccounts(group.getGroupUUID(), control.getProject().getNameKey());
    } catch (NoSuchGroupException e) {
        return fail(reviewer, MessageFormat.format(ChangeMessages.get().reviewerNotFoundUserOrGroup, group.getName()));
    } catch (NoSuchProjectException e) {
        return fail(reviewer, e.getMessage());
    }
    // if maxAllowed is set to 0, it is allowed to add any number of
    // reviewers
    int maxAllowed = cfg.getInt("addreviewer", "maxAllowed", DEFAULT_MAX_REVIEWERS);
    if (maxAllowed > 0 && members.size() > maxAllowed) {
        return fail(reviewer, MessageFormat.format(ChangeMessages.get().groupHasTooManyMembers, group.getName()));
    }
    // if maxWithoutCheck is set to 0, we never ask for confirmation
    int maxWithoutConfirmation = cfg.getInt("addreviewer", "maxWithoutConfirmation", DEFAULT_MAX_REVIEWERS_WITHOUT_CHECK);
    if (!confirmed && maxWithoutConfirmation > 0 && members.size() > maxWithoutConfirmation) {
        return fail(reviewer, true, MessageFormat.format(ChangeMessages.get().groupManyMembersConfirmation, group.getName(), members.size()));
    }
    PermissionBackend.ForRef perm = permissionBackend.user(rsrc.getUser()).ref(rsrc.getChange().getDest());
    for (Account member : members) {
        if (isValidReviewer(member, perm)) {
            reviewers.add(member.getId());
        }
    }
    return new Addition(reviewer, rsrc, reviewers, null, state, notify, accountsToNotify);
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) Account(com.google.gerrit.reviewdb.client.Account) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException) GroupDescription(com.google.gerrit.common.data.GroupDescription) ChangeControl(com.google.gerrit.server.project.ChangeControl) HashSet(java.util.HashSet) Nullable(com.google.gerrit.common.Nullable)

Example 17 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class PreviewSubmit method getBundles.

private BinaryResult getBundles(BatchUpdate.Factory updateFactory, RevisionResource rsrc, ArchiveFormat f) throws OrmException, RestApiException {
    ReviewDb db = dbProvider.get();
    ChangeControl control = rsrc.getControl();
    IdentifiedUser caller = control.getUser().asIdentifiedUser();
    Change change = rsrc.getChange();
    // Returned BinaryResult takes ownership and handles closing.
    @SuppressWarnings("resource") MergeOp op = mergeOpFactory.create(updateFactory);
    try {
        op.merge(db, change, caller, false, new SubmitInput(), true);
        BinaryResult bin = new SubmitPreviewResult(op, f, maxBundleSize);
        bin.disableGzip().setContentType(f.getMimeType()).setAttachmentName("submit-preview-" + change.getChangeId() + "." + format);
        return bin;
    } catch (OrmException | RestApiException | RuntimeException e) {
        op.close();
        throw e;
    }
}
Also used : MergeOp(com.google.gerrit.server.git.MergeOp) Change(com.google.gerrit.reviewdb.client.Change) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) OrmException(com.google.gwtorm.server.OrmException) ChangeControl(com.google.gerrit.server.project.ChangeControl) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult)

Example 18 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class PutDescription method applyImpl.

@Override
protected Response<String> applyImpl(BatchUpdate.Factory updateFactory, RevisionResource rsrc, Input input) throws UpdateException, RestApiException, PermissionBackendException {
    rsrc.permissions().check(ChangePermission.EDIT_DESCRIPTION);
    ChangeControl ctl = rsrc.getControl();
    Op op = new Op(input != null ? input : new Input(), rsrc.getPatchSet().getId());
    try (BatchUpdate u = updateFactory.create(dbProvider.get(), rsrc.getChange().getProject(), ctl.getUser(), TimeUtil.nowTs())) {
        u.addOp(rsrc.getChange().getId(), op);
        u.execute();
    }
    return Strings.isNullOrEmpty(op.newDescription) ? Response.none() : Response.ok(op.newDescription);
}
Also used : BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) DefaultInput(com.google.gerrit.extensions.restapi.DefaultInput) ChangeControl(com.google.gerrit.server.project.ChangeControl) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 19 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class Rebase method applyImpl.

@Override
protected ChangeInfo applyImpl(BatchUpdate.Factory updateFactory, RevisionResource rsrc, RebaseInput input) throws EmailException, OrmException, UpdateException, RestApiException, IOException, NoSuchChangeException, PermissionBackendException {
    rsrc.permissions().database(dbProvider).check(ChangePermission.REBASE);
    ChangeControl control = rsrc.getControl();
    Change change = rsrc.getChange();
    try (Repository repo = repoManager.openRepository(change.getProject());
        ObjectInserter oi = repo.newObjectInserter();
        ObjectReader reader = oi.newReader();
        RevWalk rw = new RevWalk(reader);
        BatchUpdate bu = updateFactory.create(dbProvider.get(), change.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
        if (!change.getStatus().isOpen()) {
            throw new ResourceConflictException("change is " + ChangeUtil.status(change));
        } else if (!hasOneParent(rw, rsrc.getPatchSet())) {
            throw new ResourceConflictException("cannot rebase merge commits or commit with no ancestor");
        }
        bu.setRepository(repo, rw, oi);
        bu.addOp(change.getId(), rebaseFactory.create(control, rsrc.getPatchSet(), findBaseRev(repo, rw, rsrc, input)).setForceContentMerge(true).setFireRevisionCreated(true));
        bu.execute();
    }
    return json.create(OPTIONS).format(change.getProject(), change.getId());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ChangeControl(com.google.gerrit.server.project.ChangeControl) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Change(com.google.gerrit.reviewdb.client.Change) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 20 with ChangeControl

use of com.google.gerrit.server.project.ChangeControl in project gerrit by GerritCodeReview.

the class DeletePrivate method applyImpl.

@Override
protected Response<String> applyImpl(BatchUpdate.Factory updateFactory, ChangeResource rsrc, SetPrivateOp.Input input) throws RestApiException, UpdateException {
    if (!canDeletePrivate(rsrc)) {
        throw new AuthException("not allowed to unmark private");
    }
    if (!rsrc.getChange().isPrivate()) {
        throw new ResourceConflictException("change is not private");
    }
    ChangeControl control = rsrc.getControl();
    SetPrivateOp op = new SetPrivateOp(cmUtil, false, input);
    try (BatchUpdate u = updateFactory.create(dbProvider.get(), control.getProject().getNameKey(), control.getUser(), TimeUtil.nowTs())) {
        u.addOp(control.getId(), op).execute();
    }
    return Response.none();
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ChangeControl(com.google.gerrit.server.project.ChangeControl) AuthException(com.google.gerrit.extensions.restapi.AuthException) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Aggregations

ChangeControl (com.google.gerrit.server.project.ChangeControl)34 Change (com.google.gerrit.reviewdb.client.Change)11 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)9 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)7 AuthException (com.google.gerrit.extensions.restapi.AuthException)6 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)6 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)5 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)5 Project (com.google.gerrit.reviewdb.client.Project)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 HashMap (java.util.HashMap)5 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)4 ObjectId (org.eclipse.jgit.lib.ObjectId)4 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)4 ObjectReader (org.eclipse.jgit.lib.ObjectReader)4 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 LabelType (com.google.gerrit.common.data.LabelType)3 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)3 Branch (com.google.gerrit.reviewdb.client.Branch)3