Allow gerrit approve to post comments on closed changes

The web UI permits comments on closed changes, so we should do the
same thing with the SSH based approve command.  However like the
web we need to ignore the vote flags if its closed, as those cannot
be changed.

Bug: issue 488
Change-Id: I366b41785eea27b939f44ea2c2613a8d67a57001
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ApproveCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ApproveCommand.java
index 9bdba23..ac61c33 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ApproveCommand.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ApproveCommand.java
@@ -151,9 +151,6 @@
     final ChangeControl changeControl =
         changeControlFactory.validateFor(changeId);
     final Change change = changeControl.getChange();
-    if (change.getStatus().isClosed()) {
-      throw error("change " + changeId + " is closed");
-    }
 
     final StringBuffer msgBuf = new StringBuffer();
     msgBuf.append("Patch Set ");
@@ -163,32 +160,34 @@
     final Map<ApprovalCategory.Id, ApprovalCategoryValue.Id> approvalsMap =
         new HashMap<ApprovalCategory.Id, ApprovalCategoryValue.Id>();
 
-    for (ApproveOption co : optionList) {
-      final ApprovalCategory.Id category = co.getCategoryId();
-      PatchSetApproval.Key psaKey =
-          new PatchSetApproval.Key(patchSetId, currentUser.getAccountId(),
-              category);
-      PatchSetApproval psa = db.patchSetApprovals().get(psaKey);
+    if (change.getStatus().isOpen()) {
+      for (ApproveOption co : optionList) {
+        final ApprovalCategory.Id category = co.getCategoryId();
+        PatchSetApproval.Key psaKey =
+            new PatchSetApproval.Key(patchSetId, currentUser.getAccountId(),
+                category);
+        PatchSetApproval psa = db.patchSetApprovals().get(psaKey);
 
-      Short score = co.value();
+        Short score = co.value();
 
-      if (score != null) {
-        addApproval(psaKey, score, change, co);
-      } else {
-        if (psa == null) {
-          score = 0;
+        if (score != null) {
           addApproval(psaKey, score, change, co);
         } else {
-          score = psa.getValue();
+          if (psa == null) {
+            score = 0;
+            addApproval(psaKey, score, change, co);
+          } else {
+            score = psa.getValue();
+          }
         }
+
+        final ApprovalCategoryValue.Id val =
+            new ApprovalCategoryValue.Id(category, score);
+
+        String message = db.approvalCategoryValues().get(val).getName();
+        msgBuf.append(" " + message + ";");
+        approvalsMap.put(category, val);
       }
-
-      final ApprovalCategoryValue.Id val =
-          new ApprovalCategoryValue.Id(category, score);
-
-      String message = db.approvalCategoryValues().get(val).getName();
-      msgBuf.append(" " + message + ";");
-      approvalsMap.put(category, val);
     }
 
     msgBuf.deleteCharAt(msgBuf.length() - 1);