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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user