Search in sources :

Example 1 with GetProjectPermissionsResult

use of edu.stanford.bmir.protege.web.shared.permissions.GetProjectPermissionsResult in project webprotege by protegeproject.

the class PermissionManager method hasPermissionForProject.

/**
 * Determines if the specified user has permission to execute the specified action on the
 * specified project.
 * @param userId The {@link UserId} to test for.
 * @param actionId The {@link ActionId} to test for.
 * @param projectId The {@link ProjectId} to test for.
 * @param callback A callback for receiving the result.
 */
public void hasPermissionForProject(@Nonnull UserId userId, @Nonnull ActionId actionId, @Nonnull ProjectId projectId, @Nonnull DispatchServiceCallback<Boolean> callback) {
    final UserIdProjectIdKey key = new UserIdProjectIdKey(userId, projectId);
    if (permittedActionCache.containsKey(key)) {
        callback.onSuccess(permittedActionCache.get(key).contains(actionId));
        return;
    }
    dispatchServiceManager.execute(new GetProjectPermissionsAction(projectId, userId), new DispatchServiceCallback<GetProjectPermissionsResult>() {

        @Override
        public void handleSuccess(GetProjectPermissionsResult result) {
            permittedActionCache.putAll(key, result.getAllowedActions());
            callback.onSuccess(result.getAllowedActions().contains(actionId));
        }

        @Override
        public void handleErrorFinally(Throwable throwable) {
            callback.handleErrorFinally(throwable);
        }
    });
}
Also used : GetProjectPermissionsAction(edu.stanford.bmir.protege.web.shared.permissions.GetProjectPermissionsAction) GetProjectPermissionsResult(edu.stanford.bmir.protege.web.shared.permissions.GetProjectPermissionsResult) UserIdProjectIdKey(edu.stanford.bmir.protege.web.shared.user.UserIdProjectIdKey)

Aggregations

GetProjectPermissionsAction (edu.stanford.bmir.protege.web.shared.permissions.GetProjectPermissionsAction)1 GetProjectPermissionsResult (edu.stanford.bmir.protege.web.shared.permissions.GetProjectPermissionsResult)1 UserIdProjectIdKey (edu.stanford.bmir.protege.web.shared.user.UserIdProjectIdKey)1