X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FUser.java;h=69b76ad2004ec9aa24c5401b7d8f1f0f42845c12;hb=d0470c5987aaecbc444c7100319df69b6f740680;hp=3c9b972dba9930612a334d74b9d1236e77c40ce3;hpb=40b66049e1d0b738f654a92176e5cb8ffc8a9665;p=gigi.git diff --git a/src/org/cacert/gigi/dbObjects/User.java b/src/org/cacert/gigi/dbObjects/User.java index 3c9b972d..69b76ad2 100644 --- a/src/org/cacert/gigi/dbObjects/User.java +++ b/src/org/cacert/gigi/dbObjects/User.java @@ -45,7 +45,7 @@ public class User extends CertificateOwner { private Locale locale; - private final Set groups = new HashSet<>(); + private Set groups = new HashSet<>(); public static final int MINIMUM_AGE = 16; @@ -93,15 +93,21 @@ public class User extends CertificateOwner { locale = Language.getLocaleFromString(localeStr); } + refreshGroups(); + } + + public synchronized void refreshGroups() { + HashSet hs = new HashSet<>(); try (GigiPreparedStatement psg = new GigiPreparedStatement("SELECT `permission` FROM `user_groups` WHERE `user`=? AND `deleted` is NULL")) { - psg.setInt(1, rs.getInt("id")); + psg.setInt(1, getId()); try (GigiResultSet rs2 = psg.executeQuery()) { while (rs2.next()) { - groups.add(Group.getByString(rs2.getString(1))); + hs.add(Group.getByString(rs2.getString(1))); } } } + groups = hs; } public User(String email, String password, DayDate dob, Locale locale, Country residenceCountry, NamePart... preferred) throws GigiApiException { @@ -438,7 +444,10 @@ public class User extends CertificateOwner { return Collections.unmodifiableSet(groups); } - public void grantGroup(User granter, Group toGrant) { + public void grantGroup(User granter, Group toGrant) throws GigiApiException { + if (toGrant.isManagedBySupport() && !granter.isInGroup(Group.SUPPORTER)) { + throw new GigiApiException("Group may only be managed by supporter"); + } groups.add(toGrant); try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `user_groups` SET `user`=?, `permission`=?::`userGroup`, `grantedby`=?")) { ps.setInt(1, getId());