Search in sources :

Example 21 with Change

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;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Change(com.google.gerrit.reviewdb.client.Change) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) SymbolicRef(org.eclipse.jgit.lib.SymbolicRef) Ref(org.eclipse.jgit.lib.Ref)

Example 22 with Change

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);
    }
}
Also used : ChangeBundle(com.google.gerrit.server.notedb.ChangeBundle) ArrayList(java.util.ArrayList) Change(com.google.gerrit.reviewdb.client.Change) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 23 with Change

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));
    }
}
Also used : ChangeBundle(com.google.gerrit.server.notedb.ChangeBundle) Change(com.google.gerrit.reviewdb.client.Change) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 24 with Change

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;
}
Also used : Branch(com.google.gerrit.reviewdb.client.Branch) ObjectId(org.eclipse.jgit.lib.ObjectId) RevId(com.google.gerrit.reviewdb.client.RevId) Change(com.google.gerrit.reviewdb.client.Change)

Example 25 with Change

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);
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Aggregations

Change (com.google.gerrit.reviewdb.client.Change)191 Test (org.junit.Test)96 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)53 ObjectId (org.eclipse.jgit.lib.ObjectId)32 Timestamp (java.sql.Timestamp)31 Account (com.google.gerrit.reviewdb.client.Account)30 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)28 OrmException (com.google.gwtorm.server.OrmException)28 Project (com.google.gerrit.reviewdb.client.Project)27 Repository (org.eclipse.jgit.lib.Repository)27 RevWalk (org.eclipse.jgit.revwalk.RevWalk)24 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)23 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)22 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)21 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)20 RevCommit (org.eclipse.jgit.revwalk.RevCommit)19 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)17 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)17 ChangeData (com.google.gerrit.server.query.change.ChangeData)16 RevId (com.google.gerrit.reviewdb.client.RevId)15