Search in sources :

Example 16 with AccountGroup

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

the class AccountCreator method create.

public synchronized TestAccount create(@Nullable String username, @Nullable String email, @Nullable String fullName, String... groups) throws Exception {
    TestAccount account = accounts.get(username);
    if (account != null) {
        return account;
    }
    try (ReviewDb db = reviewDbProvider.open()) {
        Account.Id id = new Account.Id(db.nextAccountId());
        List<ExternalId> extIds = new ArrayList<>(2);
        String httpPass = null;
        if (username != null) {
            httpPass = "http-pass";
            extIds.add(ExternalId.createUsername(username, id, httpPass));
        }
        if (email != null) {
            extIds.add(ExternalId.createEmail(id, email));
        }
        externalIdsUpdate.create().insert(extIds);
        Account a = new Account(id, TimeUtil.nowTs());
        a.setFullName(fullName);
        a.setPreferredEmail(email);
        accountsUpdate.create().insert(db, a);
        if (groups != null) {
            for (String n : groups) {
                AccountGroup.NameKey k = new AccountGroup.NameKey(n);
                AccountGroup g = groupCache.get(k);
                checkArgument(g != null, "group not found: %s", n);
                AccountGroupMember m = new AccountGroupMember(new AccountGroupMember.Key(id, g.getId()));
                db.accountGroupMembers().insert(Collections.singleton(m));
            }
        }
        KeyPair sshKey = null;
        if (SshMode.useSsh() && username != null) {
            sshKey = genSshKey();
            authorizedKeys.addKey(id, publicKey(sshKey, email));
            sshKeyCache.evict(username);
        }
        if (username != null) {
            accountCache.evictByUsername(username);
        }
        byEmailCache.evict(email);
        indexer.index(id);
        account = new TestAccount(id, username, email, fullName, sshKey, httpPass);
        if (username != null) {
            accounts.put(username, account);
        }
        return account;
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) KeyPair(com.jcraft.jsch.KeyPair) AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ArrayList(java.util.ArrayList) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 17 with AccountGroup

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

the class AbstractDaemonTest method grant.

protected void grant(Project.NameKey project, String ref, String permission, boolean force) throws RepositoryNotFoundException, IOException, ConfigInvalidException {
    AccountGroup adminGroup = groupCache.get(new AccountGroup.NameKey("Administrators"));
    grant(project, ref, permission, force, adminGroup.getGroupUUID());
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup)

Example 18 with AccountGroup

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

the class GroupsIT method getGroup.

@Test
public void getGroup() throws Exception {
    AccountGroup adminGroup = groupCache.get(new AccountGroup.NameKey("Administrators"));
    testGetGroup(adminGroup.getGroupUUID().get(), adminGroup);
    testGetGroup(adminGroup.getName(), adminGroup);
    testGetGroup(adminGroup.getId().get(), adminGroup);
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 19 with AccountGroup

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

the class GroupsIT method allGroupInfoFieldsSetCorrectly.

@Test
public void allGroupInfoFieldsSetCorrectly() throws Exception {
    AccountGroup adminGroup = getFromCache("Administrators");
    Map<String, GroupInfo> groups = gApi.groups().list().addGroup(adminGroup.getName()).getAsMap();
    assertThat(groups).hasSize(1);
    assertThat(groups).containsKey("Administrators");
    assertGroupInfo(adminGroup, Iterables.getOnlyElement(groups.values()));
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupAssert.assertGroupInfo(com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 20 with AccountGroup

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

the class AccessIT method addNonGlobalCapabilityToGlobalCapabilities.

@Test
public void addNonGlobalCapabilityToGlobalCapabilities() throws Exception {
    AccountGroup adminGroup = groupCache.get(new AccountGroup.NameKey("Administrators"));
    ProjectAccessInput accessInput = newProjectAccessInput();
    AccessSectionInfo accessSectionInfo = newAccessSectionInfo();
    PermissionInfo permissionInfo = newPermissionInfo();
    permissionInfo.rules.put(adminGroup.getGroupUUID().get(), null);
    accessSectionInfo.permissions.put(Permission.PUSH, permissionInfo);
    accessInput.add.put(AccessSection.GLOBAL_CAPABILITIES, accessSectionInfo);
    exception.expect(BadRequestException.class);
    gApi.projects().name(allProjects.get()).access(accessInput);
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) PermissionInfo(com.google.gerrit.extensions.api.access.PermissionInfo) AccessSectionInfo(com.google.gerrit.extensions.api.access.AccessSectionInfo) ProjectAccessInput(com.google.gerrit.extensions.api.access.ProjectAccessInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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