use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.
the class QueryGroups method apply.
@Override
public Response<List<GroupInfo>> apply(TopLevelResource resource) throws BadRequestException, MethodNotAllowedException, PermissionBackendException {
if (Strings.isNullOrEmpty(query)) {
throw new BadRequestException("missing query field");
}
GroupQueryProcessor queryProcessor = queryProcessorProvider.get();
if (queryProcessor.isDisabled()) {
throw new MethodNotAllowedException("query disabled");
}
if (start != 0) {
queryProcessor.setStart(start);
}
if (limit != 0) {
queryProcessor.setUserProvidedLimit(limit);
}
try {
QueryResult<InternalGroup> result = queryProcessor.query(queryBuilder.parse(query));
List<InternalGroup> groups = result.entities();
ArrayList<GroupInfo> groupInfos = Lists.newArrayListWithCapacity(groups.size());
json.addOptions(options);
for (InternalGroup group : groups) {
groupInfos.add(json.format(new InternalGroupDescription(group)));
}
if (!groupInfos.isEmpty() && result.more()) {
groupInfos.get(groupInfos.size() - 1)._moreGroups = true;
}
return Response.ok(groupInfos);
} catch (QueryParseException e) {
throw new BadRequestException(e.getMessage());
}
}
use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.
the class GroupsUpdate method updateGroupInNoteDb.
@VisibleForTesting
public UpdateResult updateGroupInNoteDb(AccountGroup.UUID groupUuid, GroupDelta groupDelta) throws IOException, ConfigInvalidException, DuplicateKeyException, NoSuchGroupException {
try (Repository allUsersRepo = repoManager.openRepository(allUsersName)) {
GroupConfig groupConfig = GroupConfig.loadForGroup(allUsersName, allUsersRepo, groupUuid);
groupConfig.setGroupDelta(groupDelta, auditLogFormatter);
if (!groupConfig.getLoadedGroup().isPresent()) {
throw new NoSuchGroupException(groupUuid);
}
InternalGroup originalGroup = groupConfig.getLoadedGroup().get();
GroupNameNotes groupNameNotes = null;
if (groupDelta.getName().isPresent()) {
AccountGroup.NameKey oldName = originalGroup.getNameKey();
AccountGroup.NameKey newName = groupDelta.getName().get();
groupNameNotes = GroupNameNotes.forRename(allUsersName, allUsersRepo, groupUuid, oldName, newName);
}
commit(allUsersRepo, groupConfig, groupNameNotes);
InternalGroup updatedGroup = groupConfig.getLoadedGroup().orElseThrow(() -> new IllegalStateException("Updated group wasn't automatically loaded"));
return getUpdateResult(originalGroup, updatedGroup);
}
}
use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.
the class AuditLogReaderTest method createGroupAsUserIdent.
@Test
public void createGroupAsUserIdent() throws Exception {
InternalGroup group = createGroupAsUser(1, "test-group");
AccountGroup.UUID uuid = group.getGroupUUID();
AccountGroupMemberAudit expAudit = createExpMemberAudit(group.getId(), userId, userId, getTipTimestamp(uuid));
assertThat(auditLogReader.getMembersAudit(allUsersRepo, uuid)).containsExactly(expAudit);
}
use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.
the class AuditLogReaderTest method addAndRemoveMembersAndSubgroups.
@Test
public void addAndRemoveMembersAndSubgroups() throws Exception {
InternalGroup group = createGroupAsUser(1, "test-group");
AccountGroup.Id groupId = group.getId();
AccountGroup.UUID uuid = group.getGroupUUID();
AccountGroupMemberAudit expMemberAudit = createExpMemberAudit(groupId, userId, userId, getTipTimestamp(uuid));
assertThat(auditLogReader.getMembersAudit(allUsersRepo, uuid)).containsExactly(expMemberAudit);
Account.Id id1 = Account.id(100002);
Account.Id id2 = Account.id(100003);
Account.Id id3 = Account.id(100004);
InternalGroup subgroup1 = createGroupAsUser(2, "test-group-2");
InternalGroup subgroup2 = createGroupAsUser(3, "test-group-3");
InternalGroup subgroup3 = createGroupAsUser(4, "test-group-4");
AccountGroup.UUID subgroupUuid1 = subgroup1.getGroupUUID();
AccountGroup.UUID subgroupUuid2 = subgroup2.getGroupUUID();
AccountGroup.UUID subgroupUuid3 = subgroup3.getGroupUUID();
// Add two accounts.
addMembers(uuid, ImmutableSet.of(id1, id2));
AccountGroupMemberAudit expMemberAudit1 = createExpMemberAudit(groupId, id1, userId, getTipTimestamp(uuid));
AccountGroupMemberAudit expMemberAudit2 = createExpMemberAudit(groupId, id2, userId, getTipTimestamp(uuid));
assertThat(auditLogReader.getMembersAudit(allUsersRepo, uuid)).containsExactly(expMemberAudit, expMemberAudit1, expMemberAudit2).inOrder();
// Add one subgroup.
addSubgroups(uuid, ImmutableSet.of(subgroupUuid1));
AccountGroupByIdAudit expGroupAudit1 = createExpGroupAudit(group.getId(), subgroupUuid1, userId, getTipTimestamp(uuid));
assertThat(auditLogReader.getSubgroupsAudit(allUsersRepo, uuid)).containsExactly(expGroupAudit1);
// Remove one account.
removeMembers(uuid, ImmutableSet.of(id2));
expMemberAudit2 = expMemberAudit2.toBuilder().removed(userId, getTipTimestamp(uuid)).build();
assertThat(auditLogReader.getMembersAudit(allUsersRepo, uuid)).containsExactly(expMemberAudit, expMemberAudit1, expMemberAudit2).inOrder();
// Add two subgroups.
addSubgroups(uuid, ImmutableSet.of(subgroupUuid2, subgroupUuid3));
AccountGroupByIdAudit expGroupAudit2 = createExpGroupAudit(group.getId(), subgroupUuid2, userId, getTipTimestamp(uuid));
AccountGroupByIdAudit expGroupAudit3 = createExpGroupAudit(group.getId(), subgroupUuid3, userId, getTipTimestamp(uuid));
assertThat(auditLogReader.getSubgroupsAudit(allUsersRepo, uuid)).containsExactly(expGroupAudit1, expGroupAudit2, expGroupAudit3).inOrder();
// Add two account, including a removed account.
addMembers(uuid, ImmutableSet.of(id2, id3));
AccountGroupMemberAudit expMemberAudit4 = createExpMemberAudit(groupId, id2, userId, getTipTimestamp(uuid));
AccountGroupMemberAudit expMemberAudit3 = createExpMemberAudit(groupId, id3, userId, getTipTimestamp(uuid));
assertThat(auditLogReader.getMembersAudit(allUsersRepo, uuid)).containsExactly(expMemberAudit, expMemberAudit1, expMemberAudit2, expMemberAudit4, expMemberAudit3).inOrder();
// Remove two subgroups.
removeSubgroups(uuid, ImmutableSet.of(subgroupUuid1, subgroupUuid3));
expGroupAudit1 = expGroupAudit1.toBuilder().removed(userId, getTipTimestamp(uuid)).build();
expGroupAudit3 = expGroupAudit3.toBuilder().removed(userId, getTipTimestamp(uuid)).build();
assertThat(auditLogReader.getSubgroupsAudit(allUsersRepo, uuid)).containsExactly(expGroupAudit1, expGroupAudit2, expGroupAudit3).inOrder();
// Add back one removed subgroup.
addSubgroups(uuid, ImmutableSet.of(subgroupUuid1));
AccountGroupByIdAudit expGroupAudit4 = createExpGroupAudit(group.getId(), subgroupUuid1, userId, getTipTimestamp(uuid));
assertThat(auditLogReader.getSubgroupsAudit(allUsersRepo, uuid)).containsExactly(expGroupAudit1, expGroupAudit2, expGroupAudit3, expGroupAudit4).inOrder();
}
use of com.google.gerrit.entities.InternalGroup in project gerrit by GerritCodeReview.
the class GroupConfigTest method createdOnIsNotAffectedByFurtherUpdates.
@Test
public void createdOnIsNotAffectedByFurtherUpdates() throws Exception {
Instant createdOn = toInstant(LocalDate.of(2017, Month.MAY, 11).atTime(13, 44, 10));
Instant updatedOn = toInstant(LocalDate.of(2017, Month.DECEMBER, 12).atTime(10, 21, 49));
InternalGroupCreation groupCreation = getPrefilledGroupCreationBuilder().build();
GroupDelta initialGroupDelta = GroupDelta.builder().setUpdatedOn(createdOn).build();
createGroup(groupCreation, initialGroupDelta);
GroupDelta laterGroupDelta = GroupDelta.builder().setName(AccountGroup.nameKey("Another name")).setUpdatedOn(updatedOn).build();
Optional<InternalGroup> group = updateGroup(groupCreation.getGroupUUID(), laterGroupDelta);
assertThatGroup(group).value().createdOn().isEqualTo(createdOn);
Optional<InternalGroup> reloadedGroup = loadGroup(groupUuid);
assertThatGroup(reloadedGroup).value().createdOn().isEqualTo(createdOn);
}
Aggregations