Search in sources :

Example 1 with AbstractPermissions

use of org.eclipse.che.multiuser.api.permission.server.model.impl.AbstractPermissions in project che-server by eclipse-che.

the class PermissionsManager method remove.

/**
 * Removes permissions of userId related to the particular instanceId of specified domainId
 *
 * @param userId user id
 * @param domainId domain id
 * @param instanceId instance id
 * @throws NotFoundException when given domainId is unsupported
 * @throws ConflictException when removes last 'setPermissions' of given instanceId
 * @throws ServerException when any other error occurs during permissions removing
 */
public void remove(String userId, String domainId, String instanceId) throws ConflictException, ServerException, NotFoundException {
    final PermissionsDao<? extends AbstractPermissions> permissionsDao = getPermissionsDao(domainId);
    Permissions permissions;
    try (@SuppressWarnings("unused") Unlocker unlocker = updateLocks.writeLock(firstNonNull(instanceId, domainId))) {
        if (userHasLastSetPermissions(permissionsDao, userId, instanceId)) {
            throw new ConflictException("Can't remove permissions because there is not any another user " + "with permission 'setPermissions'");
        }
        permissions = permissionsDao.get(userId, instanceId);
        permissionsDao.remove(userId, instanceId);
    }
    final String initiator = EnvironmentContext.getCurrent().getSubject().getUserName();
    eventService.publish(new PermissionsRemovedEvent(initiator, permissions));
}
Also used : PermissionsRemovedEvent(org.eclipse.che.multiuser.api.permission.server.event.PermissionsRemovedEvent) ConflictException(org.eclipse.che.api.core.ConflictException) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) AbstractPermissions(org.eclipse.che.multiuser.api.permission.server.model.impl.AbstractPermissions) Permissions(org.eclipse.che.multiuser.api.permission.shared.model.Permissions)

Example 2 with AbstractPermissions

use of org.eclipse.che.multiuser.api.permission.server.model.impl.AbstractPermissions in project devspaces-images by redhat-developer.

the class PermissionsManager method remove.

/**
 * Removes permissions of userId related to the particular instanceId of specified domainId
 *
 * @param userId user id
 * @param domainId domain id
 * @param instanceId instance id
 * @throws NotFoundException when given domainId is unsupported
 * @throws ConflictException when removes last 'setPermissions' of given instanceId
 * @throws ServerException when any other error occurs during permissions removing
 */
public void remove(String userId, String domainId, String instanceId) throws ConflictException, ServerException, NotFoundException {
    final PermissionsDao<? extends AbstractPermissions> permissionsDao = getPermissionsDao(domainId);
    Permissions permissions;
    try (@SuppressWarnings("unused") Unlocker unlocker = updateLocks.writeLock(firstNonNull(instanceId, domainId))) {
        if (userHasLastSetPermissions(permissionsDao, userId, instanceId)) {
            throw new ConflictException("Can't remove permissions because there is not any another user " + "with permission 'setPermissions'");
        }
        permissions = permissionsDao.get(userId, instanceId);
        permissionsDao.remove(userId, instanceId);
    }
    final String initiator = EnvironmentContext.getCurrent().getSubject().getUserName();
    eventService.publish(new PermissionsRemovedEvent(initiator, permissions));
}
Also used : PermissionsRemovedEvent(org.eclipse.che.multiuser.api.permission.server.event.PermissionsRemovedEvent) ConflictException(org.eclipse.che.api.core.ConflictException) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) AbstractPermissions(org.eclipse.che.multiuser.api.permission.server.model.impl.AbstractPermissions) Permissions(org.eclipse.che.multiuser.api.permission.shared.model.Permissions)

Aggregations

ConflictException (org.eclipse.che.api.core.ConflictException)2 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)2 PermissionsRemovedEvent (org.eclipse.che.multiuser.api.permission.server.event.PermissionsRemovedEvent)2 AbstractPermissions (org.eclipse.che.multiuser.api.permission.server.model.impl.AbstractPermissions)2 Permissions (org.eclipse.che.multiuser.api.permission.shared.model.Permissions)2