use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class Index method apply.
@Override
public Response<?> apply(GroupResource rsrc, Input input) throws IOException, AuthException, UnprocessableEntityException {
if (!rsrc.getControl().isOwner()) {
throw new AuthException("not allowed to index group");
}
AccountGroup group = GroupDescriptions.toAccountGroup(rsrc.getGroup());
if (group == null) {
throw new UnprocessableEntityException(String.format("External Group Not Allowed: %s", rsrc.getGroupUUID().get()));
}
// evicting the group from the cache, reindexes the group
groupCache.evict(group);
return Response.none();
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class ListGroups method filterGroups.
private List<AccountGroup> filterGroups(Collection<AccountGroup> groups) {
List<AccountGroup> filteredGroups = new ArrayList<>(groups.size());
for (AccountGroup group : groups) {
if (!Strings.isNullOrEmpty(matchSubstring)) {
if (!group.getName().toLowerCase(Locale.US).contains(matchSubstring.toLowerCase(Locale.US))) {
continue;
}
}
if (visibleToAll && !group.isVisibleToAll()) {
continue;
}
if (!groupsToInspect.isEmpty() && !groupsToInspect.contains(group.getGroupUUID())) {
continue;
}
GroupControl c = groupControlFactory.controlFor(group);
if (c.isVisible()) {
filteredGroups.add(group);
}
}
Collections.sort(filteredGroups, new GroupComparator());
return filteredGroups;
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class ListGroups method getGroupsOwnedBy.
private List<GroupInfo> getGroupsOwnedBy(IdentifiedUser user) throws OrmException {
List<GroupInfo> groups = new ArrayList<>();
int found = 0;
int foundIndex = 0;
for (AccountGroup g : filterGroups(groupCache.all())) {
GroupControl ctl = groupControlFactory.controlFor(g);
try {
if (genericGroupControlFactory.controlFor(user, g.getGroupUUID()).isOwner()) {
if (foundIndex++ < start) {
continue;
}
if (limit > 0 && ++found > limit) {
break;
}
groups.add(json.addOptions(options).format(ctl.getGroup()));
}
} catch (NoSuchGroupException e) {
continue;
}
}
return groups;
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class DeleteMembers method apply.
@Override
public Response<?> 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);
final GroupControl control = resource.getControl();
final Map<Account.Id, AccountGroupMember> members = getMembers(internalGroup.getId());
final List<AccountGroupMember> toRemove = new ArrayList<>();
for (final String nameOrEmail : input.members) {
Account a = accounts.parse(nameOrEmail).getAccount();
if (!control.canRemoveMember()) {
throw new AuthException("Cannot delete member: " + a.getFullName());
}
final AccountGroupMember m = members.remove(a.getId());
if (m != null) {
toRemove.add(m);
}
}
writeAudits(toRemove);
db.get().accountGroupMembers().delete(toRemove);
for (final AccountGroupMember m : toRemove) {
accountCache.evict(m.getAccountId());
}
return Response.none();
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method configureContributorAgreement.
protected ContributorAgreement configureContributorAgreement(boolean autoVerify) throws Exception {
ContributorAgreement ca;
if (autoVerify) {
String g = createGroup("cla-test-group");
GroupApi groupApi = gApi.groups().id(g);
groupApi.description("CLA test group");
AccountGroup caGroup = groupCache.get(new AccountGroup.UUID(groupApi.detail().id));
GroupReference groupRef = GroupReference.forGroup(caGroup);
PermissionRule rule = new PermissionRule(groupRef);
rule.setAction(PermissionRule.Action.ALLOW);
ca = new ContributorAgreement("cla-test");
ca.setAutoVerify(groupRef);
ca.setAccepted(ImmutableList.of(rule));
} else {
ca = new ContributorAgreement("cla-test-no-auto-verify");
}
ca.setDescription("description");
ca.setAgreementUrl("agreement-url");
ProjectConfig cfg = projectCache.checkedGet(allProjects).getConfig();
cfg.replace(ca);
saveProjectConfig(allProjects, cfg);
return ca;
}
Aggregations