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 BLOCKED_AGENT("blocked-agent", "may not verify", true, false, false), //
12 BLOCKED_APPLICANT("blocked-applicant", "may not be verified", true, false, false), //
13 BLOCKED_LOGIN("blocked-login", "may not login", true, false, false), //
14 BLOCKED_CERT("blocked-cert", "may not issue certificates", true, false, false), //
15 TTP_AGENT("ttp-agent", "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 ORG_AGENT("org-agent", "may verify organisations", true, false, true), //
19 NUCLEUS_AGENT("nucleus-agent", "may enter nucleus verifications", true, false, true), //
20 LOCATE_AGENT("locate-agent", "wants access to the locate agent system", false, true, false), //
21 VERIFY_NOTIFICATION("verify-notification", "wants to receive an email notification for any Verification they enter", 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 ?::INTEGER LIMIT ?::INTEGER", 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() {