From 42488810727a403e5ee533b1660bf7dc30a28143 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Fri, 20 May 2011 03:11:43 +0200 Subject: [PATCH] Add config setting to only suggest users which are in a visible group Add a new setting for the suggest section in the Gerrit configuration that limits the suggested users to those which are in at least one group that is visible to the current user. Change-Id: I89654bfdf63e2b780c5e0c93ee54b14afc1640a0 Signed-off-by: Edwin Kempin --- Documentation/config-gerrit.txt | 3 +++ .../gerrit/httpd/rpc/SuggestAccountsEnum.java | 1 + .../gerrit/httpd/rpc/SuggestServiceImpl.java | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index 09b3f50686..2e8d5a4ca1 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt @@ -1779,6 +1779,9 @@ or a user to a group. If `SAME_GROUP`, only users who are also members of a group the current user is a member of will be offered. + +If `VISIBLE_GROUP`, only users who are members of at least one group +that is visible to the current user will be offered. ++ If `OFF`, no account suggestions are given. + Default is `ALL`. diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestAccountsEnum.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestAccountsEnum.java index 0cd21ef2f3..2ef2d44e55 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestAccountsEnum.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestAccountsEnum.java @@ -17,5 +17,6 @@ package com.google.gerrit.httpd.rpc; public enum SuggestAccountsEnum { ALL, SAME_GROUP, + VISIBLE_GROUP, OFF; } diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java index 48176b4a74..379fee6921 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java @@ -165,6 +165,22 @@ class SuggestServiceImpl extends BaseServiceImplementation implements } break; } + case VISIBLE_GROUP: { + Set usersGroups = groupsOf(account); + usersGroups.removeAll(authConfig.getRegisteredGroups()); + usersGroups.remove(authConfig.getBatchUsersGroup()); + for (AccountGroup.Id usersGroup : usersGroups) { + try { + if (groupControlFactory.controlFor(usersGroup).isVisible()) { + map.put(account.getId(), info); + break; + } + } catch (NoSuchGroupException e) { + continue; + } + } + break; + } case OFF: break; default: