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;
}
}
Aggregations