use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.
the class VisibleRefFilter method filter.
public Map<String, Ref> filter(Map<String, Ref> refs, boolean filterTagsSeparately) {
if (projectCtl.getProjectState().isAllUsers()) {
refs = addUsersSelfSymref(refs);
}
if (projectCtl.allRefsAreVisible(ImmutableSet.of(REFS_CONFIG))) {
return fastHideRefsMetaConfig(refs);
}
Account.Id userId;
boolean viewMetadata;
if (projectCtl.getUser().isIdentifiedUser()) {
IdentifiedUser user = projectCtl.getUser().asIdentifiedUser();
userId = user.getAccountId();
viewMetadata = user.getCapabilities().canAccessDatabase();
userEditPrefix = RefNames.refsEditPrefix(userId);
} else {
userId = null;
viewMetadata = false;
}
Map<String, Ref> result = new HashMap<>();
List<Ref> deferredTags = new ArrayList<>();
for (Ref ref : refs.values()) {
String name = ref.getName();
Change.Id changeId;
Account.Id accountId;
if (name.startsWith(REFS_CACHE_AUTOMERGE) || (!showMetadata && isMetadata(projectCtl, name))) {
continue;
} else if (RefNames.isRefsEdit(name)) {
// Edits are visible only to the owning user, if change is visible.
if (viewMetadata || visibleEdit(name)) {
result.put(name, ref);
}
} else if ((changeId = Change.Id.fromRef(name)) != null) {
// Change ref is visible only if the change is visible.
if (viewMetadata || visible(changeId)) {
result.put(name, ref);
}
} else if ((accountId = Account.Id.fromRef(name)) != null) {
// Account ref is visible only to corresponding account.
if (viewMetadata || (accountId.equals(userId) && projectCtl.controlForRef(name).isVisible())) {
result.put(name, ref);
}
} else if (isTag(ref)) {
// If its a tag, consider it later.
if (ref.getObjectId() != null) {
deferredTags.add(ref);
}
} else if (name.startsWith(RefNames.REFS_SEQUENCES)) {
// Sequences are internal database implementation details.
if (viewMetadata) {
result.put(name, ref);
}
} else if (projectCtl.getProjectState().isAllUsers() && name.equals(RefNames.REFS_EXTERNAL_IDS)) {
// The notes branch with the external IDs of all users must not be exposed to normal users.
if (viewMetadata) {
result.put(name, ref);
}
} else if (projectCtl.controlForRef(ref.getLeaf().getName()).isVisible()) {
// Use the leaf to lookup the control data. If the reference is
// symbolic we want the control around the final target. If its
// not symbolic then getLeaf() is a no-op returning ref itself.
result.put(name, ref);
}
}
//
if (!deferredTags.isEmpty() && (!result.isEmpty() || filterTagsSeparately)) {
TagMatcher tags = tagCache.get(projectName).matcher(tagCache, db, filterTagsSeparately ? filter(db.getAllRefs()).values() : result.values());
for (Ref tag : deferredTags) {
if (tags.isReachable(tag)) {
result.put(tag.getName(), tag);
}
}
}
return result;
}
use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.
the class NoteDbChecker method rebuildAndCheckChanges.
private void rebuildAndCheckChanges(Stream<Change.Id> changeIds) throws Exception {
ReviewDb db = getUnwrappedDb();
List<ChangeBundle> allExpected = readExpected(changeIds);
boolean oldWrite = notesMigration.rawWriteChangesSetting();
boolean oldRead = notesMigration.readChanges();
try {
notesMigration.setWriteChanges(true);
notesMigration.setReadChanges(true);
List<String> msgs = new ArrayList<>();
for (ChangeBundle expected : allExpected) {
Change c = expected.getChange();
try {
changeRebuilder.rebuild(db, c.getId());
} catch (RepositoryNotFoundException e) {
msgs.add("Repository not found for change, cannot convert: " + c);
}
}
checkActual(allExpected, msgs);
} finally {
notesMigration.setReadChanges(oldRead);
notesMigration.setWriteChanges(oldWrite);
}
}
use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.
the class NoteDbChecker method checkActual.
private void checkActual(List<ChangeBundle> allExpected, List<String> msgs) throws Exception {
ReviewDb db = getUnwrappedDb();
boolean oldRead = notesMigration.readChanges();
boolean oldWrite = notesMigration.rawWriteChangesSetting();
try {
notesMigration.setWriteChanges(true);
notesMigration.setReadChanges(true);
for (ChangeBundle expected : allExpected) {
Change c = expected.getChange();
ChangeBundle actual;
try {
actual = ChangeBundle.fromNotes(commentsUtil, notesFactory.create(db, c.getProject(), c.getId()));
} catch (Throwable t) {
String msg = "Error converting change: " + c;
msgs.add(msg);
log.error(msg, t);
continue;
}
List<String> diff = expected.differencesFrom(actual);
if (!diff.isEmpty()) {
msgs.add("Differences between ReviewDb and NoteDb for " + c + ":");
msgs.addAll(diff);
msgs.add("");
} else {
System.err.println("NoteDb conversion of change " + c.getId() + " successful");
}
}
} finally {
notesMigration.setReadChanges(oldRead);
notesMigration.setWriteChanges(oldWrite);
}
if (!msgs.isEmpty()) {
throw new AssertionError(Joiner.on('\n').join(msgs));
}
}
use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.
the class TestChanges method newChange.
public static Change newChange(Project.NameKey project, Account.Id userId, int id) {
Change.Id changeId = new Change.Id(id);
Change c = new Change(new Change.Key("Iabcd1234abcd1234abcd1234abcd1234abcd1234"), changeId, userId, new Branch.NameKey(project, "master"), TimeUtil.nowTs());
incrementPatchSet(c);
return c;
}
use of com.google.gerrit.reviewdb.client.Change in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method explicitVisibleTo.
@Test
public void explicitVisibleTo() throws Exception {
TestRepository<Repo> repo = createProject("repo");
Change change1 = insert(repo, newChange(repo), userId);
Change change2 = insert(repo, newChangeWithStatus(repo, Change.Status.DRAFT), userId);
String q = "project:repo";
assertQuery(q, change2, change1);
// Second user cannot see first user's drafts.
Account.Id user2 = accountManager.authenticate(AuthRequest.forUser("anotheruser")).getAccountId();
assertQuery(q + " visibleto:" + user2.get(), change1);
}
Aggregations