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;
}
}
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());
}
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);
}
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()));
}
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);
}
Aggregations