Search in sources :

Example 1 with GroupDescription

use of com.google.gerrit.entities.GroupDescription in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method ownerin.

@Operator
public Predicate<ChangeData> ownerin(String group) throws QueryParseException, IOException {
    GroupReference g = GroupBackends.findBestSuggestion(args.groupBackend, group);
    if (g == null) {
        throw error("Group " + group + " not found");
    }
    AccountGroup.UUID groupId = g.getUUID();
    GroupDescription.Basic groupDescription = args.groupBackend.get(groupId);
    if (!(groupDescription instanceof GroupDescription.Internal)) {
        return new OwnerinPredicate(args.userFactory, groupId);
    }
    Set<Account.Id> accounts = getMembers(groupId);
    List<Predicate<ChangeData>> p = Lists.newArrayListWithCapacity(accounts.size());
    for (Account.Id id : accounts) {
        p.add(ChangePredicates.owner(id));
    }
    return Predicate.or(p);
}
Also used : Account(com.google.gerrit.entities.Account) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) LimitPredicate(com.google.gerrit.index.query.LimitPredicate) Predicate(com.google.gerrit.index.query.Predicate) GroupDescription(com.google.gerrit.entities.GroupDescription) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupReference(com.google.gerrit.entities.GroupReference)

Example 2 with GroupDescription

use of com.google.gerrit.entities.GroupDescription in project gerrit by GerritCodeReview.

the class GetAuditLog method apply.

@Override
public Response<List<? extends GroupAuditEventInfo>> apply(GroupResource rsrc) throws AuthException, NotInternalGroupException, IOException, ConfigInvalidException, PermissionBackendException {
    GroupDescription.Internal group = rsrc.asInternalGroup().orElseThrow(NotInternalGroupException::new);
    if (!rsrc.getControl().isOwner()) {
        throw new AuthException("Not group owner");
    }
    AccountLoader accountLoader = accountLoaderFactory.create(true);
    List<GroupAuditEventInfo> auditEvents = new ArrayList<>();
    try (Repository allUsersRepo = repoManager.openRepository(allUsers)) {
        for (AccountGroupMemberAudit auditEvent : groups.getMembersAudit(allUsersRepo, group.getGroupUUID())) {
            AccountInfo member = accountLoader.get(auditEvent.memberId());
            auditEvents.add(GroupAuditEventInfo.createAddUserEvent(accountLoader.get(auditEvent.addedBy()), auditEvent.addedOn(), member));
            if (!auditEvent.isActive()) {
                auditEvents.add(GroupAuditEventInfo.createRemoveUserEvent(accountLoader.get(auditEvent.removedBy().orElse(null)), auditEvent.removedOn().orElse(null), member));
            }
        }
        List<AccountGroupByIdAudit> subGroupsAudit = groups.getSubgroupsAudit(allUsersRepo, group.getGroupUUID());
        Map<AccountGroup.UUID, InternalGroup> groups = groupCache.get(subGroupsAudit.stream().map(a -> a.includeUuid()).collect(toImmutableList()));
        for (AccountGroupByIdAudit auditEvent : subGroupsAudit) {
            AccountGroup.UUID includedGroupUUID = auditEvent.includeUuid();
            InternalGroup includedGroup = groups.get(includedGroupUUID);
            GroupInfo member;
            if (includedGroup != null) {
                member = groupJson.format(new InternalGroupDescription(includedGroup));
            } else {
                member = new GroupInfo();
                member.id = Url.encode(includedGroupUUID.get());
                GroupDescription.Basic groupDescription = groupBackend.get(includedGroupUUID);
                if (groupDescription != null) {
                    member.name = groupDescription.getName();
                }
            }
            auditEvents.add(GroupAuditEventInfo.createAddGroupEvent(accountLoader.get(auditEvent.addedBy()), auditEvent.addedOn(), member));
            if (!auditEvent.isActive()) {
                auditEvents.add(GroupAuditEventInfo.createRemoveGroupEvent(accountLoader.get(auditEvent.removedBy().orElse(null)), auditEvent.removedOn().orElse(null), member));
            }
        }
    }
    accountLoader.fill();
    // sort by date and then reverse so that the newest audit event comes first
    auditEvents.sort(comparing((GroupAuditEventInfo a) -> a.date).reversed());
    return Response.ok(auditEvents);
}
Also used : InternalGroupDescription(com.google.gerrit.server.group.InternalGroupDescription) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ArrayList(java.util.ArrayList) AccountGroupByIdAudit(com.google.gerrit.entities.AccountGroupByIdAudit) AuthException(com.google.gerrit.extensions.restapi.AuthException) InternalGroup(com.google.gerrit.entities.InternalGroup) GroupDescription(com.google.gerrit.entities.GroupDescription) InternalGroupDescription(com.google.gerrit.server.group.InternalGroupDescription) Repository(org.eclipse.jgit.lib.Repository) GroupAuditEventInfo(com.google.gerrit.extensions.common.GroupAuditEventInfo) AccountGroup(com.google.gerrit.entities.AccountGroup) AccountLoader(com.google.gerrit.server.account.AccountLoader) AccountGroupMemberAudit(com.google.gerrit.entities.AccountGroupMemberAudit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 3 with GroupDescription

use of com.google.gerrit.entities.GroupDescription in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method uploaderin.

@Operator
public Predicate<ChangeData> uploaderin(String group) throws QueryParseException, IOException {
    checkFieldAvailable(ChangeField.UPLOADER, "uploaderin");
    GroupReference g = GroupBackends.findBestSuggestion(args.groupBackend, group);
    if (g == null) {
        throw error("Group " + group + " not found");
    }
    AccountGroup.UUID groupId = g.getUUID();
    GroupDescription.Basic groupDescription = args.groupBackend.get(groupId);
    if (!(groupDescription instanceof GroupDescription.Internal)) {
        return new UploaderinPredicate(args.userFactory, groupId);
    }
    Set<Account.Id> accounts = getMembers(groupId);
    List<Predicate<ChangeData>> p = Lists.newArrayListWithCapacity(accounts.size());
    for (Account.Id id : accounts) {
        p.add(ChangePredicates.uploader(id));
    }
    return Predicate.or(p);
}
Also used : Account(com.google.gerrit.entities.Account) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) LimitPredicate(com.google.gerrit.index.query.LimitPredicate) Predicate(com.google.gerrit.index.query.Predicate) GroupDescription(com.google.gerrit.entities.GroupDescription) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupReference(com.google.gerrit.entities.GroupReference)

Aggregations

AccountGroup (com.google.gerrit.entities.AccountGroup)3 GroupDescription (com.google.gerrit.entities.GroupDescription)3 Account (com.google.gerrit.entities.Account)2 GroupReference (com.google.gerrit.entities.GroupReference)2 LimitPredicate (com.google.gerrit.index.query.LimitPredicate)2 Predicate (com.google.gerrit.index.query.Predicate)2 ReviewerStateInternal (com.google.gerrit.server.notedb.ReviewerStateInternal)2 AccountGroupByIdAudit (com.google.gerrit.entities.AccountGroupByIdAudit)1 AccountGroupMemberAudit (com.google.gerrit.entities.AccountGroupMemberAudit)1 InternalGroup (com.google.gerrit.entities.InternalGroup)1 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1 GroupAuditEventInfo (com.google.gerrit.extensions.common.GroupAuditEventInfo)1 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 AccountLoader (com.google.gerrit.server.account.AccountLoader)1 InternalGroupDescription (com.google.gerrit.server.group.InternalGroupDescription)1 ArrayList (java.util.ArrayList)1 Repository (org.eclipse.jgit.lib.Repository)1