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