1 package club.wpia.gigi.dbObjects;
3 import club.wpia.gigi.database.DBEnum;
4 import club.wpia.gigi.database.GigiPreparedStatement;
5 import club.wpia.gigi.database.GigiResultSet;
6 import club.wpia.gigi.output.template.Outputable;
7 import club.wpia.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), //
22 VERIFY_NOTIFICATION("verify-notification", "wants to receive an email notification for any Verification they enter", false, true, false);
24 private final String dbName;
26 private final TranslateCommand tc;
28 private final boolean managedBySupport;
30 private final boolean managedByUser;
32 private final boolean isSelfViewable;
35 * Creates a new group. Users can join this group or be put into it
36 * (depending on the value of <code>managedBySupport</code>).
39 * name of the group, used in database
41 * text displayed to user
42 * @param managedBySupport
43 * true if flag is handled by support, false if handled by user
44 * @param isSelfViewable
45 * true iff user should be able to see others in the same group
47 private Group(String name, String display, boolean managedBySupport, boolean managedByUser, boolean isSelfViewable) {
49 tc = new TranslateCommand(display);
50 if (managedByUser && managedBySupport) {
51 throw new IllegalArgumentException("We do not allow groups to be user and support managable.");
53 if (managedByUser && isSelfViewable) {
54 throw new IllegalArgumentException("We do not allow groups to be self-viewable and managable by user.");
56 this.managedByUser = managedByUser;
57 this.managedBySupport = managedBySupport;
58 this.isSelfViewable = isSelfViewable;
61 public static Group getByString(String name) {
62 return valueOf(name.toUpperCase().replace('-', '_'));
65 public boolean isManagedBySupport() {
66 return managedBySupport;
69 public boolean isManagedByUser() {
73 public boolean isSelfViewable() {
74 return isSelfViewable;
77 public User[] getMembers(int offset, int count) {
78 try (GigiPreparedStatement gps = new GigiPreparedStatement("SELECT `user` FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL OFFSET ? LIMIT ?", true)) {
80 gps.setInt(2, offset);
82 GigiResultSet grs = gps.executeQuery();
84 User[] users = new User[grs.getRow()];
88 users[i++] = User.getById(grs.getInt(1));
94 public int getMemberCount() {
95 try (GigiPreparedStatement gps = new GigiPreparedStatement("SELECT COUNT(`user`) FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL", true)) {
97 GigiResultSet grs = gps.executeQuery();
101 return grs.getInt(1);
105 public Outputable getName() {
110 public String getDBName() {