Search in sources :

Example 6 with InternalGroup

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());
    }
}
Also used : InternalGroupDescription(com.google.gerrit.server.group.InternalGroupDescription) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) GroupQueryProcessor(com.google.gerrit.server.query.group.GroupQueryProcessor) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) InternalGroup(com.google.gerrit.entities.InternalGroup) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Example 7 with InternalGroup

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);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) AccountGroup(com.google.gerrit.entities.AccountGroup) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException) InternalGroup(com.google.gerrit.entities.InternalGroup) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with InternalGroup

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);
}
Also used : AccountGroup(com.google.gerrit.entities.AccountGroup) AccountGroupMemberAudit(com.google.gerrit.entities.AccountGroupMemberAudit) InternalGroup(com.google.gerrit.entities.InternalGroup) Test(org.junit.Test)

Example 9 with InternalGroup

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();
}
Also used : Account(com.google.gerrit.entities.Account) AccountGroup(com.google.gerrit.entities.AccountGroup) AccountGroupMemberAudit(com.google.gerrit.entities.AccountGroupMemberAudit) AccountGroupByIdAudit(com.google.gerrit.entities.AccountGroupByIdAudit) InternalGroup(com.google.gerrit.entities.InternalGroup) Test(org.junit.Test)

Example 10 with InternalGroup

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);
}
Also used : Instant(java.time.Instant) InternalGroup(com.google.gerrit.entities.InternalGroup) Test(org.junit.Test)

Aggregations

InternalGroup (com.google.gerrit.entities.InternalGroup)41 AccountGroup (com.google.gerrit.entities.AccountGroup)18 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)6 AccountGroupMemberAudit (com.google.gerrit.entities.AccountGroupMemberAudit)5 GroupReference (com.google.gerrit.entities.GroupReference)5 Account (com.google.gerrit.entities.Account)4 AccountGroupByIdAudit (com.google.gerrit.entities.AccountGroupByIdAudit)4 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)4 Instant (java.time.Instant)4 GroupDescription (com.google.gerrit.entities.GroupDescription)3 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)3 InternalGroupDescription (com.google.gerrit.server.group.InternalGroupDescription)3 GroupDelta (com.google.gerrit.server.group.db.GroupDelta)3 HashSet (java.util.HashSet)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 ConsistencyProblemInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)2 TraceTimer (com.google.gerrit.server.logging.TraceContext.TraceTimer)2 IOException (java.io.IOException)2 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)2