]> WPIA git - gigi.git/blob - src/org/cacert/gigi/dbObjects/SupportedUser.java
add: show support and user the account history and the trainings.
[gigi.git] / src / org / cacert / gigi / dbObjects / SupportedUser.java
1 package org.cacert.gigi.dbObjects;
2
3 import java.sql.Date;
4
5 import org.cacert.gigi.GigiApiException;
6 import org.cacert.gigi.database.DatabaseConnection;
7 import org.cacert.gigi.database.GigiPreparedStatement;
8 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
9
10 public class SupportedUser {
11
12     private User target;
13
14     private User supporter;
15
16     private String ticket;
17
18     public SupportedUser(User target, User supporter, String ticket) {
19         this.supporter = supporter;
20         this.target = target;
21         this.ticket = ticket;
22     }
23
24     public boolean setName(Name newName) throws GigiApiException {
25         if (newName.equals(target.getName())) {
26             return false;
27         }
28         writeSELog("SE Name change");
29         target.setName(newName);
30         return true;
31     }
32
33     public boolean setDob(Date dob) throws GigiApiException {
34         if (dob.toString().equals(target.getDoB().toString())) {
35             return false;
36         }
37         writeSELog("SE dob change");
38         target.setDoB(dob);
39         return true;
40     }
41
42     public void revokeAllCertificates() throws GigiApiException {
43         writeSELog("SE Revoke certificates");
44         Certificate[] certs = target.getCertificates(false);
45         // TODO Check for open jobs!
46         for (int i = 0; i < certs.length; i++) {
47             if (certs[i].getStatus() == CertificateStatus.ISSUED) {
48                 certs[i].revoke();
49             }
50         }
51     }
52
53     private void writeSELog(String type) throws GigiApiException {
54         if (ticket == null) {
55             throw new GigiApiException("No ticket set!");
56         }
57         GigiPreparedStatement prep = DatabaseConnection.getInstance().prepare("INSERT INTO `adminLog` SET uid=?, admin=?, type=?, information=?");
58         prep.setInt(1, target.getId());
59         prep.setInt(2, supporter.getId());
60         prep.setString(3, type);
61         prep.setString(4, ticket);
62         prep.executeUpdate();
63     }
64
65     public int getId() {
66         return target.getId();
67     }
68
69     public Certificate[] getCertificates(boolean includeRevoked) {
70         return target.getCertificates(includeRevoked);
71     }
72
73     public String getTicket() {
74         return ticket;
75     }
76
77     public User getTargetUser() {
78         return target;
79     }
80
81     public void submitSupportAction() throws GigiApiException {
82         target.rawUpdateUserData();
83     }
84
85 }