Search in sources :

Example 21 with GroupInfo

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

the class GetGroups method apply.

@Override
public List<GroupInfo> apply(AccountResource resource) throws OrmException {
    IdentifiedUser user = resource.getUser();
    Account.Id userId = user.getAccountId();
    List<GroupInfo> groups = new ArrayList<>();
    for (AccountGroup.UUID uuid : user.getEffectiveGroups().getKnownGroups()) {
        GroupControl ctl;
        try {
            ctl = groupControlFactory.controlFor(uuid);
        } catch (NoSuchGroupException e) {
            continue;
        }
        if (ctl.isVisible() && ctl.canSeeMember(userId)) {
            groups.add(json.format(ctl.getGroup()));
        }
    }
    return groups;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ArrayList(java.util.ArrayList) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException)

Example 22 with GroupInfo

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

the class AbstractQueryGroupsTest method byInname.

@Test
public void byInname() throws Exception {
    String namePart = getSanitizedMethodName();
    namePart = CharMatcher.is('_').removeFrom(namePart);
    GroupInfo group1 = createGroup("group-" + namePart);
    GroupInfo group2 = createGroup("group-" + namePart + "-2");
    GroupInfo group3 = createGroup("group-" + namePart + "3");
    assertQuery("inname:" + namePart, group1, group2, group3);
    assertQuery("inname:" + namePart.toUpperCase(Locale.US), group1, group2, group3);
    assertQuery("inname:" + namePart.toLowerCase(Locale.US), group1, group2, group3);
}
Also used : GroupInfo(com.google.gerrit.extensions.common.GroupInfo) Test(org.junit.Test)

Example 23 with GroupInfo

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

the class AbstractQueryGroupsTest method byIsVisibleToAll.

@Test
public void byIsVisibleToAll() throws Exception {
    assertQuery("is:visibletoall");
    GroupInfo groupThatIsVisibleToAll = createGroupThatIsVisibleToAll(name("group-that-is-visible-to-all"));
    createGroup(name("group"));
    assertQuery("is:visibletoall", groupThatIsVisibleToAll);
}
Also used : GroupInfo(com.google.gerrit.extensions.common.GroupInfo) Test(org.junit.Test)

Example 24 with GroupInfo

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

the class AbstractQueryGroupsTest method reindex.

// reindex permissions are tested by {@link GroupsIT#reindexPermissions}
@Test
public void reindex() throws Exception {
    GroupInfo group1 = createGroupWithDescription(name("group"), "barX");
    // update group in the database so that group index is stale
    String newDescription = "barY";
    AccountGroup group = db.accountGroups().get(new AccountGroup.Id(group1.groupId));
    group.setDescription(newDescription);
    db.accountGroups().update(Collections.singleton(group));
    assertQuery("description:" + group1.description, group1);
    assertQuery("description:" + newDescription);
    gApi.groups().id(group1.id).index();
    assertQuery("description:" + group1.description);
    assertQuery("description:" + newDescription, group1);
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) Test(org.junit.Test)

Example 25 with GroupInfo

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

the class AbstractQueryGroupsTest method withLimit.

@Test
public void withLimit() throws Exception {
    GroupInfo group1 = createGroup(name("group1"));
    GroupInfo group2 = createGroup(name("group2"));
    GroupInfo group3 = createGroup(name("group3"));
    String query = "uuid:" + group1.id + " OR uuid:" + group2.id + " OR uuid:" + group3.id;
    List<GroupInfo> result = assertQuery(query, group1, group2, group3);
    assertThat(result.get(result.size() - 1)._moreGroups).isNull();
    result = assertQuery(newQuery(query).withLimit(2), result.subList(0, 2));
    assertThat(result.get(result.size() - 1)._moreGroups).isTrue();
}
Also used : GroupInfo(com.google.gerrit.extensions.common.GroupInfo) Test(org.junit.Test)

Aggregations

GroupInfo (com.google.gerrit.extensions.common.GroupInfo)38 Test (org.junit.Test)20 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)11 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 GroupAssert.assertGroupInfo (com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo)8 GroupDescription (com.google.gerrit.common.data.GroupDescription)5 ArrayList (java.util.ArrayList)5 GroupReference (com.google.gerrit.common.data.GroupReference)4 GroupInput (com.google.gerrit.extensions.api.groups.GroupInput)4 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)4 TestAccount (com.google.gerrit.acceptance.TestAccount)3 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)3 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)3 GroupControl (com.google.gerrit.server.account.GroupControl)3 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 Account (com.google.gerrit.reviewdb.client.Account)2 AccountGroupById (com.google.gerrit.reviewdb.client.AccountGroupById)2 Project (com.google.gerrit.reviewdb.client.Project)2 Message (com.google.gerrit.testutil.FakeEmailSender.Message)2