]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/dbObjects/SupportedUser.java
Enforce Date-of-births to be day-only.
[gigi.git] / src / org / cacert / gigi / dbObjects / SupportedUser.java
index 58755059e27cddf15342b2513d3018881befd25d..df5b54e88d0c5d5753c7bcfa4c4acf2ae3390dad 100644 (file)
@@ -1,14 +1,15 @@
 package org.cacert.gigi.dbObjects;
 
-import java.sql.Date;
-
 import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
+import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
+import org.cacert.gigi.util.DayDate;
 
 public class SupportedUser {
 
-    private User target, supporter;
+    private User target;
+
+    private User supporter;
 
     private String ticket;
 
@@ -27,8 +28,8 @@ public class SupportedUser {
         return true;
     }
 
-    public boolean setDob(Date dob) throws GigiApiException {
-        if (dob.toString().equals(target.getDoB().toString())) {
+    public boolean setDob(DayDate dob) throws GigiApiException {
+        if (dob.equals(target.getDoB())) {
             return false;
         }
         writeSELog("SE dob change");
@@ -39,8 +40,11 @@ public class SupportedUser {
     public void revokeAllCertificates() throws GigiApiException {
         writeSELog("SE Revoke certificates");
         Certificate[] certs = target.getCertificates(false);
+        // TODO Check for open jobs!
         for (int i = 0; i < certs.length; i++) {
-            certs[i].revoke();
+            if (certs[i].getStatus() == CertificateStatus.ISSUED) {
+                certs[i].revoke();
+            }
         }
     }
 
@@ -48,12 +52,13 @@ public class SupportedUser {
         if (ticket == null) {
             throw new GigiApiException("No ticket set!");
         }
-        GigiPreparedStatement prep = DatabaseConnection.getInstance().prepare("INSERT INTO adminLog SET uid=?, admin=?, type=?, information=?");
-        prep.setInt(1, target.getId());
-        prep.setInt(2, supporter.getId());
-        prep.setString(3, type);
-        prep.setString(4, ticket);
-        prep.executeUpdate();
+        try (GigiPreparedStatement prep = new GigiPreparedStatement("INSERT INTO `adminLog` SET uid=?, admin=?, type=?, information=?")) {
+            prep.setInt(1, target.getId());
+            prep.setInt(2, supporter.getId());
+            prep.setString(3, type);
+            prep.setString(4, ticket);
+            prep.executeUpdate();
+        }
     }
 
     public int getId() {
@@ -76,4 +81,12 @@ public class SupportedUser {
         target.rawUpdateUserData();
     }
 
+    public void grant(Group toMod) {
+        target.grantGroup(supporter, toMod);
+    }
+
+    public void revoke(Group toMod) {
+        target.revokeGroup(supporter, toMod);
+    }
+
 }