X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FSupportedUser.java;h=e5daeb31bc0be4923418d595b006147068385f6b;hp=df5b54e88d0c5d5753c7bcfa4c4acf2ae3390dad;hb=4ff2f7a462e9d6ef5171b7d0a4c8d3cf3f26c024;hpb=c0d62ad52b65d78806431b34ed2ae24bf58c1ada diff --git a/src/org/cacert/gigi/dbObjects/SupportedUser.java b/src/org/cacert/gigi/dbObjects/SupportedUser.java index df5b54e8..e5daeb31 100644 --- a/src/org/cacert/gigi/dbObjects/SupportedUser.java +++ b/src/org/cacert/gigi/dbObjects/SupportedUser.java @@ -1,9 +1,18 @@ package org.cacert.gigi.dbObjects; +import java.io.IOException; +import java.util.HashMap; +import java.util.Locale; + import org.cacert.gigi.GigiApiException; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.dbObjects.Certificate.CertificateStatus; +import org.cacert.gigi.localisation.Language; +import org.cacert.gigi.output.template.MailTemplate; +import org.cacert.gigi.output.template.Outputable; +import org.cacert.gigi.output.template.SprintfCommand; import org.cacert.gigi.util.DayDate; +import org.cacert.gigi.util.ServerConstants; public class SupportedUser { @@ -19,21 +28,12 @@ public class SupportedUser { this.ticket = ticket; } - public boolean setName(Name newName) throws GigiApiException { - if (newName.equals(target.getName())) { - return false; - } - writeSELog("SE Name change"); - target.setName(newName); - return true; - } - public boolean setDob(DayDate dob) throws GigiApiException { if (dob.equals(target.getDoB())) { return false; } writeSELog("SE dob change"); - target.setDoB(dob); + target.setDoBAsSupport(dob); return true; } @@ -48,6 +48,23 @@ public class SupportedUser { } } + public void revokeCertificate(Certificate cert) throws GigiApiException { + + // TODO Check for open jobs! + if (cert.getStatus() == CertificateStatus.ISSUED) { + writeSELog("SE Revoke certificate"); + cert.revoke().waitFor(60000); + // send notification to support + String subject = "Revoke certificate"; + Outputable message = SprintfCommand.createSimple("Certificate with serial number {0} for {1} <{2}>, has been revoked.", cert.getSerial(), target.getPreferredName().toString(), target.getEmail()); + sendSupportNotification(subject, message); + // send notification to user + subject = "Revoke certificate"; + message = SprintfCommand.createSimple("Certificate with serial number {0} with subject distinguished name {1} has been revoked.", cert.getSerial(), cert.getDistinguishedName()); + sendSupportUserNotification(subject, message); + } + } + private void writeSELog(String type) throws GigiApiException { if (ticket == null) { throw new GigiApiException("No ticket set!"); @@ -77,11 +94,7 @@ public class SupportedUser { return target; } - public void submitSupportAction() throws GigiApiException { - target.rawUpdateUserData(); - } - - public void grant(Group toMod) { + public void grant(Group toMod) throws GigiApiException { target.grantGroup(supporter, toMod); } @@ -89,4 +102,35 @@ public class SupportedUser { target.revokeGroup(supporter, toMod); } + private static final MailTemplate supportNotification = new MailTemplate(SupportedUser.class.getResource("SupportNotificationMail.templ")); + + public void sendSupportNotification(String subject, Outputable message) { + try { + HashMap vars = new HashMap<>(); + vars.put("supporter", supporter.getPreferredName().toString()); + vars.put("action", message); + vars.put("ticket", this.getTicket()); + vars.put("subject", subject); + + String supportemailaddress = ServerConstants.getSupportMailAddress(); + supportNotification.sendMail(Language.getInstance(Locale.ENGLISH), vars, supportemailaddress); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static final MailTemplate supportUserNotification = new MailTemplate(SupportedUser.class.getResource("SupportUserNotificationMail.templ")); + + public void sendSupportUserNotification(String subject, Outputable message) { + try { + HashMap vars = new HashMap<>(); + vars.put("action", message); + vars.put("ticket", this.getTicket()); + vars.put("subject", subject); + + supportUserNotification.sendMail(Language.getInstance(Locale.ENGLISH), vars, target.getEmail()); + } catch (IOException e) { + e.printStackTrace(); + } + } }