Search in sources :

Example 31 with AccountGroup

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

the class PutOptions method apply.

@Override
public GroupOptionsInfo apply(GroupResource resource, GroupOptionsInfo input) throws MethodNotAllowedException, AuthException, BadRequestException, ResourceNotFoundException, OrmException, IOException {
    if (resource.toAccountGroup() == null) {
        throw new MethodNotAllowedException();
    } else if (!resource.getControl().isOwner()) {
        throw new AuthException("Not group owner");
    }
    if (input == null) {
        throw new BadRequestException("options are required");
    }
    if (input.visibleToAll == null) {
        input.visibleToAll = false;
    }
    AccountGroup group = db.get().accountGroups().get(resource.toAccountGroup().getId());
    if (group == null) {
        throw new ResourceNotFoundException();
    }
    group.setVisibleToAll(input.visibleToAll);
    db.get().accountGroups().update(Collections.singleton(group));
    groupCache.evict(group);
    GroupOptionsInfo options = new GroupOptionsInfo();
    if (group.isVisibleToAll()) {
        options.visibleToAll = true;
    }
    return options;
}
Also used : MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AuthException(com.google.gerrit.extensions.restapi.AuthException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) GroupOptionsInfo(com.google.gerrit.extensions.common.GroupOptionsInfo)

Example 32 with AccountGroup

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

the class ListGroups method getAllGroups.

private List<GroupInfo> getAllGroups() throws OrmException {
    List<GroupInfo> groupInfos;
    List<AccountGroup> groupList;
    if (!projects.isEmpty()) {
        Map<AccountGroup.UUID, AccountGroup> groups = new HashMap<>();
        for (final ProjectControl projectControl : projects) {
            final Set<GroupReference> groupsRefs = projectControl.getAllGroups();
            for (final GroupReference groupRef : groupsRefs) {
                final AccountGroup group = groupCache.get(groupRef.getUUID());
                if (group != null) {
                    groups.put(group.getGroupUUID(), group);
                }
            }
        }
        groupList = filterGroups(groups.values());
    } else {
        groupList = filterGroups(groupCache.all());
    }
    groupInfos = Lists.newArrayListWithCapacity(groupList.size());
    int found = 0;
    int foundIndex = 0;
    for (AccountGroup group : groupList) {
        if (foundIndex++ < start) {
            continue;
        }
        if (limit > 0 && ++found > limit) {
            break;
        }
        groupInfos.add(json.addOptions(options).format(GroupDescriptions.forAccountGroup(group)));
    }
    return groupInfos;
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) HashMap(java.util.HashMap) GroupReference(com.google.gerrit.common.data.GroupReference) ProjectControl(com.google.gerrit.server.project.ProjectControl)

Example 33 with AccountGroup

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

the class ListMembers method getMembers.

private Map<Account.Id, AccountInfo> getMembers(final AccountGroup.UUID groupUUID, final HashSet<AccountGroup.UUID> seenGroups) throws OrmException {
    seenGroups.add(groupUUID);
    final Map<Account.Id, AccountInfo> members = new HashMap<>();
    final AccountGroup group = groupCache.get(groupUUID);
    if (group == null) {
        // the included group is an external group and can't be resolved
        return Collections.emptyMap();
    }
    final GroupDetail groupDetail;
    try {
        groupDetail = groupDetailFactory.create(group.getId()).call();
    } catch (NoSuchGroupException e) {
        // the included group is not visible
        return Collections.emptyMap();
    }
    if (groupDetail.members != null) {
        for (final AccountGroupMember m : groupDetail.members) {
            if (!members.containsKey(m.getAccountId())) {
                members.put(m.getAccountId(), accountLoader.get(m.getAccountId()));
            }
        }
    }
    if (recursive) {
        if (groupDetail.includes != null) {
            for (final AccountGroupById includedGroup : groupDetail.includes) {
                if (!seenGroups.contains(includedGroup.getIncludeUUID())) {
                    members.putAll(getMembers(includedGroup.getIncludeUUID(), seenGroups));
                }
            }
        }
    }
    accountLoader.fill();
    return members;
}
Also used : GroupDetail(com.google.gerrit.common.data.GroupDetail) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) HashMap(java.util.HashMap) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById)

Example 34 with AccountGroup

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

the class Schema_87 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    for (AccountGroup.Id id : scanSystemGroups(db)) {
        AccountGroup group = db.accountGroups().get(id);
        if (group != null && SystemGroupBackend.isSystemGroup(group.getGroupUUID())) {
            db.accountGroups().delete(Collections.singleton(group));
            db.accountGroupNames().deleteKeys(Collections.singleton(group.getNameKey()));
        }
    }
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup)

Example 35 with AccountGroup

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

the class GroupQueryBuilder method owner.

@Operator
public Predicate<AccountGroup> owner(String owner) throws QueryParseException {
    AccountGroup group = args.groupCache.get(new AccountGroup.UUID(owner));
    if (group != null) {
        return GroupPredicates.owner(group.getGroupUUID());
    }
    GroupReference g = GroupBackends.findBestSuggestion(args.groupBackend, owner);
    if (g == null) {
        throw error("Group " + owner + " not found");
    }
    return GroupPredicates.owner(g.getUUID());
}
Also used : AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupReference(com.google.gerrit.common.data.GroupReference)

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