1 package org.cacert.gigi.dbObjects;
3 import org.cacert.gigi.database.GigiPreparedStatement;
4 import org.cacert.gigi.database.GigiResultSet;
5 import org.cacert.gigi.output.template.Outputable;
6 import org.cacert.gigi.output.template.TranslateCommand;
9 SUPPORTER("supporter", "supporter", true, true), //
10 ARBITRATOR("arbitrator", "arbitrator", true, true), //
11 BLOCKEDASSURER("blockedassurer", "may not verify", true, false), //
12 BLOCKEDASSUREE("blockedassuree", "may not be verified", true, false), //
13 BLOCKEDLOGIN("blockedlogin", "may not login", true, false), //
14 BLOCKEDCERT("blockedcert", "may not issue certificates", true, false), //
15 TTP_ASSURER("ttp-assurer", "may verify via TTP", true, true), //
16 TTP_APPLICANT("ttp-applicant", "requests to be verified via ttp", true, false), //
17 CODESIGNING("codesigning", "may issue codesigning certificates", true, false), //
18 ORGASSURER("orgassurer", "may verify organisations", true, true), //
19 NUCLEUS_ASSURER("nucleus-assurer", "may enter nucleus verifications", true, true), //
20 LOCATE_AGENT("locate-agent", "wants access to the locate agent system", false, false);
22 private final String dbName;
24 private final TranslateCommand tc;
26 private final boolean managedBySupport;
28 private final boolean isSelfViewable;
31 * Creates a new group. Users can join this group or be put into it
32 * (depending on the value of <code>managedBySupport</code>).
35 * name of the group, used in database
37 * text displayed to user
38 * @param managedBySupport
39 * true if flag is handled by support, false if handled by user
40 * @param isSelfViewable
41 * true iff user should be able to see others in the same group
43 private Group(String name, String display, boolean managedBySupport, boolean isSelfViewable) {
45 tc = new TranslateCommand(display);
46 this.managedBySupport = managedBySupport;
47 this.isSelfViewable = isSelfViewable;
50 public static Group getByString(String name) {
51 return valueOf(name.toUpperCase().replace('-', '_'));
54 public boolean isManagedBySupport() {
55 return managedBySupport;
58 public boolean isSelfViewable() {
59 return isSelfViewable;
62 public String getDatabaseName() {
66 public User[] getMembers(int offset, int count) {
67 try (GigiPreparedStatement gps = new GigiPreparedStatement("SELECT `user` FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL OFFSET ? LIMIT ?", true)) {
68 gps.setString(1, dbName);
69 gps.setInt(2, offset);
71 GigiResultSet grs = gps.executeQuery();
73 User[] users = new User[grs.getRow()];
77 users[i++] = User.getById(grs.getInt(1));
83 public int getMemberCount() {
84 try (GigiPreparedStatement gps = new GigiPreparedStatement("SELECT COUNT(`user`) FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL", true)) {
85 gps.setString(1, dbName);
86 GigiResultSet grs = gps.executeQuery();
94 public Outputable getName() {