Enable plugin-based validation of user's ref related operations

After user is authorized to perform a given ref operation, but just
before it is performed, invoke validation from plugins.

Validation is invoked for ref create, delete and update (including
non-ff) operations caused by user through either push or call to
existing ref related Gerrit endpoints (create/delete branch/es).

Change-Id: I11cbe51f54e7d133b336ab503577653b6fe0f443
Signed-off-by: Jacek Centkowski <geminica.programs@gmail.com>
This commit is contained in:
Jacek Centkowski
2014-09-10 07:53:51 -04:00
parent bc425ff53b
commit 0b9424690d
7 changed files with 125 additions and 11 deletions

View File

@@ -35,6 +35,7 @@ import org.eclipse.jgit.lib.BatchRefUpdate;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.ReceiveCommand;
@@ -53,16 +54,20 @@ public class DeleteBranches
private final GitRepositoryManager repoManager;
private final Provider<InternalChangeQuery> queryProvider;
private final GitReferenceUpdated referenceUpdated;
private final RefValidationHelper refDeletionValidator;
@Inject
DeleteBranches(Provider<IdentifiedUser> identifiedUser,
GitRepositoryManager repoManager,
Provider<InternalChangeQuery> queryProvider,
GitReferenceUpdated referenceUpdated) {
GitReferenceUpdated referenceUpdated,
RefValidationHelper.Factory refHelperFactory) {
this.identifiedUser = identifiedUser;
this.repoManager = repoManager;
this.queryProvider = queryProvider;
this.referenceUpdated = referenceUpdated;
this.refDeletionValidator =
refHelperFactory.create(ReceiveCommand.Type.DELETE);
}
@Override
@@ -100,7 +105,8 @@ public class DeleteBranches
}
private ReceiveCommand createDeleteCommand(ProjectResource project,
Repository r, String branch) throws OrmException, IOException {
Repository r, String branch)
throws OrmException, IOException, ResourceConflictException {
Ref ref = r.getRefDatabase().getRef(branch);
ReceiveCommand command;
if (ref == null) {
@@ -120,6 +126,10 @@ public class DeleteBranches
if (!queryProvider.get().setLimit(1).byBranchOpen(branchKey).isEmpty()) {
command.setResult(Result.REJECTED_OTHER_REASON, "it has open changes");
}
RefUpdate u = r.updateRef(branch);
u.setForceUpdate(true);
refDeletionValidator.validateRefOperation(
project.getName(), identifiedUser.get(), u);
return command;
}