From 2e07d5020195e01cd878a6860fa7507b93352867 Mon Sep 17 00:00:00 2001 From: Gustaf Lundh Date: Wed, 8 May 2013 17:07:42 +0100 Subject: [PATCH] Show granted date for labels/all when using /changes/-api. Change-Id: I54f11119ac4865524351a327d98960771edcc1c8 --- Documentation/rest-api-changes.txt | 2 ++ .../com/google/gerrit/server/change/ChangeJson.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt index dc53d6a368..a5a2fb8d42 100644 --- a/Documentation/rest-api-changes.txt +++ b/Documentation/rest-api-changes.txt @@ -2044,6 +2044,8 @@ In addition `ApprovalInfo` has the following fields: The vote that the user has given for the label. If present and zero, the user is permitted to vote on the label. If absent, the user is not permitted to vote on that label. +|`date` |optional| +The time and date describing when the approval was made. |=========================== [[change-info]] diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java index 3c08bba645..563ab81bb7 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java @@ -470,16 +470,18 @@ public class ChangeJson { continue; } Integer value; + Timestamp date = null; PatchSetApproval psa = current.get(accountId, lt.getName()); if (psa != null) { value = Integer.valueOf(psa.getValue()); + date = psa.getGranted(); } else { // Either the user cannot vote on this label, or there just wasn't a // dummy approval for this label. Explicitly check whether the user // can vote on this label. value = labelNormalizer.canVote(ctl, lt, accountId) ? 0 : null; } - e.getValue().addApproval(approvalInfo(accountId, value)); + e.getValue().addApproval(approvalInfo(accountId, value, date)); } } } @@ -523,7 +525,7 @@ public class ChangeJson { if (detailed) { for (String name : labels.keySet()) { - ApprovalInfo ai = approvalInfo(accountId, 0); + ApprovalInfo ai = approvalInfo(accountId, 0, null); byLabel.put(name, ai); labels.get(name).addApproval(ai); } @@ -538,6 +540,7 @@ public class ChangeJson { ApprovalInfo info = byLabel.get(type.getName()); if (info != null) { info.value = Integer.valueOf(val); + info.date = psa.getGranted(); } LabelInfo li = labels.get(type.getName()); @@ -562,9 +565,10 @@ public class ChangeJson { return labels; } - private ApprovalInfo approvalInfo(Account.Id id, Integer value) { + private ApprovalInfo approvalInfo(Account.Id id, Integer value, Timestamp date) { ApprovalInfo ai = new ApprovalInfo(id); ai.value = value; + ai.date = date; accountLoader.put(ai); return ai; } @@ -918,6 +922,7 @@ public class ChangeJson { static class ApprovalInfo extends AccountInfo { Integer value; + Timestamp date; ApprovalInfo(Account.Id id) { super(id);