use of com.google.gerrit.server.account.GroupControl in project gerrit by GerritCodeReview.
the class AgreementJson method format.
public AgreementInfo format(ContributorAgreement ca) {
AgreementInfo info = new AgreementInfo();
info.name = ca.getName();
info.description = ca.getDescription();
info.url = ca.getAgreementUrl();
GroupReference autoVerifyGroup = ca.getAutoVerify();
if (autoVerifyGroup != null && self.get().isIdentifiedUser()) {
IdentifiedUser user = identifiedUserFactory.create(self.get().getAccountId());
try {
GroupControl gc = genericGroupControlFactory.controlFor(user, autoVerifyGroup.getUUID());
GroupResource group = new GroupResource(gc);
info.autoVerifyGroup = groupJson.format(group);
} catch (NoSuchGroupException | OrmException e) {
log.warn("autoverify group \"" + autoVerifyGroup.getName() + "\" does not exist, referenced in CLA \"" + ca.getName() + "\"");
}
}
return info;
}
use of com.google.gerrit.server.account.GroupControl in project gerrit by GerritCodeReview.
the class DeleteIncludedGroups method apply.
@Override
public Response<?> apply(GroupResource resource, Input input) throws AuthException, MethodNotAllowedException, UnprocessableEntityException, OrmException {
AccountGroup internalGroup = resource.toAccountGroup();
if (internalGroup == null) {
throw new MethodNotAllowedException();
}
input = Input.init(input);
final GroupControl control = resource.getControl();
final Map<AccountGroup.UUID, AccountGroupById> includedGroups = getIncludedGroups(internalGroup.getId());
final List<AccountGroupById> toRemove = new ArrayList<>();
for (final String includedGroup : input.groups) {
GroupDescription.Basic d = groupsCollection.parse(includedGroup);
if (!control.canRemoveGroup()) {
throw new AuthException(String.format("Cannot delete group: %s", d.getName()));
}
AccountGroupById g = includedGroups.remove(d.getGroupUUID());
if (g != null) {
toRemove.add(g);
}
}
if (!toRemove.isEmpty()) {
writeAudits(toRemove);
db.get().accountGroupById().delete(toRemove);
for (final AccountGroupById g : toRemove) {
groupIncludeCache.evictParentGroupsOf(g.getIncludeUUID());
}
groupIncludeCache.evictSubgroupsOf(internalGroup.getGroupUUID());
}
return Response.none();
}
use of com.google.gerrit.server.account.GroupControl in project gerrit by GerritCodeReview.
the class AddIncludedGroups method apply.
@Override
public List<GroupInfo> apply(GroupResource resource, Input input) throws MethodNotAllowedException, AuthException, UnprocessableEntityException, OrmException {
AccountGroup group = resource.toAccountGroup();
if (group == null) {
throw new MethodNotAllowedException();
}
input = Input.init(input);
GroupControl control = resource.getControl();
Map<AccountGroup.UUID, AccountGroupById> newIncludedGroups = new HashMap<>();
List<GroupInfo> result = new ArrayList<>();
Account.Id me = control.getUser().getAccountId();
for (String includedGroup : input.groups) {
GroupDescription.Basic d = groupsCollection.parse(includedGroup);
if (!control.canAddGroup()) {
throw new AuthException(String.format("Cannot add group: %s", d.getName()));
}
if (!newIncludedGroups.containsKey(d.getGroupUUID())) {
AccountGroupById.Key agiKey = new AccountGroupById.Key(group.getId(), d.getGroupUUID());
AccountGroupById agi = db.get().accountGroupById().get(agiKey);
if (agi == null) {
agi = new AccountGroupById(agiKey);
newIncludedGroups.put(d.getGroupUUID(), agi);
}
}
result.add(json.format(d));
}
if (!newIncludedGroups.isEmpty()) {
auditService.dispatchAddGroupsToGroup(me, newIncludedGroups.values());
db.get().accountGroupById().insert(newIncludedGroups.values());
for (AccountGroupById agi : newIncludedGroups.values()) {
groupIncludeCache.evictParentGroupsOf(agi.getIncludeUUID());
}
groupIncludeCache.evictSubgroupsOf(group.getGroupUUID());
}
return result;
}
use of com.google.gerrit.server.account.GroupControl in project gerrit by GerritCodeReview.
the class AddMembers method apply.
@Override
public List<AccountInfo> apply(GroupResource resource, Input input) throws AuthException, MethodNotAllowedException, UnprocessableEntityException, OrmException, IOException {
AccountGroup internalGroup = resource.toAccountGroup();
if (internalGroup == null) {
throw new MethodNotAllowedException();
}
input = Input.init(input);
GroupControl control = resource.getControl();
Set<Account.Id> newMemberIds = new HashSet<>();
for (String nameOrEmailOrId : input.members) {
Account a = findAccount(nameOrEmailOrId);
if (!a.isActive()) {
throw new UnprocessableEntityException(String.format("Account Inactive: %s", nameOrEmailOrId));
}
if (!control.canAddMember()) {
throw new AuthException("Cannot add member: " + a.getFullName());
}
newMemberIds.add(a.getId());
}
addMembers(internalGroup.getId(), newMemberIds);
return toAccountInfoList(newMemberIds);
}
Aggregations