use of io.lumeer.api.model.RoleType in project engine by Lumeer.
the class LumeerBridge method removeDocumentsInView.
@SuppressWarnings("unused")
public void removeDocumentsInView(final String viewId) {
try {
final View view = task.getDaoContextSnapshot().getViewDao().getViewById(viewId);
final Query query = view.getQuery().getFirstStem(0, Task.MAX_VIEW_DOCUMENTS);
final Language language = Language.fromString(task.getCurrentLocale());
final Set<RoleType> roles = PermissionUtils.getUserRolesInResource(task.getDaoContextSnapshot().getOrganization(), task.getDaoContextSnapshot().getProject(), view, task.getInitiator(), task.getGroups());
final AllowedPermissions permissions = new AllowedPermissions(roles);
final List<Document> documents = DocumentUtils.getDocuments(task.getDaoContextSnapshot(), query, task.getInitiator(), language, permissions, task.getTimeZone());
documents.stream().filter(d -> task.getDaoContextSnapshot().increaseDeletionCounter() <= Task.MAX_CREATED_AND_DELETED_DOCUMENTS_AND_LINKS).forEach(d -> operations.add(new DocumentRemovalOperation(d)));
} catch (Exception e) {
cause = e;
throw e;
}
}
use of io.lumeer.api.model.RoleType 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;
}
}
use of io.lumeer.api.model.RoleType in project engine by Lumeer.
the class LumeerBridge method readView.
@SuppressWarnings("unused")
public List<DocumentBridge> readView(final String viewId) {
try {
final View view = task.getDaoContextSnapshot().getViewDao().getViewById(viewId);
final Query query = view.getQuery().getFirstStem(0, Task.MAX_VIEW_DOCUMENTS);
final Language language = Language.fromString(task.getCurrentLocale());
final Set<RoleType> roles = PermissionUtils.getUserRolesInResource(task.getDaoContextSnapshot().getOrganization(), task.getDaoContextSnapshot().getProject(), view, task.getInitiator(), task.getGroups());
final AllowedPermissions permissions = new AllowedPermissions(roles);
final List<Document> documents = DocumentUtils.getDocuments(task.getDaoContextSnapshot(), query, task.getInitiator(), language, permissions, task.getTimeZone());
return documents.stream().map(DocumentBridge::new).collect(toList());
} catch (Exception e) {
cause = e;
throw e;
}
}
use of io.lumeer.api.model.RoleType in project engine by Lumeer.
the class DocumentMatcher method initializePermissions.
private void initializePermissions() {
Set<RoleType> thisCollectionRoles = PermissionUtils.getUserRolesInResource(this.organization, this.project, this.thisCollection, this.ruleTask.getInitiator(), this.ruleTask.getGroups());
Set<RoleType> thatCollectionRoles = PermissionUtils.getUserRolesInResource(this.organization, this.project, this.thatCollection, this.ruleTask.getInitiator(), this.ruleTask.getGroups());
AllowedPermissions thisCollectionPermissions = new AllowedPermissions(thisCollectionRoles);
AllowedPermissions thatCollectionPermissions = new AllowedPermissions(thatCollectionRoles);
AllowedPermissions linkTypePermission = AllowedPermissions.merge(thisCollectionPermissions, thatCollectionPermissions);
collectionPermissions = Map.of(thisCollection.getId(), thisCollectionPermissions, thatCollection.getId(), thatCollectionPermissions);
linkTypePermissions = Map.of(linkType.getId(), linkTypePermission);
}
use of io.lumeer.api.model.RoleType in project engine by Lumeer.
the class PermissionsCheckerTest method testGetActualRolesEmpty.
@Test
public void testGetActualRolesEmpty() {
Resource resource = prepareResource(Collections.emptySet(), Collections.emptySet());
Set<RoleType> roles = permissionsChecker.getActualRoles(resource);
assertThat(roles).isEmpty();
}
Aggregations