1 package org.cacert.gigi.dbObjects;
3 import org.cacert.gigi.GigiApiException;
4 import org.cacert.gigi.database.GigiPreparedStatement;
5 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
6 import org.cacert.gigi.util.DayDate;
8 public class SupportedUser {
12 private User supporter;
14 private String ticket;
16 public SupportedUser(User target, User supporter, String ticket) {
17 this.supporter = supporter;
22 public boolean setName(Name newName) throws GigiApiException {
23 if (newName.equals(target.getName())) {
26 writeSELog("SE Name change");
27 target.setName(newName);
31 public boolean setDob(DayDate dob) throws GigiApiException {
32 if (dob.equals(target.getDoB())) {
35 writeSELog("SE dob change");
40 public void revokeAllCertificates() throws GigiApiException {
41 writeSELog("SE Revoke certificates");
42 Certificate[] certs = target.getCertificates(false);
43 // TODO Check for open jobs!
44 for (int i = 0; i < certs.length; i++) {
45 if (certs[i].getStatus() == CertificateStatus.ISSUED) {
51 private void writeSELog(String type) throws GigiApiException {
53 throw new GigiApiException("No ticket set!");
55 try (GigiPreparedStatement prep = new GigiPreparedStatement("INSERT INTO `adminLog` SET uid=?, admin=?, type=?, information=?")) {
56 prep.setInt(1, target.getId());
57 prep.setInt(2, supporter.getId());
58 prep.setString(3, type);
59 prep.setString(4, ticket);
65 return target.getId();
68 public Certificate[] getCertificates(boolean includeRevoked) {
69 return target.getCertificates(includeRevoked);
72 public String getTicket() {
76 public User getTargetUser() {
80 public void submitSupportAction() throws GigiApiException {
81 target.rawUpdateUserData();
84 public void grant(Group toMod) {
85 target.grantGroup(supporter, toMod);
88 public void revoke(Group toMod) {
89 target.revokeGroup(supporter, toMod);