1 package org.cacert.gigi.dbObjects;
3 import org.cacert.gigi.database.DBEnum;
4 import org.cacert.gigi.database.GigiPreparedStatement;
5 import org.cacert.gigi.database.GigiResultSet;
6 import org.cacert.gigi.output.template.Outputable;
7 import org.cacert.gigi.output.template.TranslateCommand;
9 public enum Group implements DBEnum {
10 SUPPORTER("supporter", "supporter", true, false, true), //
11 ARBITRATOR("arbitrator", "arbitrator", true, false, true), //
12 BLOCKEDASSURER("blockedassurer", "may not verify", true, false, false), //
13 BLOCKEDASSUREE("blockedassuree", "may not be verified", true, false, false), //
14 BLOCKEDLOGIN("blockedlogin", "may not login", true, false, false), //
15 BLOCKEDCERT("blockedcert", "may not issue certificates", true, false, false), //
16 TTP_ASSURER("ttp-assurer", "may verify via TTP", true, false, true), //
17 TTP_APPLICANT("ttp-applicant", "requests to be verified via ttp", false, true, false), //
18 CODESIGNING("codesigning", "may issue codesigning certificates", true, false, false), //
19 ORGASSURER("orgassurer", "may verify organisations", true, false, true), //
20 NUCLEUS_ASSURER("nucleus-assurer", "may enter nucleus verifications", true, false, true), //
21 LOCATE_AGENT("locate-agent", "wants access to the locate agent system", false, true, false);
23 private final String dbName;
25 private final TranslateCommand tc;
27 private final boolean managedBySupport;
29 private final boolean managedByUser;
31 private final boolean isSelfViewable;
34 * Creates a new group. Users can join this group or be put into it
35 * (depending on the value of <code>managedBySupport</code>).
38 * name of the group, used in database
40 * text displayed to user
41 * @param managedBySupport
42 * true if flag is handled by support, false if handled by user
43 * @param isSelfViewable
44 * true iff user should be able to see others in the same group
46 private Group(String name, String display, boolean managedBySupport, boolean managedByUser, boolean isSelfViewable) {
48 tc = new TranslateCommand(display);
49 if (managedByUser && managedBySupport) {
50 throw new IllegalArgumentException("We do not allow groups to be user and support managable.");
52 if (managedByUser && isSelfViewable) {
53 throw new IllegalArgumentException("We do not allow groups to be self-viewable and managable by user.");
55 this.managedByUser = managedByUser;
56 this.managedBySupport = managedBySupport;
57 this.isSelfViewable = isSelfViewable;
60 public static Group getByString(String name) {
61 return valueOf(name.toUpperCase().replace('-', '_'));
64 public boolean isManagedBySupport() {
65 return managedBySupport;
68 public boolean isManagedByUser() {
72 public boolean isSelfViewable() {
73 return isSelfViewable;
76 public User[] getMembers(int offset, int count) {
77 try (GigiPreparedStatement gps = new GigiPreparedStatement("SELECT `user` FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL OFFSET ? LIMIT ?", true)) {
79 gps.setInt(2, offset);
81 GigiResultSet grs = gps.executeQuery();
83 User[] users = new User[grs.getRow()];
87 users[i++] = User.getById(grs.getInt(1));
93 public int getMemberCount() {
94 try (GigiPreparedStatement gps = new GigiPreparedStatement("SELECT COUNT(`user`) FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL", true)) {
96 GigiResultSet grs = gps.executeQuery();
100 return grs.getInt(1);
104 public Outputable getName() {
109 public String getDBName() {