Search in sources :

Example 6 with RefControl

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

the class Revert method applyImpl.

@Override
protected ChangeInfo applyImpl(BatchUpdate.Factory updateFactory, ChangeResource req, RevertInput input) throws IOException, OrmException, RestApiException, UpdateException, NoSuchChangeException {
    RefControl refControl = req.getControl().getRefControl();
    ProjectControl projectControl = req.getControl().getProjectControl();
    Capable capable = projectControl.canPushToAtLeastOneRef();
    if (capable != Capable.OK) {
        throw new AuthException(capable.getMessage());
    }
    Change change = req.getChange();
    if (!refControl.canUpload()) {
        throw new AuthException("revert not permitted");
    } else if (change.getStatus() != Status.MERGED) {
        throw new ResourceConflictException("change is " + ChangeUtil.status(change));
    }
    Change.Id revertedChangeId = revert(updateFactory, req.getControl(), Strings.emptyToNull(input.message));
    return json.noOptions().format(req.getProject(), revertedChangeId);
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Capable(com.google.gerrit.common.data.Capable) RefControl(com.google.gerrit.server.project.RefControl) AuthException(com.google.gerrit.extensions.restapi.AuthException) Change(com.google.gerrit.reviewdb.client.Change) ProjectControl(com.google.gerrit.server.project.ProjectControl)

Example 7 with RefControl

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

the class ReceiveCommits method parseRewind.

private void parseRewind(ReceiveCommand cmd) throws PermissionBackendException {
    RevCommit newObject;
    try {
        newObject = rp.getRevWalk().parseCommit(cmd.getNewId());
    } catch (IncorrectObjectTypeException notCommit) {
        newObject = null;
    } catch (IOException err) {
        logError("Invalid object " + cmd.getNewId().name() + " for " + cmd.getRefName() + " forced update", err);
        reject(cmd, "invalid object");
        return;
    }
    logDebug("Rewinding {}", cmd);
    RefControl ctl = projectControl.controlForRef(cmd.getRefName());
    if (newObject != null) {
        validateNewCommits(ctl, cmd);
        if (cmd.getResult() != NOT_ATTEMPTED) {
            return;
        }
    }
    boolean ok;
    try {
        permissions.ref(cmd.getRefName()).check(RefPermission.FORCE_UPDATE);
        ok = true;
    } catch (AuthException err) {
        ok = false;
    }
    if (ok) {
        if (!validRefOperation(cmd)) {
            return;
        }
        actualCommands.add(cmd);
    } else {
        cmd.setResult(REJECTED_NONFASTFORWARD, " need '" + PermissionRule.FORCE_PUSH + "' privilege.");
    }
}
Also used : RefControl(com.google.gerrit.server.project.RefControl) AuthException(com.google.gerrit.extensions.restapi.AuthException) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 8 with RefControl

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

the class ReceiveCommits method parseCreate.

private void parseCreate(ReceiveCommand cmd) {
    RevObject obj;
    try {
        obj = rp.getRevWalk().parseAny(cmd.getNewId());
    } catch (IOException err) {
        logError("Invalid object " + cmd.getNewId().name() + " for " + cmd.getRefName() + " creation", err);
        reject(cmd, "invalid object");
        return;
    }
    logDebug("Creating {}", cmd);
    if (isHead(cmd) && !isCommit(cmd)) {
        return;
    }
    RefControl ctl = projectControl.controlForRef(cmd.getRefName());
    if (ctl.canCreate(db, rp.getRepository(), obj)) {
        if (!validRefOperation(cmd)) {
            return;
        }
        validateNewCommits(ctl, cmd);
        actualCommands.add(cmd);
    } else {
        reject(cmd, "prohibited by Gerrit: create access denied for " + cmd.getRefName());
    }
}
Also used : RevObject(org.eclipse.jgit.revwalk.RevObject) RefControl(com.google.gerrit.server.project.RefControl) IOException(java.io.IOException)

Aggregations

RefControl (com.google.gerrit.server.project.RefControl)8 AuthException (com.google.gerrit.extensions.restapi.AuthException)5 Change (com.google.gerrit.reviewdb.client.Change)5 Capable (com.google.gerrit.common.data.Capable)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 ProjectControl (com.google.gerrit.server.project.ProjectControl)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)3 IOException (java.io.IOException)3 Project (com.google.gerrit.reviewdb.client.Project)2 IntegrationException (com.google.gerrit.server.git.IntegrationException)2 ChangeControl (com.google.gerrit.server.project.ChangeControl)2 InvalidChangeOperationException (com.google.gerrit.server.project.InvalidChangeOperationException)2 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)2 ObjectReader (org.eclipse.jgit.lib.ObjectReader)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 AccessSection (com.google.gerrit.common.data.AccessSection)1 Permission (com.google.gerrit.common.data.Permission)1