Search in sources :

Example 6 with RoleType

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;
    }
}
Also used : AllowedPermissions(io.lumeer.api.model.AllowedPermissions) SelectedWorkspace(io.lumeer.api.SelectedWorkspace) Arrays(java.util.Arrays) TaskExecutor(io.lumeer.core.task.TaskExecutor) PrintTextOperation(io.lumeer.core.task.executor.operation.PrintTextOperation) CollectionUtil(io.lumeer.api.util.CollectionUtil) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) FileAttachmentData(io.lumeer.core.task.executor.operation.data.FileAttachmentData) Operation(io.lumeer.core.task.executor.operation.Operation) TextPrintRequest(io.lumeer.core.task.executor.request.TextPrintRequest) StringUtils(org.apache.commons.lang3.StringUtils) UserMessageOperation(io.lumeer.core.task.executor.operation.UserMessageOperation) BigDecimal(java.math.BigDecimal) SmtpConfigurationBuilder(io.lumeer.core.task.executor.request.SmtpConfigurationBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceType(io.lumeer.api.model.ResourceType) Map(java.util.Map) AddLinkFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddLinkFileAttachmentOperation) Collectors.toSet(java.util.stream.Collectors.toSet) ConstraintManager(io.lumeer.core.constraint.ConstraintManager) DocumentOperation(io.lumeer.core.task.executor.operation.DocumentOperation) RoleType(io.lumeer.api.model.RoleType) View(io.lumeer.api.model.View) ViewPermissionsOperation(io.lumeer.core.task.executor.operation.ViewPermissionsOperation) DataDocument(io.lumeer.engine.api.data.DataDocument) Value(org.graalvm.polyglot.Value) DummySequenceOperation(io.lumeer.core.task.executor.operation.DummySequenceOperation) Document(io.lumeer.api.model.Document) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) LinkInstance(io.lumeer.api.model.LinkInstance) StandardCharsets(java.nio.charset.StandardCharsets) LinkType(io.lumeer.api.model.LinkType) Group(io.lumeer.api.model.Group) DefaultConfigurationProducer(io.lumeer.core.facade.configuration.DefaultConfigurationProducer) PrintAttributeOperation(io.lumeer.core.task.executor.operation.PrintAttributeOperation) SendSmtpEmailRequest(io.lumeer.core.task.executor.request.SendSmtpEmailRequest) List(java.util.List) SendEmailOperation(io.lumeer.core.task.executor.operation.SendEmailOperation) EmailSecurityType(io.lumeer.core.util.EmailSecurityType) Optional(java.util.Optional) Attribute(io.lumeer.api.model.Attribute) WithId(io.lumeer.api.model.common.WithId) SendSmtpEmailOperation(io.lumeer.core.task.executor.operation.SendSmtpEmailOperation) ChangesTracker(io.lumeer.core.task.executor.ChangesTracker) LongAdder(java.util.concurrent.atomic.LongAdder) LinkOperation(io.lumeer.core.task.executor.operation.LinkOperation) Engine(com.floreysoft.jmte.Engine) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocumentCreationOperation(io.lumeer.core.task.executor.operation.DocumentCreationOperation) SendEmailRequest(io.lumeer.core.task.executor.request.SendEmailRequest) HashMap(java.util.HashMap) AllowedPermissions(io.lumeer.api.model.AllowedPermissions) ArrayList(java.util.ArrayList) NavigationOperation(io.lumeer.core.task.executor.operation.NavigationOperation) SearchQueryStem(io.lumeer.storage.api.query.SearchQueryStem) HashSet(java.util.HashSet) Language(io.lumeer.api.model.Language) LinkCreationOperation(io.lumeer.core.task.executor.operation.LinkCreationOperation) PrintRequest(io.lumeer.core.task.executor.request.PrintRequest) DocumentRemovalOperation(io.lumeer.core.task.executor.operation.DocumentRemovalOperation) Query(io.lumeer.api.model.Query) ResourceOperation(io.lumeer.core.task.executor.operation.ResourceOperation) ContextualTask(io.lumeer.core.task.ContextualTask) LinkTypeUtil(io.lumeer.api.util.LinkTypeUtil) Task(io.lumeer.core.task.Task) PermissionUtils(io.lumeer.api.util.PermissionUtils) IOException(java.io.IOException) UserMessageRequest(io.lumeer.core.task.executor.request.UserMessageRequest) NavigationRequest(io.lumeer.core.task.executor.request.NavigationRequest) SmtpConfiguration(io.lumeer.core.task.executor.request.SmtpConfiguration) SearchQuery(io.lumeer.storage.api.query.SearchQuery) AddDocumentFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddDocumentFileAttachmentOperation) DocumentUtils(io.lumeer.core.util.DocumentUtils) FileAttachment(io.lumeer.api.model.FileAttachment) Collectors.toList(java.util.stream.Collectors.toList) ResourceVariable(io.lumeer.api.model.ResourceVariable) PdfCreator(io.lumeer.core.pdf.PdfCreator) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Query(io.lumeer.api.model.Query) SearchQuery(io.lumeer.storage.api.query.SearchQuery) Language(io.lumeer.api.model.Language) RoleType(io.lumeer.api.model.RoleType) DocumentRemovalOperation(io.lumeer.core.task.executor.operation.DocumentRemovalOperation) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) View(io.lumeer.api.model.View) IOException(java.io.IOException)

Example 7 with RoleType

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

Example 8 with RoleType

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;
    }
}
Also used : AllowedPermissions(io.lumeer.api.model.AllowedPermissions) Query(io.lumeer.api.model.Query) SearchQuery(io.lumeer.storage.api.query.SearchQuery) Language(io.lumeer.api.model.Language) RoleType(io.lumeer.api.model.RoleType) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) View(io.lumeer.api.model.View) IOException(java.io.IOException)

Example 9 with RoleType

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);
}
Also used : AllowedPermissions(io.lumeer.api.model.AllowedPermissions) RoleType(io.lumeer.api.model.RoleType)

Example 10 with RoleType

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();
}
Also used : RoleType(io.lumeer.api.model.RoleType) Resource(io.lumeer.api.model.common.Resource) Test(org.junit.Test)

Aggregations

RoleType (io.lumeer.api.model.RoleType)14 AllowedPermissions (io.lumeer.api.model.AllowedPermissions)6 User (io.lumeer.api.model.User)6 Role (io.lumeer.api.model.Role)5 Resource (io.lumeer.api.model.common.Resource)5 Collection (io.lumeer.api.model.Collection)4 View (io.lumeer.api.model.View)4 HashSet (java.util.HashSet)4 Attribute (io.lumeer.api.model.Attribute)3 Document (io.lumeer.api.model.Document)3 LinkType (io.lumeer.api.model.LinkType)3 ResourceType (io.lumeer.api.model.ResourceType)3 IOException (java.io.IOException)3 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Test (org.junit.Test)3 SelectedWorkspace (io.lumeer.api.SelectedWorkspace)2 FileAttachment (io.lumeer.api.model.FileAttachment)2 Group (io.lumeer.api.model.Group)2