Search in sources :

Example 6 with GlobalOrPluginPermission

use of com.google.gerrit.extensions.api.access.GlobalOrPluginPermission in project gerrit by GerritCodeReview.

the class GetCapabilities method apply.

@Override
public Object apply(AccountResource rsrc) throws AuthException, PermissionBackendException {
    PermissionBackend.WithUser perm = permissionBackend.user(self);
    if (self.get() != rsrc.getUser()) {
        perm.check(GlobalPermission.ADMINISTRATE_SERVER);
        perm = permissionBackend.user(rsrc.getUser());
    }
    Map<String, Object> have = new LinkedHashMap<>();
    for (GlobalOrPluginPermission p : perm.test(permissionsToTest())) {
        have.put(p.permissionName(), true);
    }
    addRanges(have, rsrc);
    addPriority(have, rsrc);
    return OutputFormat.JSON.newGson().toJsonTree(have, new TypeToken<Map<String, Object>>() {
    }.getType());
}
Also used : PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) TypeToken(com.google.gson.reflect.TypeToken) GlobalOrPluginPermission(com.google.gerrit.extensions.api.access.GlobalOrPluginPermission) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with GlobalOrPluginPermission

use of com.google.gerrit.extensions.api.access.GlobalOrPluginPermission in project gerrit by GerritCodeReview.

the class Capabilities method parse.

@Override
public Capability parse(AccountResource parent, IdString id) throws ResourceNotFoundException, AuthException, PermissionBackendException {
    permissionBackend.checkUsesDefaultCapabilities();
    IdentifiedUser target = parent.getUser();
    if (!self.get().hasSameAccountId(target)) {
        permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
    }
    GlobalOrPluginPermission perm = parse(id);
    if (permissionBackend.absentUser(target.getAccountId()).test(perm)) {
        return new AccountResource.Capability(target, globalOrPluginPermissionName(perm));
    }
    throw new ResourceNotFoundException(id);
}
Also used : Capability(com.google.gerrit.server.account.AccountResource.Capability) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) GlobalOrPluginPermission(com.google.gerrit.extensions.api.access.GlobalOrPluginPermission)

Aggregations

GlobalOrPluginPermission (com.google.gerrit.extensions.api.access.GlobalOrPluginPermission)7 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)4 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)3 PluginPermission (com.google.gerrit.extensions.api.access.PluginPermission)2 IdString (com.google.gerrit.extensions.restapi.IdString)2 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)2 Capability (com.google.gerrit.server.account.AccountResource.Capability)2 LinkedHashMap (java.util.LinkedHashMap)2 Nullable (com.google.gerrit.common.Nullable)1 BooleanCondition (com.google.gerrit.extensions.conditions.BooleanCondition)1 UiAction (com.google.gerrit.extensions.webui.UiAction)1 Description (com.google.gerrit.extensions.webui.UiAction.Description)1 Timer1 (com.google.gerrit.metrics.Timer1)1 AccountLimits (com.google.gerrit.server.account.AccountLimits)1 GlobalPermission (com.google.gerrit.server.permissions.GlobalPermission)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 TypeToken (com.google.gson.reflect.TypeToken)1