use of com.google.gerrit.reviewdb.client.AccountGroup 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.reviewdb.client.AccountGroup 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.reviewdb.client.AccountGroup 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();
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class SuggestReviewersIT method suggestReviewersGroupSizeConsiderations.
@Test
@GerritConfig(name = "addreviewer.maxAllowed", value = "2")
@GerritConfig(name = "addreviewer.maxWithoutConfirmation", value = "1")
public void suggestReviewersGroupSizeConsiderations() throws Exception {
AccountGroup largeGroup = group("large");
AccountGroup mediumGroup = group("medium");
// Both groups have Administrator as a member. Add two users to large
// group to push it past maxAllowed, and one to medium group to push it
// past maxWithoutConfirmation.
user("individual 0", "Test0 Last0", largeGroup, mediumGroup);
user("individual 1", "Test1 Last1", largeGroup);
String changeId = createChange().getChangeId();
List<SuggestedReviewerInfo> reviewers;
SuggestedReviewerInfo reviewer;
// Individual account suggestions have count of 1 and no confirm.
reviewers = suggestReviewers(changeId, "test", 10);
assertThat(reviewers).hasSize(2);
reviewer = reviewers.get(0);
assertThat(reviewer.count).isEqualTo(1);
assertThat(reviewer.confirm).isNull();
// Large group should never be suggested.
reviewers = suggestReviewers(changeId, largeGroup.getName(), 10);
assertThat(reviewers).isEmpty();
// Medium group should be suggested with appropriate count and confirm.
reviewers = suggestReviewers(changeId, mediumGroup.getName(), 10);
assertThat(reviewers).hasSize(1);
reviewer = reviewers.get(0);
assertThat(reviewer.group.name).isEqualTo(mediumGroup.getName());
assertThat(reviewer.count).isEqualTo(2);
assertThat(reviewer.confirm).isTrue();
}
use of com.google.gerrit.reviewdb.client.AccountGroup in project gerrit by GerritCodeReview.
the class ElasticTestUtils method createAllIndexes.
static void createAllIndexes(ElasticNodeInfo nodeInfo) {
Schema<ChangeData> changeSchema = ChangeSchemaDefinitions.INSTANCE.getLatest();
ChangeMapping openChangesMapping = new ChangeMapping(changeSchema);
ChangeMapping closedChangesMapping = new ChangeMapping(changeSchema);
openChangesMapping.closedChanges = null;
closedChangesMapping.openChanges = null;
nodeInfo.node.client().admin().indices().prepareCreate(String.format("%s%04d", CHANGES_PREFIX, changeSchema.getVersion())).addMapping(OPEN_CHANGES, gson.toJson(openChangesMapping)).addMapping(CLOSED_CHANGES, gson.toJson(closedChangesMapping)).execute().actionGet();
Schema<AccountState> accountSchema = AccountSchemaDefinitions.INSTANCE.getLatest();
AccountMapping accountMapping = new AccountMapping(accountSchema);
nodeInfo.node.client().admin().indices().prepareCreate(String.format("%s%04d", ACCOUNTS_PREFIX, accountSchema.getVersion())).addMapping(ElasticAccountIndex.ACCOUNTS, gson.toJson(accountMapping)).execute().actionGet();
Schema<AccountGroup> groupSchema = GroupSchemaDefinitions.INSTANCE.getLatest();
GroupMapping groupMapping = new GroupMapping(groupSchema);
nodeInfo.node.client().admin().indices().prepareCreate(String.format("%s%04d", GROUPS_PREFIX, groupSchema.getVersion())).addMapping(ElasticGroupIndex.GROUPS, gson.toJson(groupMapping)).execute().actionGet();
}
Aggregations