Support to check via REST if a group is owned by the calling user

It is now possible to list the groups that are owned by a user by
GET on '/groups/?owned&user=<user>'. If the 'user' parameter is
omitted the owned groups of the calling user are listed.

Groups can be added by the 'q' parameter to limit the result to
those groups that are of interest to the caller, e.g. if a user wants
to check if he owns group 'MyGroup' he can send this request:
  GET /groups/?owned&q=MyGroup
If the group is returned the user owns 'MyGroup'.

Change-Id: I09bc99ce0fb60a40320a26d592257408ef2d9c75
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-02-01 16:23:10 +01:00
parent 052d7391d7
commit bf75002957
7 changed files with 153 additions and 28 deletions

View File

@@ -23,9 +23,31 @@ import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
/** Access control management for a group of accounts managed in Gerrit. */
public class GroupControl {
@Singleton
public static class GenericFactory {
private final GroupBackend groupBackend;
@Inject
GenericFactory(final GroupBackend gb) {
groupBackend = gb;
}
public GroupControl controlFor(final CurrentUser who,
final AccountGroup.UUID groupId)
throws NoSuchGroupException {
final GroupDescription.Basic group = groupBackend.get(groupId);
if (group == null) {
throw new NoSuchGroupException(groupId);
}
return new GroupControl(who, group);
}
}
public static class Factory {
private final GroupCache groupCache;
private final Provider<CurrentUser> user;