Search in sources :

Example 6 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 7 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 8 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 9 with AccountGroup

use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.

the class SuggestReviewersIT method suggestReviewersGroupSizeConsiderations.

@Test
@GerritConfig(name = "addreviewer.maxAllowed", value = "2")
@GerritConfig(name = "addreviewer.maxWithoutConfirmation", value = "1")
public void suggestReviewersGroupSizeConsiderations() throws Exception {
    AccountGroup largeGroup = group("large");
    AccountGroup mediumGroup = group("medium");
    // Both groups have Administrator as a member. Add two users to large
    // group to push it past maxAllowed, and one to medium group to push it
    // past maxWithoutConfirmation.
    user("individual 0", "Test0 Last0", largeGroup, mediumGroup);
    user("individual 1", "Test1 Last1", largeGroup);
    String changeId = createChange().getChangeId();
    List<SuggestedReviewerInfo> reviewers;
    SuggestedReviewerInfo reviewer;
    // Individual account suggestions have count of 1 and no confirm.
    reviewers = suggestReviewers(changeId, "test", 10);
    assertThat(reviewers).hasSize(2);
    reviewer = reviewers.get(0);
    assertThat(reviewer.count).isEqualTo(1);
    assertThat(reviewer.confirm).isNull();
    // Large group should never be suggested.
    reviewers = suggestReviewers(changeId, largeGroup.getName(), 10);
    assertThat(reviewers).isEmpty();
    // Medium group should be suggested with appropriate count and confirm.
    reviewers = suggestReviewers(changeId, mediumGroup.getName(), 10);
    assertThat(reviewers).hasSize(1);
    reviewer = reviewers.get(0);
    assertThat(reviewer.group.name).isEqualTo(mediumGroup.getName());
    assertThat(reviewer.count).isEqualTo(2);
    assertThat(reviewer.confirm).isTrue();
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) GerritConfig(com.google.gerrit.acceptance.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 10 with AccountGroup

use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.

the class ElasticTestUtils method createAllIndexes.

static void createAllIndexes(ElasticNodeInfo nodeInfo) {
    Schema<ChangeData> changeSchema = ChangeSchemaDefinitions.INSTANCE.getLatest();
    ChangeMapping openChangesMapping = new ChangeMapping(changeSchema);
    ChangeMapping closedChangesMapping = new ChangeMapping(changeSchema);
    openChangesMapping.closedChanges = null;
    closedChangesMapping.openChanges = null;
    nodeInfo.node.client().admin().indices().prepareCreate(String.format("%s%04d", CHANGES_PREFIX, changeSchema.getVersion())).addMapping(OPEN_CHANGES, gson.toJson(openChangesMapping)).addMapping(CLOSED_CHANGES, gson.toJson(closedChangesMapping)).execute().actionGet();
    Schema<AccountState> accountSchema = AccountSchemaDefinitions.INSTANCE.getLatest();
    AccountMapping accountMapping = new AccountMapping(accountSchema);
    nodeInfo.node.client().admin().indices().prepareCreate(String.format("%s%04d", ACCOUNTS_PREFIX, accountSchema.getVersion())).addMapping(ElasticAccountIndex.ACCOUNTS, gson.toJson(accountMapping)).execute().actionGet();
    Schema<AccountGroup> groupSchema = GroupSchemaDefinitions.INSTANCE.getLatest();
    GroupMapping groupMapping = new GroupMapping(groupSchema);
    nodeInfo.node.client().admin().indices().prepareCreate(String.format("%s%04d", GROUPS_PREFIX, groupSchema.getVersion())).addMapping(ElasticGroupIndex.GROUPS, gson.toJson(groupMapping)).execute().actionGet();
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AccountState(com.google.gerrit.server.account.AccountState) AccountMapping(com.google.gerrit.elasticsearch.ElasticAccountIndex.AccountMapping) GroupMapping(com.google.gerrit.elasticsearch.ElasticGroupIndex.GroupMapping) ChangeData(com.google.gerrit.server.query.change.ChangeData) ChangeMapping(com.google.gerrit.elasticsearch.ElasticChangeIndex.ChangeMapping)

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