ChangeFinder: Return ChangeNotes instead of ChangeControl
Change-Id: Idaeeb7d82cdd314bdc446216d4eee13b7bef5004
This commit is contained in:
@@ -253,6 +253,7 @@ public abstract class AbstractDaemonTest {
|
|||||||
@Inject private InProcessProtocol inProcessProtocol;
|
@Inject private InProcessProtocol inProcessProtocol;
|
||||||
@Inject private Provider<AnonymousUser> anonymousUser;
|
@Inject private Provider<AnonymousUser> anonymousUser;
|
||||||
@Inject private SchemaFactory<ReviewDb> reviewDbProvider;
|
@Inject private SchemaFactory<ReviewDb> reviewDbProvider;
|
||||||
|
@Inject private ChangeControl.GenericFactory changeControlFactory;
|
||||||
|
|
||||||
private List<Repository> toClose;
|
private List<Repository> toClose;
|
||||||
|
|
||||||
@@ -1116,9 +1117,10 @@ public abstract class AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ChangeResource parseChangeResource(String changeId) throws Exception {
|
protected ChangeResource parseChangeResource(String changeId) throws Exception {
|
||||||
List<ChangeControl> ctls = changeFinder.find(changeId, atrScope.get().getUser());
|
List<ChangeNotes> notes = changeFinder.find(changeId);
|
||||||
assertThat(ctls).hasSize(1);
|
assertThat(notes).hasSize(1);
|
||||||
return changeResourceFactory.create(ctls.get(0));
|
return changeResourceFactory.create(
|
||||||
|
changeControlFactory.controlFor(notes.get(0), atrScope.get().getUser()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String createGroup(String name) throws Exception {
|
protected String createGroup(String name) throws Exception {
|
||||||
|
|||||||
@@ -116,7 +116,6 @@ import com.google.gerrit.server.config.AnonymousCowardNameProvider;
|
|||||||
import com.google.gerrit.server.git.ChangeMessageModifier;
|
import com.google.gerrit.server.git.ChangeMessageModifier;
|
||||||
import com.google.gerrit.server.git.ProjectConfig;
|
import com.google.gerrit.server.git.ProjectConfig;
|
||||||
import com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage;
|
import com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
|
||||||
import com.google.gerrit.server.project.Util;
|
import com.google.gerrit.server.project.Util;
|
||||||
import com.google.gerrit.server.update.BatchUpdate;
|
import com.google.gerrit.server.update.BatchUpdate;
|
||||||
import com.google.gerrit.server.update.BatchUpdateOp;
|
import com.google.gerrit.server.update.BatchUpdateOp;
|
||||||
@@ -3304,9 +3303,7 @@ public class ChangeIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ChangeResource parseResource(PushOneCommit.Result r) throws Exception {
|
private ChangeResource parseResource(PushOneCommit.Result r) throws Exception {
|
||||||
List<ChangeControl> ctls = changeFinder.find(r.getChangeId(), atrScope.get().getUser());
|
return parseChangeResource(r.getChangeId());
|
||||||
assertThat(ctls).hasSize(1);
|
|
||||||
return changeResourceFactory.create(ctls.get(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ReviewerState> getReviewerState(String changeId, Account.Id accountId)
|
private Optional<ReviewerState> getReviewerState(String changeId, Account.Id accountId)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import com.google.gerrit.reviewdb.client.Project;
|
|||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.cache.CacheModule;
|
import com.google.gerrit.server.cache.CacheModule;
|
||||||
import com.google.gerrit.server.change.ChangeTriplet;
|
import com.google.gerrit.server.change.ChangeTriplet;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||||
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;
|
||||||
@@ -59,7 +59,7 @@ public class ChangeFinder {
|
|||||||
private final Cache<Change.Id, String> changeIdProjectCache;
|
private final Cache<Change.Id, String> changeIdProjectCache;
|
||||||
private final Provider<InternalChangeQuery> queryProvider;
|
private final Provider<InternalChangeQuery> queryProvider;
|
||||||
private final Provider<ReviewDb> reviewDb;
|
private final Provider<ReviewDb> reviewDb;
|
||||||
private final ChangeControl.GenericFactory changeControlFactory;
|
private final ChangeNotes.Factory changeNotesFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ChangeFinder(
|
ChangeFinder(
|
||||||
@@ -67,24 +67,22 @@ public class ChangeFinder {
|
|||||||
@Named(CACHE_NAME) Cache<Change.Id, String> changeIdProjectCache,
|
@Named(CACHE_NAME) Cache<Change.Id, String> changeIdProjectCache,
|
||||||
Provider<InternalChangeQuery> queryProvider,
|
Provider<InternalChangeQuery> queryProvider,
|
||||||
Provider<ReviewDb> reviewDb,
|
Provider<ReviewDb> reviewDb,
|
||||||
ChangeControl.GenericFactory changeControlFactory) {
|
ChangeNotes.Factory changeNotesFactory) {
|
||||||
this.indexConfig = indexConfig;
|
this.indexConfig = indexConfig;
|
||||||
this.changeIdProjectCache = changeIdProjectCache;
|
this.changeIdProjectCache = changeIdProjectCache;
|
||||||
this.queryProvider = queryProvider;
|
this.queryProvider = queryProvider;
|
||||||
this.reviewDb = reviewDb;
|
this.reviewDb = reviewDb;
|
||||||
this.changeControlFactory = changeControlFactory;
|
this.changeNotesFactory = changeNotesFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find changes matching the given identifier.
|
* Find changes matching the given identifier.
|
||||||
*
|
*
|
||||||
* @param id change identifier, either a numeric ID, a Change-Id, or project~branch~id triplet.
|
* @param id change identifier, either a numeric ID, a Change-Id, or project~branch~id triplet.
|
||||||
* @param user user to wrap in controls.
|
* @return possibly-empty list of notes for all matching changes; may or may not be visible.
|
||||||
* @return possibly-empty list of controls for all matching changes, corresponding to the given
|
|
||||||
* user; may or may not be visible.
|
|
||||||
* @throws OrmException if an error occurred querying the database.
|
* @throws OrmException if an error occurred querying the database.
|
||||||
*/
|
*/
|
||||||
public List<ChangeControl> find(String id, CurrentUser user) throws OrmException {
|
public List<ChangeNotes> find(String id) throws OrmException {
|
||||||
if (id.isEmpty()) {
|
if (id.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
@@ -95,7 +93,7 @@ public class ChangeFinder {
|
|||||||
// Try project~numericChangeId
|
// Try project~numericChangeId
|
||||||
Integer n = Ints.tryParse(id.substring(z + 1));
|
Integer n = Ints.tryParse(id.substring(z + 1));
|
||||||
if (n != null) {
|
if (n != null) {
|
||||||
return fromProjectNumber(user, id.substring(0, z), n.intValue());
|
return fromProjectNumber(id.substring(0, z), n.intValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +101,7 @@ public class ChangeFinder {
|
|||||||
// Try numeric changeId
|
// Try numeric changeId
|
||||||
Integer n = Ints.tryParse(id);
|
Integer n = Ints.tryParse(id);
|
||||||
if (n != null) {
|
if (n != null) {
|
||||||
return find(new Change.Id(n), user);
|
return find(new Change.Id(n));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,33 +113,22 @@ public class ChangeFinder {
|
|||||||
Optional<ChangeTriplet> triplet = ChangeTriplet.parse(id, y, z);
|
Optional<ChangeTriplet> triplet = ChangeTriplet.parse(id, y, z);
|
||||||
if (triplet.isPresent()) {
|
if (triplet.isPresent()) {
|
||||||
ChangeTriplet t = triplet.get();
|
ChangeTriplet t = triplet.get();
|
||||||
return asChangeControls(query.byBranchKey(t.branch(), t.id()), user);
|
return asChangeNotes(query.byBranchKey(t.branch(), t.id()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try isolated Ihash... format ("Change-Id: Ihash").
|
// Try isolated Ihash... format ("Change-Id: Ihash").
|
||||||
return asChangeControls(query.byKeyPrefix(id), user);
|
return asChangeNotes(query.byKeyPrefix(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ChangeControl> fromProjectNumber(CurrentUser user, String project, int changeNumber)
|
private List<ChangeNotes> fromProjectNumber(String project, int changeNumber)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
Change.Id cId = new Change.Id(changeNumber);
|
Change.Id cId = new Change.Id(changeNumber);
|
||||||
try {
|
try {
|
||||||
return ImmutableList.of(
|
return ImmutableList.of(
|
||||||
changeControlFactory.controlFor(
|
changeNotesFactory.createChecked(reviewDb.get(), Project.NameKey.parse(project), cId));
|
||||||
reviewDb.get(), Project.NameKey.parse(project), cId, user));
|
|
||||||
} catch (NoSuchChangeException e) {
|
} catch (NoSuchChangeException e) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
String changeNotFound = String.format("change %s not found in ReviewDb", cId);
|
|
||||||
String projectNotFound =
|
|
||||||
String.format(
|
|
||||||
"passed project %s when creating ChangeNotes for %s, but actual project is",
|
|
||||||
project, cId);
|
|
||||||
if (e.getMessage().equals(changeNotFound) || e.getMessage().startsWith(projectNotFound)) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
} catch (OrmException e) {
|
} catch (OrmException e) {
|
||||||
// Distinguish between a RepositoryNotFoundException (project argument invalid) and
|
// Distinguish between a RepositoryNotFoundException (project argument invalid) and
|
||||||
// other OrmExceptions (failure in the persistence layer).
|
// other OrmExceptions (failure in the persistence layer).
|
||||||
@@ -152,18 +139,18 @@ public class ChangeFinder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangeControl findOne(Change.Id id, CurrentUser user) throws OrmException {
|
public ChangeNotes findOne(Change.Id id) throws OrmException {
|
||||||
List<ChangeControl> ctls = find(id, user);
|
List<ChangeNotes> notes = find(id);
|
||||||
if (ctls.size() != 1) {
|
if (notes.size() != 1) {
|
||||||
throw new NoSuchChangeException(id);
|
throw new NoSuchChangeException(id);
|
||||||
}
|
}
|
||||||
return ctls.get(0);
|
return notes.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ChangeControl> find(Change.Id id, CurrentUser user) throws OrmException {
|
public List<ChangeNotes> find(Change.Id id) throws OrmException {
|
||||||
String project = changeIdProjectCache.getIfPresent(id);
|
String project = changeIdProjectCache.getIfPresent(id);
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
return fromProjectNumber(user, project, id.get());
|
return fromProjectNumber(project, id.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the index to search for changes, but don't return any stored fields,
|
// Use the index to search for changes, but don't return any stored fields,
|
||||||
@@ -173,17 +160,16 @@ public class ChangeFinder {
|
|||||||
if (r.size() == 1) {
|
if (r.size() == 1) {
|
||||||
changeIdProjectCache.put(id, r.get(0).project().get());
|
changeIdProjectCache.put(id, r.get(0).project().get());
|
||||||
}
|
}
|
||||||
return asChangeControls(r, user);
|
return asChangeNotes(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ChangeControl> asChangeControls(List<ChangeData> cds, CurrentUser user)
|
private List<ChangeNotes> asChangeNotes(List<ChangeData> cds) throws OrmException {
|
||||||
throws OrmException {
|
List<ChangeNotes> notes = new ArrayList<>(cds.size());
|
||||||
List<ChangeControl> ctls = new ArrayList<>(cds.size());
|
|
||||||
if (!indexConfig.separateChangeSubIndexes()) {
|
if (!indexConfig.separateChangeSubIndexes()) {
|
||||||
for (ChangeData cd : cds) {
|
for (ChangeData cd : cds) {
|
||||||
checkedAdd(cd, ctls, user);
|
notes.add(cd.notes());
|
||||||
}
|
}
|
||||||
return ctls;
|
return notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an index implementation uses separate non-atomic subindexes, it's possible to temporarily
|
// If an index implementation uses separate non-atomic subindexes, it's possible to temporarily
|
||||||
@@ -195,18 +181,9 @@ public class ChangeFinder {
|
|||||||
Set<Change.Id> seen = Sets.newHashSetWithExpectedSize(cds.size());
|
Set<Change.Id> seen = Sets.newHashSetWithExpectedSize(cds.size());
|
||||||
for (ChangeData cd : cds) {
|
for (ChangeData cd : cds) {
|
||||||
if (seen.add(cd.getId())) {
|
if (seen.add(cd.getId())) {
|
||||||
checkedAdd(cd, ctls, user);
|
notes.add(cd.notes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ctls;
|
return notes;
|
||||||
}
|
|
||||||
|
|
||||||
private static void checkedAdd(ChangeData cd, List<ChangeControl> ctls, CurrentUser user)
|
|
||||||
throws OrmException {
|
|
||||||
try {
|
|
||||||
ctls.add(cd.changeControl(user));
|
|
||||||
} catch (NoSuchChangeException e) {
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,10 +26,12 @@ import com.google.gerrit.reviewdb.client.Change;
|
|||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.ChangeFinder;
|
import com.google.gerrit.server.ChangeFinder;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
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.ChangeControl;
|
||||||
|
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||||
import com.google.gerrit.server.query.change.QueryChanges;
|
import com.google.gerrit.server.query.change.QueryChanges;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -48,6 +50,7 @@ public class ChangesCollection
|
|||||||
private final CreateChange createChange;
|
private final CreateChange createChange;
|
||||||
private final ChangeResource.Factory changeResourceFactory;
|
private final ChangeResource.Factory changeResourceFactory;
|
||||||
private final PermissionBackend permissionBackend;
|
private final PermissionBackend permissionBackend;
|
||||||
|
private final ChangeControl.GenericFactory changeControlFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ChangesCollection(
|
ChangesCollection(
|
||||||
@@ -58,7 +61,8 @@ public class ChangesCollection
|
|||||||
ChangeFinder changeFinder,
|
ChangeFinder changeFinder,
|
||||||
CreateChange createChange,
|
CreateChange createChange,
|
||||||
ChangeResource.Factory changeResourceFactory,
|
ChangeResource.Factory changeResourceFactory,
|
||||||
PermissionBackend permissionBackend) {
|
PermissionBackend permissionBackend,
|
||||||
|
ChangeControl.GenericFactory changeControlFactory) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
@@ -67,6 +71,7 @@ public class ChangesCollection
|
|||||||
this.createChange = createChange;
|
this.createChange = createChange;
|
||||||
this.changeResourceFactory = changeResourceFactory;
|
this.changeResourceFactory = changeResourceFactory;
|
||||||
this.permissionBackend = permissionBackend;
|
this.permissionBackend = permissionBackend;
|
||||||
|
this.changeControlFactory = changeControlFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -82,34 +87,34 @@ public class ChangesCollection
|
|||||||
@Override
|
@Override
|
||||||
public ChangeResource parse(TopLevelResource root, IdString id)
|
public ChangeResource parse(TopLevelResource root, IdString id)
|
||||||
throws ResourceNotFoundException, OrmException, PermissionBackendException {
|
throws ResourceNotFoundException, OrmException, PermissionBackendException {
|
||||||
List<ChangeControl> ctls = changeFinder.find(id.encoded(), user.get());
|
List<ChangeNotes> notes = changeFinder.find(id.encoded());
|
||||||
if (ctls.isEmpty()) {
|
if (notes.isEmpty()) {
|
||||||
throw new ResourceNotFoundException(id);
|
throw new ResourceNotFoundException(id);
|
||||||
} else if (ctls.size() != 1) {
|
} else if (notes.size() != 1) {
|
||||||
throw new ResourceNotFoundException("Multiple changes found for " + id);
|
throw new ResourceNotFoundException("Multiple changes found for " + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChangeControl ctl = ctls.get(0);
|
ChangeNotes change = notes.get(0);
|
||||||
if (!canRead(ctl)) {
|
if (!canRead(change)) {
|
||||||
throw new ResourceNotFoundException(id);
|
throw new ResourceNotFoundException(id);
|
||||||
}
|
}
|
||||||
return changeResourceFactory.create(ctl);
|
return changeResourceFactory.create(controlFor(change));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChangeResource parse(Change.Id id)
|
public ChangeResource parse(Change.Id id)
|
||||||
throws ResourceNotFoundException, OrmException, PermissionBackendException {
|
throws ResourceNotFoundException, OrmException, PermissionBackendException {
|
||||||
List<ChangeControl> ctls = changeFinder.find(id, user.get());
|
List<ChangeNotes> notes = changeFinder.find(id);
|
||||||
if (ctls.isEmpty()) {
|
if (notes.isEmpty()) {
|
||||||
throw new ResourceNotFoundException(toIdString(id));
|
throw new ResourceNotFoundException(toIdString(id));
|
||||||
} else if (ctls.size() != 1) {
|
} else if (notes.size() != 1) {
|
||||||
throw new ResourceNotFoundException("Multiple changes found for " + id);
|
throw new ResourceNotFoundException("Multiple changes found for " + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChangeControl ctl = ctls.get(0);
|
ChangeNotes change = notes.get(0);
|
||||||
if (!canRead(ctl)) {
|
if (!canRead(change)) {
|
||||||
throw new ResourceNotFoundException(toIdString(id));
|
throw new ResourceNotFoundException(toIdString(id));
|
||||||
}
|
}
|
||||||
return changeResourceFactory.create(ctl);
|
return changeResourceFactory.create(controlFor(change));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IdString toIdString(Change.Id id) {
|
private static IdString toIdString(Change.Id id) {
|
||||||
@@ -126,11 +131,16 @@ public class ChangesCollection
|
|||||||
return createChange;
|
return createChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canRead(ChangeControl ctl) throws PermissionBackendException {
|
private boolean canRead(ChangeNotes notes) throws PermissionBackendException {
|
||||||
return permissionBackend
|
return permissionBackend.user(user).change(notes).database(db).test(ChangePermission.READ);
|
||||||
.user(user)
|
}
|
||||||
.change(ctl.getNotes())
|
|
||||||
.database(db)
|
private ChangeControl controlFor(ChangeNotes notes) throws ResourceNotFoundException {
|
||||||
.test(ChangePermission.READ);
|
try {
|
||||||
|
return changeControlFactory.controlFor(notes, user.get());
|
||||||
|
} catch (NoSuchChangeException e) {
|
||||||
|
throw new ResourceNotFoundException(
|
||||||
|
String.format("Change %s not found", notes.getChangeId()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ import com.google.gerrit.server.config.AnonymousCowardName;
|
|||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.git.MergeUtil;
|
import com.google.gerrit.server.git.MergeUtil;
|
||||||
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
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.permissions.RefPermission;
|
import com.google.gerrit.server.permissions.RefPermission;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
|
||||||
import com.google.gerrit.server.project.CommitsCollection;
|
import com.google.gerrit.server.project.CommitsCollection;
|
||||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
@@ -194,19 +194,15 @@ public class CreateChange
|
|||||||
ObjectId parentCommit;
|
ObjectId parentCommit;
|
||||||
List<String> groups;
|
List<String> groups;
|
||||||
if (input.baseChange != null) {
|
if (input.baseChange != null) {
|
||||||
List<ChangeControl> ctls = changeFinder.find(input.baseChange, rsrc.getUser());
|
List<ChangeNotes> notes = changeFinder.find(input.baseChange);
|
||||||
if (ctls.size() != 1) {
|
if (notes.size() != 1) {
|
||||||
throw new UnprocessableEntityException("Base change not found: " + input.baseChange);
|
throw new UnprocessableEntityException("Base change not found: " + input.baseChange);
|
||||||
}
|
}
|
||||||
ChangeControl ctl = Iterables.getOnlyElement(ctls);
|
ChangeNotes change = Iterables.getOnlyElement(notes);
|
||||||
if (!permissionBackend
|
if (!permissionBackend.user(user).change(change).database(db).test(ChangePermission.READ)) {
|
||||||
.user(user)
|
|
||||||
.change(ctl.getNotes())
|
|
||||||
.database(db)
|
|
||||||
.test(ChangePermission.READ)) {
|
|
||||||
throw new UnprocessableEntityException("Base change not found: " + input.baseChange);
|
throw new UnprocessableEntityException("Base change not found: " + input.baseChange);
|
||||||
}
|
}
|
||||||
PatchSet ps = psUtil.current(db.get(), ctl.getNotes());
|
PatchSet ps = psUtil.current(db.get(), change);
|
||||||
parentCommit = ObjectId.fromString(ps.getRevision().get());
|
parentCommit = ObjectId.fromString(ps.getRevision().get());
|
||||||
groups = ps.getGroups();
|
groups = ps.getGroups();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
|
|||||||
// Prepopulate the change exists with proper noteDbState field.
|
// Prepopulate the change exists with proper noteDbState field.
|
||||||
change = newNoteDbOnlyChange(project, changeId);
|
change = newNoteDbOnlyChange(project, changeId);
|
||||||
} else {
|
} else {
|
||||||
checkArgument(change != null, "change %s not found in ReviewDb", changeId);
|
checkNotNull(change, "change %s not found in ReviewDb", changeId);
|
||||||
checkArgument(
|
checkArgument(
|
||||||
change.getProject().equals(project),
|
change.getProject().equals(project),
|
||||||
"passed project %s when creating ChangeNotes for %s, but actual project is %s",
|
"passed project %s when creating ChangeNotes for %s, but actual project is %s",
|
||||||
|
|||||||
@@ -14,9 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.sshd;
|
package com.google.gerrit.sshd;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
|
||||||
|
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
|
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
@@ -30,7 +29,6 @@ import com.google.gerrit.server.permissions.GlobalPermission;
|
|||||||
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.ChangeControl;
|
||||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
import com.google.gerrit.sshd.BaseCommand.UnloggedFailure;
|
import com.google.gerrit.sshd.BaseCommand.UnloggedFailure;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
@@ -39,7 +37,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class ChangeArgumentParser {
|
public class ChangeArgumentParser {
|
||||||
private final CurrentUser currentUser;
|
private final CurrentUser currentUser;
|
||||||
@@ -85,9 +82,8 @@ public class ChangeArgumentParser {
|
|||||||
ProjectControl projectControl,
|
ProjectControl projectControl,
|
||||||
boolean useIndex)
|
boolean useIndex)
|
||||||
throws UnloggedFailure, OrmException, PermissionBackendException {
|
throws UnloggedFailure, OrmException, PermissionBackendException {
|
||||||
List<ChangeControl> matched =
|
List<ChangeNotes> matched = useIndex ? changeFinder.find(id) : changeFromNotesFactory(id);
|
||||||
useIndex ? changeFinder.find(id, currentUser) : changeFromNotesFactory(id, currentUser);
|
List<ChangeNotes> toAdd = new ArrayList<>(changes.size());
|
||||||
List<ChangeControl> toAdd = new ArrayList<>(changes.size());
|
|
||||||
boolean canMaintainServer;
|
boolean canMaintainServer;
|
||||||
try {
|
try {
|
||||||
permissionBackend.user(currentUser).check(GlobalPermission.MAINTAIN_SERVER);
|
permissionBackend.user(currentUser).check(GlobalPermission.MAINTAIN_SERVER);
|
||||||
@@ -95,16 +91,16 @@ public class ChangeArgumentParser {
|
|||||||
} catch (AuthException | PermissionBackendException e) {
|
} catch (AuthException | PermissionBackendException e) {
|
||||||
canMaintainServer = false;
|
canMaintainServer = false;
|
||||||
}
|
}
|
||||||
for (ChangeControl ctl : matched) {
|
for (ChangeNotes notes : matched) {
|
||||||
if (!changes.containsKey(ctl.getId())
|
if (!changes.containsKey(notes.getChangeId())
|
||||||
&& inProject(projectControl, ctl.getProject())
|
&& inProject(projectControl, notes.getProjectName())
|
||||||
&& (canMaintainServer
|
&& (canMaintainServer
|
||||||
|| permissionBackend
|
|| permissionBackend
|
||||||
.user(currentUser)
|
.user(currentUser)
|
||||||
.change(ctl.getNotes())
|
.change(notes)
|
||||||
.database(db)
|
.database(db)
|
||||||
.test(ChangePermission.READ))) {
|
.test(ChangePermission.READ))) {
|
||||||
toAdd.add(ctl);
|
toAdd.add(notes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,19 +109,18 @@ public class ChangeArgumentParser {
|
|||||||
} else if (toAdd.size() > 1) {
|
} else if (toAdd.size() > 1) {
|
||||||
throw new UnloggedFailure(1, "\"" + id + "\" matches multiple changes");
|
throw new UnloggedFailure(1, "\"" + id + "\" matches multiple changes");
|
||||||
}
|
}
|
||||||
ChangeControl ctl = toAdd.get(0);
|
Change.Id cId = toAdd.get(0).getChangeId();
|
||||||
changes.put(ctl.getId(), changesCollection.parse(ctl));
|
ChangeResource changeResource;
|
||||||
|
try {
|
||||||
|
changeResource = changesCollection.parse(cId);
|
||||||
|
} catch (ResourceNotFoundException e) {
|
||||||
|
throw new UnloggedFailure(1, "\"" + id + "\" no such change");
|
||||||
|
}
|
||||||
|
changes.put(cId, changeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ChangeControl> changeFromNotesFactory(String id, CurrentUser currentUser)
|
private List<ChangeNotes> changeFromNotesFactory(String id) throws OrmException, UnloggedFailure {
|
||||||
throws OrmException, UnloggedFailure {
|
return changeNotesFactory.create(db, parseId(id));
|
||||||
return changeNotesFactory
|
|
||||||
.create(db, parseId(id))
|
|
||||||
.stream()
|
|
||||||
.map(changeNote -> controlForChange(changeNote, currentUser))
|
|
||||||
.filter(changeControl -> changeControl.isPresent())
|
|
||||||
.map(changeControl -> changeControl.get())
|
|
||||||
.collect(toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Change.Id> parseId(String id) throws UnloggedFailure {
|
private List<Change.Id> parseId(String id) throws UnloggedFailure {
|
||||||
@@ -136,17 +131,9 @@ public class ChangeArgumentParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ChangeControl> controlForChange(ChangeNotes change, CurrentUser user) {
|
private boolean inProject(ProjectControl projectControl, Project.NameKey project) {
|
||||||
try {
|
|
||||||
return Optional.of(changeControlFactory.controlFor(change, user));
|
|
||||||
} catch (NoSuchChangeException e) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean inProject(ProjectControl projectControl, Project project) {
|
|
||||||
if (projectControl != null) {
|
if (projectControl != null) {
|
||||||
return projectControl.getProject().getNameKey().equals(project.getNameKey());
|
return projectControl.getProject().getNameKey().equals(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No --project option, so they want every project.
|
// No --project option, so they want every project.
|
||||||
|
|||||||
@@ -21,10 +21,8 @@ import com.google.gerrit.reviewdb.client.Project;
|
|||||||
import com.google.gerrit.reviewdb.client.RevId;
|
import com.google.gerrit.reviewdb.client.RevId;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.ChangeFinder;
|
import com.google.gerrit.server.ChangeFinder;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
|
||||||
import com.google.gerrit.server.PatchSetUtil;
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
|
||||||
import com.google.gerrit.server.project.NoSuchChangeException;
|
import com.google.gerrit.server.project.NoSuchChangeException;
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
@@ -44,7 +42,6 @@ public class PatchSetParser {
|
|||||||
private final ChangeNotes.Factory notesFactory;
|
private final ChangeNotes.Factory notesFactory;
|
||||||
private final PatchSetUtil psUtil;
|
private final PatchSetUtil psUtil;
|
||||||
private final ChangeFinder changeFinder;
|
private final ChangeFinder changeFinder;
|
||||||
private final Provider<CurrentUser> self;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PatchSetParser(
|
PatchSetParser(
|
||||||
@@ -52,14 +49,12 @@ public class PatchSetParser {
|
|||||||
Provider<InternalChangeQuery> queryProvider,
|
Provider<InternalChangeQuery> queryProvider,
|
||||||
ChangeNotes.Factory notesFactory,
|
ChangeNotes.Factory notesFactory,
|
||||||
PatchSetUtil psUtil,
|
PatchSetUtil psUtil,
|
||||||
ChangeFinder changeFinder,
|
ChangeFinder changeFinder) {
|
||||||
Provider<CurrentUser> self) {
|
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.queryProvider = queryProvider;
|
this.queryProvider = queryProvider;
|
||||||
this.notesFactory = notesFactory;
|
this.notesFactory = notesFactory;
|
||||||
this.psUtil = psUtil;
|
this.psUtil = psUtil;
|
||||||
this.changeFinder = changeFinder;
|
this.changeFinder = changeFinder;
|
||||||
this.self = self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PatchSet parsePatchSet(String token, ProjectControl projectControl, String branch)
|
public PatchSet parsePatchSet(String token, ProjectControl projectControl, String branch)
|
||||||
@@ -141,8 +136,8 @@ public class PatchSetParser {
|
|||||||
return notesFactory.create(db.get(), projectControl.getProject().getNameKey(), changeId);
|
return notesFactory.create(db.get(), projectControl.getProject().getNameKey(), changeId);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ChangeControl ctl = changeFinder.findOne(changeId, self.get());
|
ChangeNotes notes = changeFinder.findOne(changeId);
|
||||||
return notesFactory.create(db.get(), ctl.getProject().getNameKey(), changeId);
|
return notesFactory.create(db.get(), notes.getProjectName(), changeId);
|
||||||
} catch (NoSuchChangeException e) {
|
} catch (NoSuchChangeException e) {
|
||||||
throw error("\"" + changeId + "\" no such change");
|
throw error("\"" + changeId + "\" no such change");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user