Search in sources :

Example 1 with GetProjectPermissionsAction

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

the class PermissionManager method firePermissionsChanged.

/**
 * Fires a {@link PermissionsChangedEvent} for the
 * current project on the event bus.
 */
public void firePermissionsChanged() {
    GWT.log("[PermissionManager] Firing permissions changed");
    permittedActionCache.clear();
    final UserId userId = loggedInUserProvider.getCurrentUserId();
    final Optional<ProjectId> projectId = activeProjectManager.getActiveProjectId();
    if (!projectId.isPresent()) {
        return;
    }
    final ProjectId theProjectId = projectId.get();
    dispatchServiceManager.execute(new GetProjectPermissionsAction(projectId.get(), userId), result -> {
        UserIdProjectIdKey key = new UserIdProjectIdKey(userId, theProjectId);
        permittedActionCache.putAll(key, result.getAllowedActions());
        GWT.log("[PermissionManager] Firing permissions changed for project: " + projectId);
        eventBus.fireEventFromSource(new PermissionsChangedEvent(theProjectId).asGWTEvent(), theProjectId);
    });
}
Also used : PermissionsChangedEvent(edu.stanford.bmir.protege.web.shared.permissions.PermissionsChangedEvent) GetProjectPermissionsAction(edu.stanford.bmir.protege.web.shared.permissions.GetProjectPermissionsAction) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) UserIdProjectIdKey(edu.stanford.bmir.protege.web.shared.user.UserIdProjectIdKey)

Example 2 with GetProjectPermissionsAction

use of edu.stanford.bmir.protege.web.shared.permissions.GetProjectPermissionsAction 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)2 UserIdProjectIdKey (edu.stanford.bmir.protege.web.shared.user.UserIdProjectIdKey)2 GetProjectPermissionsResult (edu.stanford.bmir.protege.web.shared.permissions.GetProjectPermissionsResult)1 PermissionsChangedEvent (edu.stanford.bmir.protege.web.shared.permissions.PermissionsChangedEvent)1 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1