Esempio n. 1
0
  private GroupReference getOrCreateGroupForIndividuals(
      ReviewDb db,
      ProjectConfig config,
      List<AccountGroup.UUID> adminGroupUUIDs,
      ContributorAgreement agreement)
      throws OrmException {
    if (!agreement.getAccepted().isEmpty()) {
      return agreement.getAccepted().get(0).getGroup();
    }

    String name = "CLA Accepted - " + agreement.getName();
    AccountGroupName agn = db.accountGroupNames().get(new AccountGroup.NameKey(name));
    AccountGroup ag;
    if (agn != null) {
      ag = db.accountGroups().get(agn.getId());
      if (ag == null) {
        throw new IllegalStateException(
            "account group name exists but account group does not: " + name);
      }

      if (!adminGroupUUIDs.contains(ag.getOwnerGroupUUID())) {
        throw new IllegalStateException(
            "individual group exists with non admin owner group: " + name);
      }
    } else {
      ag =
          createGroup(
              db,
              name,
              adminGroupUUIDs.get(0),
              String.format("Users who have accepted the %s CLA", agreement.getName()));
    }
    GroupReference group = config.resolve(ag);
    agreement.setAccepted(Lists.newArrayList(new PermissionRule(group)));
    if (agreement.getAutoVerify() != null) {
      agreement.setAutoVerify(group);
    }

    // Don't allow accounts in the same individual CLA group to see each
    // other in same group visibility mode.
    List<PermissionRule> sameGroupVisibility = config.getAccountsSection().getSameGroupVisibility();
    PermissionRule rule = new PermissionRule(group);
    rule.setDeny();
    if (!sameGroupVisibility.contains(rule)) {
      sameGroupVisibility.add(rule);
    }
    return group;
  }
Esempio n. 2
0
 private AccountGroup createGroup(
     ReviewDb db, String groupName, AccountGroup.UUID adminGroupUUID, String description)
     throws OrmException {
   final AccountGroup.Id groupId = new AccountGroup.Id(db.nextAccountGroupId());
   final AccountGroup.NameKey nameKey = new AccountGroup.NameKey(groupName);
   final AccountGroup.UUID uuid = GroupUUID.make(groupName, serverUser);
   final AccountGroup group = new AccountGroup(nameKey, groupId, uuid);
   group.setOwnerGroupUUID(adminGroupUUID);
   group.setDescription(description);
   final AccountGroupName gn = new AccountGroupName(group);
   // first insert the group name to validate that the group name hasn't
   // already been used to create another group
   db.accountGroupNames().insert(Collections.singleton(gn));
   db.accountGroups().insert(Collections.singleton(group));
   return group;
 }