Search in sources :

Example 1 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class GroupsIT method testGetGroup.

private void testGetGroup(Object id, AccountGroup expectedGroup) throws Exception {
    GroupInfo group = gApi.groups().id(id.toString()).get();
    assertGroupInfo(expectedGroup, group);
}
Also used : GroupAssert.assertGroupInfo(com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo) GroupInfo(com.google.gerrit.extensions.common.GroupInfo)

Example 2 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class ProjectWatchIT method watchProjectNotifyOnDraftChange.

@Test
public void watchProjectNotifyOnDraftChange() throws Exception {
    String watchedProject = createProject("watchedProject").get();
    // create group that can view all drafts
    GroupInfo groupThatCanViewDrafts = gApi.groups().create("groupThatCanViewDrafts").get();
    grant(new Project.NameKey(watchedProject), "refs/*", Permission.VIEW_DRAFTS, false, new AccountGroup.UUID(groupThatCanViewDrafts.id));
    // watch project as user that can't view drafts
    setApiUser(user);
    watch(watchedProject, null);
    // watch project as user that can view all drafts
    TestAccount userThatCanViewDrafts = accounts.create("user2", "user2@test.com", "User2", groupThatCanViewDrafts.name);
    setApiUser(userThatCanViewDrafts);
    watch(watchedProject, null);
    // push a draft change to watched project -> should trigger email notification for
    // userThatCanViewDrafts, but not for user
    setApiUser(admin);
    TestRepository<InMemoryRepository> watchedRepo = cloneProject(new Project.NameKey(watchedProject), admin);
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), watchedRepo, "TRIGGER", "a", "a1").to("refs/for/master%draft");
    r.assertOkStatus();
    // assert email notification
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(userThatCanViewDrafts.emailAddress);
    assertThat(m.body()).contains("Change subject: TRIGGER\n");
    assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Message(com.google.gerrit.testutil.FakeEmailSender.Message) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Project(com.google.gerrit.reviewdb.client.Project) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class QueryGroups method apply.

@Override
public List<GroupInfo> apply(TopLevelResource resource) throws BadRequestException, MethodNotAllowedException, OrmException {
    if (Strings.isNullOrEmpty(query)) {
        throw new BadRequestException("missing query field");
    }
    GroupIndex searchIndex = indexes.getSearchIndex();
    if (searchIndex == null) {
        throw new MethodNotAllowedException("no group index");
    }
    if (start != 0) {
        queryProcessor.setStart(start);
    }
    if (limit != 0) {
        queryProcessor.setLimit(limit);
    }
    try {
        QueryResult<AccountGroup> result = queryProcessor.query(queryBuilder.parse(query));
        List<AccountGroup> groups = result.entities();
        ArrayList<GroupInfo> groupInfos = Lists.newArrayListWithCapacity(groups.size());
        json.addOptions(options);
        for (AccountGroup group : groups) {
            groupInfos.add(json.format(GroupDescriptions.forAccountGroup(group)));
        }
        if (!groupInfos.isEmpty() && result.more()) {
            groupInfos.get(groupInfos.size() - 1)._moreGroups = true;
        }
        return groupInfos;
    } catch (QueryParseException e) {
        throw new BadRequestException(e.getMessage());
    }
}
Also used : MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) GroupIndex(com.google.gerrit.server.index.group.GroupIndex) QueryParseException(com.google.gerrit.server.query.QueryParseException)

Example 4 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class ListGroups method apply.

@Override
public SortedMap<String, GroupInfo> apply(TopLevelResource resource) throws OrmException, BadRequestException {
    SortedMap<String, GroupInfo> output = new TreeMap<>();
    for (GroupInfo info : get()) {
        output.put(MoreObjects.firstNonNull(info.name, "Group " + Url.decode(info.id)), info);
        info.name = null;
    }
    return output;
}
Also used : GroupInfo(com.google.gerrit.extensions.common.GroupInfo) TreeMap(java.util.TreeMap)

Example 5 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo 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)

Aggregations

GroupInfo (com.google.gerrit.extensions.common.GroupInfo)92 Test (org.junit.Test)60 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)43 AccountGroup (com.google.gerrit.entities.AccountGroup)28 GroupAssert.assertGroupInfo (com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo)24 ArrayList (java.util.ArrayList)11 GroupInput (com.google.gerrit.extensions.api.groups.GroupInput)10 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)10 Account (com.google.gerrit.entities.Account)8 AuthException (com.google.gerrit.extensions.restapi.AuthException)8 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)8 GroupControl (com.google.gerrit.server.account.GroupControl)8 GroupDescription (com.google.gerrit.entities.GroupDescription)7 GroupReference (com.google.gerrit.entities.GroupReference)7 TestAccount (com.google.gerrit.acceptance.TestAccount)6 InternalGroup (com.google.gerrit.entities.InternalGroup)6 GroupDescription (com.google.gerrit.common.data.GroupDescription)5 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)5 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)5 InternalGroupDescription (com.google.gerrit.server.group.InternalGroupDescription)5