Remove getChangeControl() from ChangeContext
Change-Id: I07da7337d35bf6e05766fcbf1e328c260255381c
This commit is contained in:
@@ -56,8 +56,8 @@ import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
|||||||
import com.google.gerrit.server.permissions.ChangePermission;
|
import com.google.gerrit.server.permissions.ChangePermission;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
|
||||||
import com.google.gerrit.server.project.ProjectCache;
|
import com.google.gerrit.server.project.ProjectCache;
|
||||||
|
import com.google.gerrit.server.project.ProjectState;
|
||||||
import com.google.gerrit.server.ssh.NoSshInfo;
|
import com.google.gerrit.server.ssh.NoSshInfo;
|
||||||
import com.google.gerrit.server.update.ChangeContext;
|
import com.google.gerrit.server.update.ChangeContext;
|
||||||
import com.google.gerrit.server.update.Context;
|
import com.google.gerrit.server.update.Context;
|
||||||
@@ -137,6 +137,7 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
private PatchSetInfo patchSetInfo;
|
private PatchSetInfo patchSetInfo;
|
||||||
private PatchSet patchSet;
|
private PatchSet patchSet;
|
||||||
private String pushCert;
|
private String pushCert;
|
||||||
|
private ProjectState projectState;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ChangeInserter(
|
ChangeInserter(
|
||||||
@@ -369,6 +370,7 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
@Override
|
@Override
|
||||||
public void updateRepo(RepoContext ctx) throws ResourceConflictException, IOException {
|
public void updateRepo(RepoContext ctx) throws ResourceConflictException, IOException {
|
||||||
cmd = new ReceiveCommand(ObjectId.zeroId(), commitId, psId.toRefName());
|
cmd = new ReceiveCommand(ObjectId.zeroId(), commitId, psId.toRefName());
|
||||||
|
projectState = projectCache.checkedGet(ctx.getProject());
|
||||||
validate(ctx);
|
validate(ctx);
|
||||||
if (!updateRef) {
|
if (!updateRef) {
|
||||||
return;
|
return;
|
||||||
@@ -381,7 +383,6 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
throws RestApiException, OrmException, IOException, PermissionBackendException {
|
throws RestApiException, OrmException, IOException, PermissionBackendException {
|
||||||
change = ctx.getChange(); // Use defensive copy created by ChangeControl.
|
change = ctx.getChange(); // Use defensive copy created by ChangeControl.
|
||||||
ReviewDb db = ctx.getDb();
|
ReviewDb db = ctx.getDb();
|
||||||
ChangeControl ctl = ctx.getControl();
|
|
||||||
patchSetInfo =
|
patchSetInfo =
|
||||||
patchSetInfoFactory.get(ctx.getRevWalk(), ctx.getRevWalk().parseCommit(commitId), psId);
|
patchSetInfoFactory.get(ctx.getRevWalk(), ctx.getRevWalk().parseCommit(commitId), psId);
|
||||||
ctx.getChange().setCurrentPatchSet(patchSetInfo);
|
ctx.getChange().setCurrentPatchSet(patchSetInfo);
|
||||||
@@ -433,7 +434,7 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
reviewersToAdd.addAll(extraCC);
|
reviewersToAdd.addAll(extraCC);
|
||||||
}
|
}
|
||||||
|
|
||||||
LabelTypes labelTypes = ctl.getProjectControl().getProjectState().getLabelTypes();
|
LabelTypes labelTypes = projectState.getLabelTypes();
|
||||||
approvalsUtil.addReviewers(
|
approvalsUtil.addReviewers(
|
||||||
db,
|
db,
|
||||||
update,
|
update,
|
||||||
@@ -534,10 +535,7 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
revisionCreated.fire(change, patchSet, ctx.getAccount(), ctx.getWhen(), notify);
|
revisionCreated.fire(change, patchSet, ctx.getAccount(), ctx.getWhen(), notify);
|
||||||
if (approvals != null && !approvals.isEmpty()) {
|
if (approvals != null && !approvals.isEmpty()) {
|
||||||
List<LabelType> labels =
|
List<LabelType> labels =
|
||||||
projectCache
|
projectState.getLabelTypes(change.getDest(), ctx.getUser()).getLabelTypes();
|
||||||
.checkedGet(ctx.getProject())
|
|
||||||
.getLabelTypes(change.getDest(), ctx.getUser())
|
|
||||||
.getLabelTypes();
|
|
||||||
Map<String, Short> allApprovals = new HashMap<>();
|
Map<String, Short> allApprovals = new HashMap<>();
|
||||||
Map<String, Short> oldApprovals = new HashMap<>();
|
Map<String, Short> oldApprovals = new HashMap<>();
|
||||||
for (LabelType lt : labels) {
|
for (LabelType lt : labels) {
|
||||||
@@ -567,7 +565,7 @@ public class ChangeInserter implements InsertChangeOp {
|
|||||||
try (CommitReceivedEvent event =
|
try (CommitReceivedEvent event =
|
||||||
new CommitReceivedEvent(
|
new CommitReceivedEvent(
|
||||||
cmd,
|
cmd,
|
||||||
projectCache.checkedGet(ctx.getProject()).getProject(),
|
projectState.getProject(),
|
||||||
change.getDest().get(),
|
change.getDest().get(),
|
||||||
ctx.getRevWalk().getObjectReader(),
|
ctx.getRevWalk().getObjectReader(),
|
||||||
commitId,
|
commitId,
|
||||||
|
|||||||
@@ -139,7 +139,9 @@ public class DeleteDraftPatchSet
|
|||||||
if (!allowDrafts) {
|
if (!allowDrafts) {
|
||||||
throw new MethodNotAllowedException("Draft workflow is disabled");
|
throw new MethodNotAllowedException("Draft workflow is disabled");
|
||||||
}
|
}
|
||||||
if (!ctx.getControl().canDeleteDraft(ctx.getDb())) {
|
if (!changeControlFactory
|
||||||
|
.controlFor(ctx.getNotes(), ctx.getUser())
|
||||||
|
.canDeleteDraft(ctx.getDb())) {
|
||||||
throw new AuthException("Not permitted to delete this draft patch set");
|
throw new AuthException("Not permitted to delete this draft patch set");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ public class PublishDraftPatchSet
|
|||||||
@Override
|
@Override
|
||||||
public boolean updateChange(ChangeContext ctx)
|
public boolean updateChange(ChangeContext ctx)
|
||||||
throws RestApiException, OrmException, IOException {
|
throws RestApiException, OrmException, IOException {
|
||||||
if (!ctx.getControl().canPublish(ctx.getDb())) {
|
if (!changeControlFactory.controlFor(ctx.getNotes(), ctx.getUser()).canPublish(ctx.getDb())) {
|
||||||
throw new AuthException("Cannot publish this draft patch set");
|
throw new AuthException("Cannot publish this draft patch set");
|
||||||
}
|
}
|
||||||
if (patchSet == null) {
|
if (patchSet == null) {
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ import com.google.gerrit.server.change.EmailReviewComments;
|
|||||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||||
import com.google.gerrit.server.extensions.events.CommentAdded;
|
import com.google.gerrit.server.extensions.events.CommentAdded;
|
||||||
import com.google.gerrit.server.mail.MailFilter;
|
import com.google.gerrit.server.mail.MailFilter;
|
||||||
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
import com.google.gerrit.server.patch.PatchListCache;
|
import com.google.gerrit.server.patch.PatchListCache;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
import com.google.gerrit.server.query.change.InternalChangeQuery;
|
||||||
import com.google.gerrit.server.update.BatchUpdate;
|
import com.google.gerrit.server.update.BatchUpdate;
|
||||||
@@ -231,7 +231,7 @@ public class MailProcessor {
|
|||||||
private ChangeMessage changeMessage;
|
private ChangeMessage changeMessage;
|
||||||
private List<Comment> comments;
|
private List<Comment> comments;
|
||||||
private PatchSet patchSet;
|
private PatchSet patchSet;
|
||||||
private ChangeControl changeControl;
|
private ChangeNotes notes;
|
||||||
|
|
||||||
private Op(PatchSet.Id psId, List<MailComment> parsedComments, String messageId) {
|
private Op(PatchSet.Id psId, List<MailComment> parsedComments, String messageId) {
|
||||||
this.psId = psId;
|
this.psId = psId;
|
||||||
@@ -242,8 +242,8 @@ public class MailProcessor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean updateChange(ChangeContext ctx)
|
public boolean updateChange(ChangeContext ctx)
|
||||||
throws OrmException, UnprocessableEntityException {
|
throws OrmException, UnprocessableEntityException {
|
||||||
changeControl = ctx.getControl();
|
|
||||||
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
|
patchSet = psUtil.get(ctx.getDb(), ctx.getNotes(), psId);
|
||||||
|
notes = ctx.getNotes();
|
||||||
if (patchSet == null) {
|
if (patchSet == null) {
|
||||||
throw new OrmException("patch set not found: " + psId);
|
throw new OrmException("patch set not found: " + psId);
|
||||||
}
|
}
|
||||||
@@ -279,7 +279,7 @@ public class MailProcessor {
|
|||||||
.create(
|
.create(
|
||||||
NotifyHandling.ALL,
|
NotifyHandling.ALL,
|
||||||
ArrayListMultimap.create(),
|
ArrayListMultimap.create(),
|
||||||
changeControl.getNotes(),
|
notes,
|
||||||
patchSet,
|
patchSet,
|
||||||
ctx.getUser().asIdentifiedUser(),
|
ctx.getUser().asIdentifiedUser(),
|
||||||
changeMessage,
|
changeMessage,
|
||||||
@@ -292,8 +292,8 @@ public class MailProcessor {
|
|||||||
approvalsUtil
|
approvalsUtil
|
||||||
.byPatchSetUser(
|
.byPatchSetUser(
|
||||||
ctx.getDb(),
|
ctx.getDb(),
|
||||||
changeControl.getNotes(),
|
notes,
|
||||||
changeControl.getUser(),
|
ctx.getUser(),
|
||||||
psId,
|
psId,
|
||||||
ctx.getAccountId(),
|
ctx.getAccountId(),
|
||||||
ctx.getRevWalk(),
|
ctx.getRevWalk(),
|
||||||
@@ -302,7 +302,7 @@ public class MailProcessor {
|
|||||||
// Fire Gerrit event. Note that approvals can't be granted via email, so old and new approvals
|
// Fire Gerrit event. Note that approvals can't be granted via email, so old and new approvals
|
||||||
// are always the same here.
|
// are always the same here.
|
||||||
commentAdded.fire(
|
commentAdded.fire(
|
||||||
changeControl.getChange(),
|
notes.getChange(),
|
||||||
patchSet,
|
patchSet,
|
||||||
ctx.getAccount(),
|
ctx.getAccount(),
|
||||||
changeMessage.getMessage(),
|
changeMessage.getMessage(),
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import com.google.gerrit.reviewdb.client.Change;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
import com.google.gerrit.server.notedb.ChangeUpdate;
|
import com.google.gerrit.server.notedb.ChangeUpdate;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context for performing the {@link BatchUpdateOp#updateChange} phase.
|
* Context for performing the {@link BatchUpdateOp#updateChange} phase.
|
||||||
@@ -44,14 +43,14 @@ public interface ChangeContext extends Context {
|
|||||||
ChangeUpdate getUpdate(PatchSet.Id psId);
|
ChangeUpdate getUpdate(PatchSet.Id psId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the control for this change, encapsulating the user and up-to-date change data.
|
* Get the up-to-date notes for this change.
|
||||||
*
|
*
|
||||||
* <p>The user will be the same as {@link #getUser()}, and the change data is read within the same
|
* <p>The change data is read within the same transaction that {@link
|
||||||
* transaction that {@link BatchUpdateOp#updateChange(ChangeContext)} is executing.
|
* BatchUpdateOp#updateChange(ChangeContext)} is executing.
|
||||||
*
|
*
|
||||||
* @return control for this change.
|
* @return notes for this change.
|
||||||
*/
|
*/
|
||||||
ChangeControl getControl();
|
ChangeNotes getNotes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Don't bump the value of {@link Change#getLastUpdatedOn()}.
|
* Don't bump the value of {@link Change#getLastUpdatedOn()}.
|
||||||
@@ -70,17 +69,8 @@ public interface ChangeContext extends Context {
|
|||||||
*/
|
*/
|
||||||
void deleteChange();
|
void deleteChange();
|
||||||
|
|
||||||
/**
|
/** @return change corresponding to {@link #getNotes()}. */
|
||||||
* Get notes corresponding to {@link #getControl()}.
|
|
||||||
*
|
|
||||||
* @return loaded notes instance.
|
|
||||||
*/
|
|
||||||
default ChangeNotes getNotes() {
|
|
||||||
return checkNotNull(getControl().getNotes());
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return change corresponding to {@link #getControl()}. */
|
|
||||||
default Change getChange() {
|
default Change getChange() {
|
||||||
return checkNotNull(getControl().getChange());
|
return checkNotNull(getNotes().getChange());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,8 +240,8 @@ class NoteDbBatchUpdate extends BatchUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChangeControl getControl() {
|
public ChangeNotes getNotes() {
|
||||||
return ctl;
|
return ctl.getNotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -209,9 +209,9 @@ class ReviewDbBatchUpdate extends BatchUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChangeControl getControl() {
|
public ChangeNotes getNotes() {
|
||||||
checkNotNull(ctl);
|
checkNotNull(ctl);
|
||||||
return ctl;
|
return ctl.getNotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user