X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FGroup.java;h=91becaf8c84d97b518810f3281f6cd08d9b066e4;hp=13080efb208490a4ae7fc489cd57b5fb462a4001;hb=f315d0bca61b165008c9af84ddba648fae2361e9;hpb=6f621133a5fb40c0590d4ac1b80f6ad2bdd77f80 diff --git a/src/org/cacert/gigi/dbObjects/Group.java b/src/org/cacert/gigi/dbObjects/Group.java index 13080efb..91becaf8 100644 --- a/src/org/cacert/gigi/dbObjects/Group.java +++ b/src/org/cacert/gigi/dbObjects/Group.java @@ -1,23 +1,25 @@ package org.cacert.gigi.dbObjects; +import org.cacert.gigi.database.DBEnum; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.database.GigiResultSet; import org.cacert.gigi.output.template.Outputable; import org.cacert.gigi.output.template.TranslateCommand; -public enum Group { - 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); +public enum Group implements DBEnum { + SUPPORTER("supporter", "supporter", true, false, true), // + ARBITRATOR("arbitrator", "arbitrator", true, false, true), // + BLOCKEDASSURER("blockedassurer", "may not verify", true, false, false), // + BLOCKEDASSUREE("blockedassuree", "may not be verified", true, false, false), // + BLOCKEDLOGIN("blockedlogin", "may not login", true, false, false), // + BLOCKEDCERT("blockedcert", "may not issue certificates", true, false, false), // + TTP_ASSURER("ttp-assurer", "may verify via TTP", true, false, true), // + TTP_APPLICANT("ttp-applicant", "requests to be verified via ttp", false, true, false), // + CODESIGNING("codesigning", "may issue codesigning certificates", true, false, false), // + ORGASSURER("orgassurer", "may verify organisations", true, false, true), // + NUCLEUS_ASSURER("nucleus-assurer", "may enter nucleus verifications", true, false, true), // + LOCATE_AGENT("locate-agent", "wants access to the locate agent system", false, true, false), // + VERIFY_NOTIFICATION("verify-notification", "wants to receive an email notification for any Verification they enter", false, true, false); private final String dbName; @@ -25,6 +27,8 @@ public enum Group { private final boolean managedBySupport; + private final boolean managedByUser; + private final boolean isSelfViewable; /** @@ -40,9 +44,16 @@ public enum Group { * @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) { + private Group(String name, String display, boolean managedBySupport, boolean managedByUser, boolean isSelfViewable) { dbName = name; tc = new TranslateCommand(display); + if (managedByUser && managedBySupport) { + throw new IllegalArgumentException("We do not allow groups to be user and support managable."); + } + if (managedByUser && isSelfViewable) { + throw new IllegalArgumentException("We do not allow groups to be self-viewable and managable by user."); + } + this.managedByUser = managedByUser; this.managedBySupport = managedBySupport; this.isSelfViewable = isSelfViewable; } @@ -55,17 +66,17 @@ public enum Group { return managedBySupport; } - public boolean isSelfViewable() { - return isSelfViewable; + public boolean isManagedByUser() { + return managedByUser; } - public String getDatabaseName() { - return dbName; + public boolean isSelfViewable() { + return isSelfViewable; } public User[] getMembers(int offset, int count) { try (GigiPreparedStatement gps = new GigiPreparedStatement("SELECT `user` FROM `user_groups` WHERE `permission`=?::`userGroup` AND `deleted` IS NULL OFFSET ? LIMIT ?", true)) { - gps.setString(1, dbName); + gps.setEnum(1, this); gps.setInt(2, offset); gps.setInt(3, count); GigiResultSet grs = gps.executeQuery(); @@ -82,7 +93,7 @@ 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); + gps.setEnum(1, this); GigiResultSet grs = gps.executeQuery(); if ( !grs.next()) { return 0; @@ -94,4 +105,9 @@ public enum Group { public Outputable getName() { return tc; } + + @Override + public String getDBName() { + return dbName; + } }