]> WPIA git - gigi.git/commitdiff
ADD: Use a "SupportedUser" for the user details form
authorJanis Streib <janis@dogcraft.de>
Sat, 21 Mar 2015 15:46:41 +0000 (16:46 +0100)
committerJanis Streib <janis@dogcraft.de>
Sat, 21 Mar 2015 20:07:51 +0000 (21:07 +0100)
src/org/cacert/gigi/dbObjects/SupportedUser.java
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.java
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsForm.templ
src/org/cacert/gigi/pages/admin/support/SupportUserDetailsPage.java

index bdad013aa106828278a4e9648fe2b1354c5c893b..668fd8c9815a64896f33b5f41f3c272c1a359eec 100644 (file)
@@ -2,6 +2,7 @@ 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;
 
@@ -17,17 +18,17 @@ public class SupportedUser {
         this.ticket = ticket;
     }
 
-    public void setName(String fname, String mname, String lname, String suffix) {
+    public void setName(String fname, String mname, String lname, String suffix) throws GigiApiException {
         writeSELog("SE Name change");
         target.setName(new Name(fname, lname, mname, suffix));
     }
 
-    public void setDob(Date dob) {
+    public void setDob(Date dob) throws GigiApiException {
         writeSELog("SE dob change");
         target.setDoB(dob);
     }
 
-    public void revokeAllCertificates() {
+    public void revokeAllCertificates() throws GigiApiException {
         writeSELog("SE Revoke certificates");
         Certificate[] certs = target.getCertificates(false);
         for (int i = 0; i < certs.length; i++) {
@@ -35,7 +36,10 @@ public class SupportedUser {
         }
     }
 
-    public void writeSELog(String type) {
+    private void writeSELog(String type) throws GigiApiException {
+        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());
@@ -56,4 +60,8 @@ public class SupportedUser {
         return ticket;
     }
 
+    public User getTargetUser() {
+        return target;
+    }
+
 }
index 3a8dc30ecf99a863be917fa802e1bae3ef1d1c3d..737a94c116b7c99fda767144fbc54d71ee2055d6 100644 (file)
@@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletRequest;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.Name;
+import org.cacert.gigi.dbObjects.SupportedUser;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.DateSelector;
@@ -18,24 +19,26 @@ public class SupportUserDetailsForm extends Form {
 
     private static Template t;
 
-    private User user;
+    private SupportedUser user;
 
     static {
         t = new Template(FindDomainForm.class.getResource("SupportUserDetailsForm.templ"));
     }
 
-    public SupportUserDetailsForm(HttpServletRequest hsr, User user) {
+    public SupportUserDetailsForm(HttpServletRequest hsr, SupportedUser user) {
         super(hsr);
         this.user = user;
     }
 
     @Override
     public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException {
+
         return false;
     }
 
     @Override
     protected void outputContent(PrintWriter out, Language l, Map<String, Object> vars) {
+        User user = this.user.getTargetUser();
         Name name = user.getName();
         vars.put("mail", user.getEmail());
         vars.put("fname", name.getFname());
index c0329527b41fec7d6a9168cc8c2959a6020f45d8..e3ae77f70d5477bb0cffdf5c1c2c0530817fca29 100644 (file)
             <tr>
             <td colspan="2"><a href="./<?=$id?>/history"><?=_Show account history?></a></td>
         </tr>
-        <tr><td colspan="2"><input type="submit" value="<?=_Update?>"/></td></tr>
+        <tr><td colspan="2"><input name="detailupdate" type="submit" value="<?=_Update?>"/></td></tr>
     </tbody>
 </table>
 <br/>
\ No newline at end of file
index f1eed52624011a9463e7ac7ac2af84e3494695a9..234448088d91f5bcaa82b1eb357f8f81c25995db 100644 (file)
@@ -31,10 +31,10 @@ public class SupportUserDetailsPage extends Page {
         String[] idP = req.getPathInfo().split("/");
         id = Integer.parseInt(idP[idP.length - 1]);
         final User user = User.getById(id);
-        SupportUserDetailsForm f = new SupportUserDetailsForm(req, user);
+        String ticket = (String) req.getSession().getAttribute("ticketNo" + user.getId());
+        SupportUserDetailsForm f = new SupportUserDetailsForm(req, new SupportedUser(user, getUser(req), ticket));
         HashMap<String, Object> vars = new HashMap<String, Object>();
         vars.put("details", f);
-        String ticket = (String) req.getSession().getAttribute("ticketNo" + user.getId());
         vars.put("ticketNo", ticket);
         final EmailAddress[] addrs = user.getEmails();
         vars.put("emails", new IterableDataset() {
@@ -71,6 +71,10 @@ public class SupportUserDetailsPage extends Page {
                 if ( !Form.getForm(req, SupportRevokeCertificatesForm.class).submit(resp.getWriter(), req)) {
                     throw new GigiApiException("No ticket number set.");
                 }
+            } else if (req.getParameter("detailupdate") != null) {
+                if ( !Form.getForm(req, SupportUserDetailsForm.class).submit(resp.getWriter(), req)) {
+                    throw new GigiApiException("No ticket number set.");
+                }
             }
         } catch (GigiApiException e) {
             e.printStackTrace();