Search in sources :

Example 1 with ViewPermissionsOperation

use of io.lumeer.core.task.executor.operation.ViewPermissionsOperation in project engine by Lumeer.

the class LumeerBridge method shareView.

@SuppressWarnings("unused")
public void shareView(final String viewId, final String userEmail, final String roles) {
    try {
        final SelectedWorkspace workspace = task.getDaoContextSnapshot().getSelectedWorkspace();
        if (workspace.getOrganization().isPresent() && workspace.getProject().isPresent()) {
            final View view = task.getDaoContextSnapshot().getViewDao().getViewById(viewId);
            if (view != null) {
                // can the initiator share the view?
                if (PermissionUtils.hasRole(workspace.getOrganization().get(), workspace.getProject().get(), view, RoleType.UserConfig, task.getInitiator(), task.getGroups())) {
                    final User newUser = task.getDaoContextSnapshot().getUserDao().getUserByEmail(userEmail);
                    final Set<RoleType> userRoles = StringUtils.isNotEmpty(roles) && !"none".equals(roles) ? Arrays.stream(roles.split(",")).map(RoleType::fromString).collect(toSet()) : Set.of();
                    operations.add(new ViewPermissionsOperation(view, newUser.getId(), userRoles));
                }
            }
        }
    } catch (Exception e) {
        cause = e;
        throw e;
    }
}
Also used : ViewPermissionsOperation(io.lumeer.core.task.executor.operation.ViewPermissionsOperation) User(io.lumeer.api.model.User) RoleType(io.lumeer.api.model.RoleType) SelectedWorkspace(io.lumeer.api.SelectedWorkspace) View(io.lumeer.api.model.View) IOException(java.io.IOException)

Aggregations

SelectedWorkspace (io.lumeer.api.SelectedWorkspace)1 RoleType (io.lumeer.api.model.RoleType)1 User (io.lumeer.api.model.User)1 View (io.lumeer.api.model.View)1 ViewPermissionsOperation (io.lumeer.core.task.executor.operation.ViewPermissionsOperation)1 IOException (java.io.IOException)1