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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations