Search in sources :

Example 1 with GroupControl

use of com.google.gerrit.server.account.GroupControl in project gerrit by GerritCodeReview.

the class AgreementJson method format.

public AgreementInfo format(ContributorAgreement ca) {
    AgreementInfo info = new AgreementInfo();
    info.name = ca.getName();
    info.description = ca.getDescription();
    info.url = ca.getAgreementUrl();
    GroupReference autoVerifyGroup = ca.getAutoVerify();
    if (autoVerifyGroup != null && self.get().isIdentifiedUser()) {
        IdentifiedUser user = identifiedUserFactory.create(self.get().getAccountId());
        try {
            GroupControl gc = genericGroupControlFactory.controlFor(user, autoVerifyGroup.getUUID());
            GroupResource group = new GroupResource(gc);
            info.autoVerifyGroup = groupJson.format(group);
        } catch (NoSuchGroupException | OrmException e) {
            log.warn("autoverify group \"" + autoVerifyGroup.getName() + "\" does not exist, referenced in CLA \"" + ca.getName() + "\"");
        }
    }
    return info;
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) OrmException(com.google.gwtorm.server.OrmException) AgreementInfo(com.google.gerrit.extensions.common.AgreementInfo) GroupReference(com.google.gerrit.common.data.GroupReference) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) GroupResource(com.google.gerrit.server.group.GroupResource) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException)

Example 2 with GroupControl

use of com.google.gerrit.server.account.GroupControl in project gerrit by GerritCodeReview.

the class ListGroups method filterGroups.

private List<AccountGroup> filterGroups(Collection<AccountGroup> groups) {
    List<AccountGroup> filteredGroups = new ArrayList<>(groups.size());
    for (AccountGroup group : groups) {
        if (!Strings.isNullOrEmpty(matchSubstring)) {
            if (!group.getName().toLowerCase(Locale.US).contains(matchSubstring.toLowerCase(Locale.US))) {
                continue;
            }
        }
        if (visibleToAll && !group.isVisibleToAll()) {
            continue;
        }
        if (!groupsToInspect.isEmpty() && !groupsToInspect.contains(group.getGroupUUID())) {
            continue;
        }
        GroupControl c = groupControlFactory.controlFor(group);
        if (c.isVisible()) {
            filteredGroups.add(group);
        }
    }
    Collections.sort(filteredGroups, new GroupComparator());
    return filteredGroups;
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) GroupComparator(com.google.gerrit.server.account.GroupComparator) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) ArrayList(java.util.ArrayList)

Example 3 with GroupControl

use of com.google.gerrit.server.account.GroupControl in project gerrit by GerritCodeReview.

the class ListGroups method getGroupsOwnedBy.

private List<GroupInfo> getGroupsOwnedBy(IdentifiedUser user) throws OrmException {
    List<GroupInfo> groups = new ArrayList<>();
    int found = 0;
    int foundIndex = 0;
    for (AccountGroup g : filterGroups(groupCache.all())) {
        GroupControl ctl = groupControlFactory.controlFor(g);
        try {
            if (genericGroupControlFactory.controlFor(user, g.getGroupUUID()).isOwner()) {
                if (foundIndex++ < start) {
                    continue;
                }
                if (limit > 0 && ++found > limit) {
                    break;
                }
                groups.add(json.addOptions(options).format(ctl.getGroup()));
            }
        } catch (NoSuchGroupException e) {
            continue;
        }
    }
    return groups;
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ArrayList(java.util.ArrayList) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException)

Example 4 with GroupControl

use of com.google.gerrit.server.account.GroupControl in project gerrit by GerritCodeReview.

the class ListIncludedGroups method apply.

@Override
public List<GroupInfo> apply(GroupResource rsrc) throws MethodNotAllowedException, OrmException {
    if (rsrc.toAccountGroup() == null) {
        throw new MethodNotAllowedException();
    }
    boolean ownerOfParent = rsrc.getControl().isOwner();
    List<GroupInfo> included = new ArrayList<>();
    for (AccountGroupById u : dbProvider.get().accountGroupById().byGroup(rsrc.toAccountGroup().getId())) {
        try {
            GroupControl i = controlFactory.controlFor(u.getIncludeUUID());
            if (ownerOfParent || i.isVisible()) {
                included.add(json.format(i.getGroup()));
            }
        } catch (NoSuchGroupException notFound) {
            log.warn(String.format("Group %s no longer available, included into %s", u.getIncludeUUID(), rsrc.getGroup().getName()));
            continue;
        }
    }
    Collections.sort(included, new Comparator<GroupInfo>() {

        @Override
        public int compare(GroupInfo a, GroupInfo b) {
            int cmp = nullToEmpty(a.name).compareTo(nullToEmpty(b.name));
            if (cmp != 0) {
                return cmp;
            }
            return nullToEmpty(a.id).compareTo(nullToEmpty(b.id));
        }
    });
    return included;
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ArrayList(java.util.ArrayList) AccountGroupById(com.google.gerrit.reviewdb.client.AccountGroupById) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException)

Example 5 with GroupControl

use of com.google.gerrit.server.account.GroupControl in project gerrit by GerritCodeReview.

the class DeleteMembers method apply.

@Override
public Response<?> apply(GroupResource resource, Input input) throws AuthException, MethodNotAllowedException, UnprocessableEntityException, OrmException, IOException {
    AccountGroup internalGroup = resource.toAccountGroup();
    if (internalGroup == null) {
        throw new MethodNotAllowedException();
    }
    input = Input.init(input);
    final GroupControl control = resource.getControl();
    final Map<Account.Id, AccountGroupMember> members = getMembers(internalGroup.getId());
    final List<AccountGroupMember> toRemove = new ArrayList<>();
    for (final String nameOrEmail : input.members) {
        Account a = accounts.parse(nameOrEmail).getAccount();
        if (!control.canRemoveMember()) {
            throw new AuthException("Cannot delete member: " + a.getFullName());
        }
        final AccountGroupMember m = members.remove(a.getId());
        if (m != null) {
            toRemove.add(m);
        }
    }
    writeAudits(toRemove);
    db.get().accountGroupMembers().delete(toRemove);
    for (final AccountGroupMember m : toRemove) {
        accountCache.evict(m.getAccountId());
    }
    return Response.none();
}
Also used : GroupControl(com.google.gerrit.server.account.GroupControl) Account(com.google.gerrit.reviewdb.client.Account) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) AccountGroupMember(com.google.gerrit.reviewdb.client.AccountGroupMember) ArrayList(java.util.ArrayList) AuthException(com.google.gerrit.extensions.restapi.AuthException)

Aggregations

GroupControl (com.google.gerrit.server.account.GroupControl)19 AuthException (com.google.gerrit.extensions.restapi.AuthException)10 ArrayList (java.util.ArrayList)9 AccountGroup (com.google.gerrit.entities.AccountGroup)7 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)7 GroupDescription (com.google.gerrit.entities.GroupDescription)6 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)6 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)6 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)6 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)5 GroupResource (com.google.gerrit.server.group.GroupResource)4 HashSet (java.util.HashSet)4 GroupDescription (com.google.gerrit.common.data.GroupDescription)3 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)3 Account (com.google.gerrit.reviewdb.client.Account)3 AccountGroupById (com.google.gerrit.reviewdb.client.AccountGroupById)3 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)3 Account (com.google.gerrit.entities.Account)2 AgreementInfo (com.google.gerrit.extensions.common.AgreementInfo)2 IdString (com.google.gerrit.extensions.restapi.IdString)2