CommitValidators: uniformize argument ordering for creation methods
Change-Id: Idf5a3bed6cbd3f90f5c9582e160c57a3a201933f
This commit is contained in:
@@ -552,8 +552,6 @@ public class ChangeInserter implements InsertChangeOp {
|
||||
return;
|
||||
}
|
||||
|
||||
PermissionBackend.ForRef perm =
|
||||
permissionBackend.user(ctx.getUser()).project(ctx.getProject()).ref(refName);
|
||||
try {
|
||||
try (CommitReceivedEvent event =
|
||||
new CommitReceivedEvent(
|
||||
@@ -565,7 +563,7 @@ public class ChangeInserter implements InsertChangeOp {
|
||||
ctx.getIdentifiedUser())) {
|
||||
commitValidatorsFactory
|
||||
.forGerritCommits(
|
||||
perm,
|
||||
permissionBackend.user(ctx.getUser()).project(ctx.getProject()),
|
||||
new Branch.NameKey(ctx.getProject(), refName),
|
||||
ctx.getIdentifiedUser(),
|
||||
new NoSshInfo(),
|
||||
|
||||
@@ -323,9 +323,6 @@ public class PatchSetInserter implements BatchUpdateOp {
|
||||
return;
|
||||
}
|
||||
|
||||
PermissionBackend.ForRef perm =
|
||||
permissionBackend.user(ctx.getUser()).ref(origNotes.getChange().getDest());
|
||||
|
||||
String refName = getPatchSetId().toRefName();
|
||||
try (CommitReceivedEvent event =
|
||||
new CommitReceivedEvent(
|
||||
@@ -340,7 +337,7 @@ public class PatchSetInserter implements BatchUpdateOp {
|
||||
ctx.getIdentifiedUser())) {
|
||||
commitValidatorsFactory
|
||||
.forGerritCommits(
|
||||
perm,
|
||||
permissionBackend.user(ctx.getUser()).project(ctx.getProject()),
|
||||
origNotes.getChange().getDest(),
|
||||
ctx.getIdentifiedUser(),
|
||||
new NoSshInfo(),
|
||||
|
||||
@@ -3115,7 +3115,6 @@ class ReceiveCommits {
|
||||
@Nullable Change change,
|
||||
NoteMap rejectCommits)
|
||||
throws IOException {
|
||||
PermissionBackend.ForRef perm = permissions.ref(branch.get());
|
||||
|
||||
ValidCommitKey key = new AutoValue_ReceiveCommits_ValidCommitKey(commit.copy(), branch);
|
||||
if (validCommits.contains(key)) {
|
||||
@@ -3127,12 +3126,11 @@ class ReceiveCommits {
|
||||
CommitValidators validators;
|
||||
if (isMerged) {
|
||||
validators =
|
||||
commitValidatorsFactory.forMergedCommits(
|
||||
project.getNameKey(), perm, user.asIdentifiedUser());
|
||||
commitValidatorsFactory.forMergedCommits(permissions, branch, user.asIdentifiedUser());
|
||||
} else {
|
||||
validators =
|
||||
commitValidatorsFactory.forReceiveCommits(
|
||||
perm,
|
||||
permissions,
|
||||
branch,
|
||||
user.asIdentifiedUser(),
|
||||
sshInfo,
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.google.gerrit.reviewdb.client.BooleanProjectConfig;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Branch.NameKey;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
@@ -48,7 +47,6 @@ import com.google.gerrit.server.events.CommitReceivedEvent;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.ValidationError;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend.ForRef;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.permissions.RefPermission;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
@@ -122,7 +120,7 @@ public class CommitValidators {
|
||||
}
|
||||
|
||||
public CommitValidators forReceiveCommits(
|
||||
PermissionBackend.ForRef perm,
|
||||
PermissionBackend.ForProject forProject,
|
||||
Branch.NameKey branch,
|
||||
IdentifiedUser user,
|
||||
SshInfo sshInfo,
|
||||
@@ -130,6 +128,7 @@ public class CommitValidators {
|
||||
RevWalk rw,
|
||||
@Nullable Change change)
|
||||
throws IOException {
|
||||
PermissionBackend.ForRef perm = forProject.ref(branch.get());
|
||||
ProjectState projectState = projectCache.checkedGet(branch.getParentKey());
|
||||
return new CommitValidators(
|
||||
ImmutableList.of(
|
||||
@@ -155,13 +154,14 @@ public class CommitValidators {
|
||||
}
|
||||
|
||||
public CommitValidators forGerritCommits(
|
||||
ForRef perm,
|
||||
PermissionBackend.ForProject forProject,
|
||||
NameKey branch,
|
||||
IdentifiedUser user,
|
||||
SshInfo sshInfo,
|
||||
RevWalk rw,
|
||||
@Nullable Change change)
|
||||
throws IOException {
|
||||
PermissionBackend.ForRef perm = forProject.ref(branch.get());
|
||||
ProjectState projectState = projectCache.checkedGet(branch.getParentKey());
|
||||
return new CommitValidators(
|
||||
ImmutableList.of(
|
||||
@@ -185,7 +185,7 @@ public class CommitValidators {
|
||||
}
|
||||
|
||||
public CommitValidators forMergedCommits(
|
||||
Project.NameKey project, PermissionBackend.ForRef perm, IdentifiedUser user)
|
||||
PermissionBackend.ForProject forProject, Branch.NameKey branch, IdentifiedUser user)
|
||||
throws IOException {
|
||||
// Generally only include validators that are based on permissions of the
|
||||
// user creating a change for a merged commit; generally exclude
|
||||
@@ -200,10 +200,11 @@ public class CommitValidators {
|
||||
// discuss what to do about it.
|
||||
// - Plugin validators may do things like require certain commit message
|
||||
// formats, so we play it safe and exclude them.
|
||||
PermissionBackend.ForRef perm = forProject.ref(branch.get());
|
||||
return new CommitValidators(
|
||||
ImmutableList.of(
|
||||
new UploadMergesPermissionValidator(perm),
|
||||
new ProjectStateValidationListener(projectCache.checkedGet(project)),
|
||||
new ProjectStateValidationListener(projectCache.checkedGet(branch.getParentKey())),
|
||||
new AuthorUploaderValidator(user, perm, canonicalWebUrl),
|
||||
new CommitterUploaderValidator(user, perm, canonicalWebUrl)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user