1 package org.cacert.gigi.dbObjects;
3 import java.io.IOException;
4 import java.util.HashMap;
5 import java.util.Locale;
7 import org.cacert.gigi.GigiApiException;
8 import org.cacert.gigi.database.GigiPreparedStatement;
9 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
10 import org.cacert.gigi.localisation.Language;
11 import org.cacert.gigi.output.template.MailTemplate;
12 import org.cacert.gigi.output.template.Outputable;
13 import org.cacert.gigi.util.DayDate;
14 import org.cacert.gigi.util.ServerConstants;
16 public class SupportedUser {
20 private User supporter;
22 private String ticket;
24 public SupportedUser(User target, User supporter, String ticket) {
25 this.supporter = supporter;
30 public boolean setDob(DayDate dob) throws GigiApiException {
31 if (dob.equals(target.getDoB())) {
34 writeSELog("SE dob change");
35 target.setDoBAsSupport(dob);
39 public void revokeAllCertificates() throws GigiApiException {
40 writeSELog("SE Revoke certificates");
41 Certificate[] certs = target.getCertificates(false);
42 // TODO Check for open jobs!
43 for (int i = 0; i < certs.length; i++) {
44 if (certs[i].getStatus() == CertificateStatus.ISSUED) {
50 private void writeSELog(String type) throws GigiApiException {
52 throw new GigiApiException("No ticket set!");
54 try (GigiPreparedStatement prep = new GigiPreparedStatement("INSERT INTO `adminLog` SET uid=?, admin=?, type=?, information=?")) {
55 prep.setInt(1, target.getId());
56 prep.setInt(2, supporter.getId());
57 prep.setString(3, type);
58 prep.setString(4, ticket);
64 return target.getId();
67 public Certificate[] getCertificates(boolean includeRevoked) {
68 return target.getCertificates(includeRevoked);
71 public String getTicket() {
75 public User getTargetUser() {
79 public void grant(Group toMod) {
80 target.grantGroup(supporter, toMod);
83 public void revoke(Group toMod) {
84 target.revokeGroup(supporter, toMod);
87 private static final MailTemplate supportNotification = new MailTemplate(SupportedUser.class.getResource("SupportNotificationMail.templ"));
89 public void sendSupportNotification(String subject, Outputable message) {
91 HashMap<String, Object> vars = new HashMap<>();
92 vars.put("supporter", supporter.getPreferredName().toString());
93 vars.put("action", message);
94 vars.put("ticket", this.getTicket());
95 vars.put("subject", subject);
97 String supportemailaddress = ServerConstants.getSupportMailAddress();
98 supportNotification.sendMail(Language.getInstance(Locale.ENGLISH), vars, supportemailaddress);
99 } catch (IOException e) {