Search in sources :

Example 11 with AccountGroup

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();
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AuthException(com.google.gerrit.extensions.restapi.AuthException)

Example 12 with AccountGroup

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;
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) GroupComparator(com.google.gerrit.server.account.GroupComparator) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) ArrayList(java.util.ArrayList)

Example 13 with AccountGroup

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;
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ArrayList(java.util.ArrayList) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException)

Example 14 with AccountGroup

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();
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) Account(com.google.gerrit.reviewdb.client.Account) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) ArrayList(java.util.ArrayList) AuthException(com.google.gerrit.extensions.restapi.AuthException)

Example 15 with AccountGroup

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;
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) GroupApi(com.google.gerrit.extensions.api.groups.GroupApi) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) PermissionRule(com.google.gerrit.common.data.PermissionRule) ContributorAgreement(com.google.gerrit.common.data.ContributorAgreement) IdString(com.google.gerrit.extensions.restapi.IdString) GroupReference(com.google.gerrit.common.data.GroupReference)

Aggregations

AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)44 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)11 ArrayList (java.util.ArrayList)11 AuthException (com.google.gerrit.extensions.restapi.AuthException)10 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)8 Account (com.google.gerrit.reviewdb.client.Account)8 Test (org.junit.Test)8 GroupDescription (com.google.gerrit.common.data.GroupDescription)7 AccountGroupMember (com.google.gerrit.reviewdb.client.AccountGroupMember)7 GroupControl (com.google.gerrit.server.account.GroupControl)6 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)5 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)5 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 AccountGroupById (com.google.gerrit.reviewdb.client.AccountGroupById)4 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)4 GroupDetail (com.google.gerrit.common.data.GroupDetail)3 GroupReference (com.google.gerrit.common.data.GroupReference)3 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)3 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)3 AccountGroupName (com.google.gerrit.reviewdb.client.AccountGroupName)3