X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FGroup.java;h=13080efb208490a4ae7fc489cd57b5fb462a4001;hp=16cde6c1aa9e197268943fa3f2cb0e90d8f2b983;hb=6f621133a5fb40c0590d4ac1b80f6ad2bdd77f80;hpb=aa5723dbb64ec8efa63909d39ff72364f0a5ee96 diff --git a/src/org/cacert/gigi/dbObjects/Group.java b/src/org/cacert/gigi/dbObjects/Group.java index 16cde6c1..13080efb 100644 --- a/src/org/cacert/gigi/dbObjects/Group.java +++ b/src/org/cacert/gigi/dbObjects/Group.java @@ -6,26 +6,59 @@ import org.cacert.gigi.output.template.Outputable; import org.cacert.gigi.output.template.TranslateCommand; public enum Group { - SUPPORTER("supporter", "supporter"), ARBITRATOR("arbitrator", "arbitrator"), // - BLOCKEDASSURER("blockedassurer", "may not assure"), BLOCKEDASSUREE("blockedassuree", "may not be assured"), // - BLOCKEDLOGIN("blockedlogin", "may not login"), BLOCKEDCERT("blockedcert", "may not issue certificates"), // - TTP_ASSURER("ttp-assurer", "may assure via TTP"), TTP_APPLICANT("ttp-applicant", "requests to be assured via ttp"), // - CODESIGNING("codesigning", "may issue codesigning certificates"), ORGASSURER("orgassurer", "may assure organisations"), // - NUCLEUS_ASSURER("nucleus-assurer", "may issue nucleus assurances"); + SUPPORTER("supporter", "supporter", true, true), // + ARBITRATOR("arbitrator", "arbitrator", true, true), // + BLOCKEDASSURER("blockedassurer", "may not verify", true, false), // + BLOCKEDASSUREE("blockedassuree", "may not be verified", true, false), // + BLOCKEDLOGIN("blockedlogin", "may not login", true, false), // + BLOCKEDCERT("blockedcert", "may not issue certificates", true, false), // + TTP_ASSURER("ttp-assurer", "may verify via TTP", true, true), // + TTP_APPLICANT("ttp-applicant", "requests to be verified via ttp", true, false), // + CODESIGNING("codesigning", "may issue codesigning certificates", true, false), // + ORGASSURER("orgassurer", "may verify organisations", true, true), // + NUCLEUS_ASSURER("nucleus-assurer", "may enter nucleus verifications", true, true), // + LOCATE_AGENT("locate-agent", "wants access to the locate agent system", false, false); private final String dbName; private final TranslateCommand tc; - private Group(String name, String display) { + private final boolean managedBySupport; + + private final boolean isSelfViewable; + + /** + * Creates a new group. Users can join this group or be put into it + * (depending on the value of managedBySupport). + * + * @param name + * name of the group, used in database + * @param display + * text displayed to user + * @param managedBySupport + * true if flag is handled by support, false if handled by user + * @param isSelfViewable + * true iff user should be able to see others in the same group + */ + private Group(String name, String display, boolean managedBySupport, boolean isSelfViewable) { dbName = name; tc = new TranslateCommand(display); + this.managedBySupport = managedBySupport; + this.isSelfViewable = isSelfViewable; } public static Group getByString(String name) { return valueOf(name.toUpperCase().replace('-', '_')); } + public boolean isManagedBySupport() { + return managedBySupport; + } + + public boolean isSelfViewable() { + return isSelfViewable; + } + public String getDatabaseName() { return dbName; } @@ -47,6 +80,17 @@ public enum Group { } } + public int getMemberCount() { + try (GigiPreparedStatement gps = new GigiPreparedStatement("SELECT COUNT(`user`) FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL", true)) { + gps.setString(1, dbName); + GigiResultSet grs = gps.executeQuery(); + if ( !grs.next()) { + return 0; + } + return grs.getInt(1); + } + } + public Outputable getName() { return tc; }