Search in sources :

Example 21 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.PatchSetApproval in project gerrit by GerritCodeReview.

the class AbstractSubmit method assertNoSubmitter.

protected void assertNoSubmitter(String changeId, int psId) throws Exception {
    Change c = getOnlyElement(queryProvider.get().byKeyPrefix(changeId)).change();
    ChangeNotes cn = notesFactory.createChecked(db, c);
    PatchSetApproval submitter = approvalsUtil.getSubmitter(db, cn, new PatchSet.Id(cn.getChangeId(), psId));
    assertThat(submitter).isNull();
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 22 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.PatchSetApproval in project gerrit by GerritCodeReview.

the class ImpersonationIT method voteOnBehalfOf.

@Test
public void voteOnBehalfOf() throws Exception {
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    RevisionApi revision = gApi.changes().id(r.getChangeId()).current();
    ReviewInput in = ReviewInput.recommend();
    in.onBehalfOf = user.id.toString();
    in.message = "Message on behalf of";
    revision.review(in);
    PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
    assertThat(psa.getPatchSetId().get()).isEqualTo(1);
    assertThat(psa.getLabel()).isEqualTo("Code-Review");
    assertThat(psa.getAccountId()).isEqualTo(user.id);
    assertThat(psa.getValue()).isEqualTo(1);
    assertThat(psa.getRealAccountId()).isEqualTo(admin.id);
    ChangeData cd = r.getChange();
    ChangeMessage m = Iterables.getLast(cmUtil.byChange(db, cd.notes()));
    assertThat(m.getMessage()).endsWith(in.message);
    assertThat(m.getAuthor()).isEqualTo(user.id);
    assertThat(m.getRealAuthor()).isEqualTo(admin.id);
}
Also used : RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 23 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.PatchSetApproval in project gerrit by GerritCodeReview.

the class ImpersonationIT method testVoteOnBehalfOfWithComment.

private void testVoteOnBehalfOfWithComment() throws Exception {
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id.toString();
    in.label("Code-Review", 1);
    CommentInput ci = new CommentInput();
    ci.path = Patch.COMMIT_MSG;
    ci.side = Side.REVISION;
    ci.line = 1;
    ci.message = "message";
    in.comments = ImmutableMap.of(ci.path, ImmutableList.of(ci));
    gApi.changes().id(r.getChangeId()).current().review(in);
    PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
    assertThat(psa.getPatchSetId().get()).isEqualTo(1);
    assertThat(psa.getLabel()).isEqualTo("Code-Review");
    assertThat(psa.getAccountId()).isEqualTo(user.id);
    assertThat(psa.getValue()).isEqualTo(1);
    assertThat(psa.getRealAccountId()).isEqualTo(admin.id);
    ChangeData cd = r.getChange();
    Comment c = Iterables.getOnlyElement(commentsUtil.publishedByChange(db, cd.notes()));
    assertThat(c.message).isEqualTo(ci.message);
    assertThat(c.author.getId()).isEqualTo(user.id);
    assertThat(c.getRealAuthor().getId()).isEqualTo(admin.id);
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) RobotComment(com.google.gerrit.reviewdb.client.RobotComment) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 24 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeJson method currentLabels.

private Map<String, Short> currentLabels(PermissionBackend.ForChange perm, ChangeData cd) throws OrmException {
    IdentifiedUser user = perm.user().asIdentifiedUser();
    ChangeControl ctl = cd.changeControl().forUser(user);
    Map<String, Short> result = new HashMap<>();
    for (PatchSetApproval psa : approvalsUtil.byPatchSetUser(db.get(), ctl, cd.change().currentPatchSetId(), user.getAccountId())) {
        result.put(psa.getLabel(), psa.getValue());
    }
    return result;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ChangeControl(com.google.gerrit.server.project.ChangeControl) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 25 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeJson method setAllApprovals.

private void setAllApprovals(PermissionBackend.ForChange basePerm, ChangeData cd, Map<String, LabelWithStatus> labels) throws OrmException, PermissionBackendException {
    Change.Status status = cd.change().getStatus();
    checkState(status.isOpen(), "should not call setAllApprovals on %s change", status);
    // Include a user in the output for this label if either:
    //  - They are an explicit reviewer.
    //  - They ever voted on this change.
    Set<Account.Id> allUsers = new HashSet<>();
    allUsers.addAll(cd.reviewers().byState(ReviewerStateInternal.REVIEWER));
    for (PatchSetApproval psa : cd.approvals().values()) {
        allUsers.add(psa.getAccountId());
    }
    Table<Account.Id, String, PatchSetApproval> current = HashBasedTable.create(allUsers.size(), cd.getLabelTypes().getLabelTypes().size());
    for (PatchSetApproval psa : cd.currentApprovals()) {
        current.put(psa.getAccountId(), psa.getLabel(), psa);
    }
    LabelTypes labelTypes = cd.getLabelTypes();
    for (Account.Id accountId : allUsers) {
        PermissionBackend.ForChange perm = basePerm.user(userFactory.create(accountId));
        Map<String, VotingRangeInfo> pvr = getPermittedVotingRanges(permittedLabels(perm, cd));
        for (Map.Entry<String, LabelWithStatus> e : labels.entrySet()) {
            LabelType lt = labelTypes.byLabel(e.getKey());
            if (lt == null) {
                // author didn't intend for the label to show up in the table.
                continue;
            }
            Integer value;
            VotingRangeInfo permittedVotingRange = pvr.getOrDefault(lt.getName(), null);
            String tag = null;
            Timestamp date = null;
            PatchSetApproval psa = current.get(accountId, lt.getName());
            if (psa != null) {
                value = Integer.valueOf(psa.getValue());
                if (value == 0) {
                    // This may be a dummy approval that was inserted when the reviewer
                    // was added. Explicitly check whether the user can vote on this
                    // label.
                    value = perm.test(new LabelPermission(lt)) ? 0 : null;
                }
                tag = psa.getTag();
                date = psa.getGranted();
                if (psa.isPostSubmit()) {
                    log.warn("unexpected post-submit approval on open change: {}", psa);
                }
            } else {
                // Either the user cannot vote on this label, or they were added as a
                // reviewer but have not responded yet. Explicitly check whether the
                // user can vote on this label.
                value = perm.test(new LabelPermission(lt)) ? 0 : null;
            }
            addApproval(e.getValue().label(), approvalInfo(accountId, value, permittedVotingRange, tag, date));
        }
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) LabelTypes(com.google.gerrit.common.data.LabelTypes) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) VotingRangeInfo(com.google.gerrit.extensions.common.VotingRangeInfo) Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Timestamp(java.sql.Timestamp) LabelType(com.google.gerrit.common.data.LabelType) ObjectId(org.eclipse.jgit.lib.ObjectId) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LabelPermission(com.google.gerrit.server.permissions.LabelPermission) HashSet(java.util.HashSet)

Aggregations

PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)71 Change (com.google.gerrit.reviewdb.client.Change)37 Test (org.junit.Test)32 Account (com.google.gerrit.reviewdb.client.Account)17 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)17 LabelType (com.google.gerrit.common.data.LabelType)14 LabelId (com.google.gerrit.reviewdb.client.LabelId)13 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)10 ChangeData (com.google.gerrit.server.query.change.ChangeData)10 ObjectId (org.eclipse.jgit.lib.ObjectId)10 RevId (com.google.gerrit.reviewdb.client.RevId)8 Timestamp (java.sql.Timestamp)8 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)7 HashMap (java.util.HashMap)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 LabelTypes (com.google.gerrit.common.data.LabelTypes)6 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 RequestId (com.google.gerrit.server.util.RequestId)5