]> WPIA git - gigi.git/blob - src/org/cacert/gigi/pages/account/History.java
upd: history also for organisations.
[gigi.git] / src / org / cacert / gigi / pages / account / History.java
1 package org.cacert.gigi.pages.account;
2
3 import java.io.IOException;
4 import java.util.HashMap;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.cacert.gigi.dbObjects.CertificateOwner;
10 import org.cacert.gigi.dbObjects.User;
11 import org.cacert.gigi.output.template.OutputableArrayIterable;
12 import org.cacert.gigi.pages.LoginPage;
13 import org.cacert.gigi.pages.Page;
14 import org.cacert.gigi.util.AuthorizationContext;
15
16 public class History extends Page {
17
18     public static final String SUPPORT_PATH = "/support/user/*/history";
19
20     public static final String PATH = "/account/history";
21
22     private static final int intStart = SUPPORT_PATH.indexOf('*');
23
24     private boolean support;
25
26     public History(boolean support) {
27         super(support ? "Support History" : "History");
28         this.support = support;
29     }
30
31     @Override
32     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
33         CertificateOwner u;
34         if (support) {
35             String info = req.getPathInfo();
36             int id = Integer.parseInt(info.substring(intStart, info.length() - SUPPORT_PATH.length() + intStart + 1));
37             u = User.getById(id);
38             if (u == null) {
39                 resp.sendError(404);
40                 return;
41             }
42         } else {
43             u = LoginPage.getAuthorizationContext(req).getTarget();
44         }
45         String[] adminLog = u.getAdminLog();
46         HashMap<String, Object> vars = new HashMap<>();
47         vars.put("entries", new OutputableArrayIterable(adminLog, "entry"));
48         getDefaultTemplate().output(resp.getWriter(), getLanguage(req), vars);
49     }
50
51     @Override
52     public boolean isPermitted(AuthorizationContext ac) {
53         return ac != null && ( !support || ac.canSupport());
54     }
55 }