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, false, true), //
10 ARBITRATOR("arbitrator", "arbitrator", true, false, true), //
11 BLOCKEDASSURER("blockedassurer", "may not verify", true, false, false), //
12 BLOCKEDASSUREE("blockedassuree", "may not be verified", true, false, false), //
13 BLOCKEDLOGIN("blockedlogin", "may not login", true, false, false), //
14 BLOCKEDCERT("blockedcert", "may not issue certificates", true, false, false), //
15 TTP_ASSURER("ttp-assurer", "may verify via TTP", true, false, true), //
16 TTP_APPLICANT("ttp-applicant", "requests to be verified via ttp", false, true, false), //
17 CODESIGNING("codesigning", "may issue codesigning certificates", true, false, false), //
18 ORGASSURER("orgassurer", "may verify organisations", true, false, true), //
19 NUCLEUS_ASSURER("nucleus-assurer", "may enter nucleus verifications", true, false, true), //
20 LOCATE_AGENT("locate-agent", "wants access to the locate agent system", false, true, false);
22 private final String dbName;
24 private final TranslateCommand tc;
26 private final boolean managedBySupport;
28 private final boolean managedByUser;
30 private final boolean isSelfViewable;
33 * Creates a new group. Users can join this group or be put into it
34 * (depending on the value of <code>managedBySupport</code>).
37 * name of the group, used in database
39 * text displayed to user
40 * @param managedBySupport
41 * true if flag is handled by support, false if handled by user
42 * @param isSelfViewable
43 * true iff user should be able to see others in the same group
45 private Group(String name, String display, boolean managedBySupport, boolean managedByUser, boolean isSelfViewable) {
47 tc = new TranslateCommand(display);
48 if (managedByUser && managedBySupport) {
49 throw new IllegalArgumentException("We do not allow groups to be user and support managable.");
51 if (managedByUser && isSelfViewable) {
52 throw new IllegalArgumentException("We do not allow groups to be self-viewable and managable by user.");
54 this.managedByUser = managedByUser;
55 this.managedBySupport = managedBySupport;
56 this.isSelfViewable = isSelfViewable;
59 public static Group getByString(String name) {
60 return valueOf(name.toUpperCase().replace('-', '_'));
63 public boolean isManagedBySupport() {
64 return managedBySupport;
67 public boolean isManagedByUser() {
71 public boolean isSelfViewable() {
72 return isSelfViewable;
75 public String getDatabaseName() {
79 public User[] getMembers(int offset, int count) {
80 try (GigiPreparedStatement gps = new GigiPreparedStatement("SELECT `user` FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL OFFSET ? LIMIT ?", true)) {
81 gps.setString(1, dbName);
82 gps.setInt(2, offset);
84 GigiResultSet grs = gps.executeQuery();
86 User[] users = new User[grs.getRow()];
90 users[i++] = User.getById(grs.getInt(1));
96 public int getMemberCount() {
97 try (GigiPreparedStatement gps = new GigiPreparedStatement("SELECT COUNT(`user`) FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL", true)) {
98 gps.setString(1, dbName);
99 GigiResultSet grs = gps.executeQuery();
103 return grs.getInt(1);
107 public Outputable getName() {