Search in sources :

Example 1 with RoleType

use of io.lumeer.api.model.RoleType in project engine by Lumeer.

the class PermissionsCheckerTest method testGetActualRolesUserOnly.

@Test
public void testGetActualRolesUserOnly() {
    Resource resource = prepareResource(Sets.newLinkedHashSet(new Role(RoleType.Read), new Role(RoleType.DataWrite)), Collections.emptySet());
    Set<RoleType> roles = permissionsChecker.getActualRoles(resource);
    assertThat(roles).containsOnly(RoleType.Read, RoleType.DataWrite);
}
Also used : Role(io.lumeer.api.model.Role) RoleType(io.lumeer.api.model.RoleType) Resource(io.lumeer.api.model.common.Resource) Test(org.junit.Test)

Example 2 with RoleType

use of io.lumeer.api.model.RoleType in project engine by Lumeer.

the class CollectionFacade method createCollectionAttributesWithoutPushNotification.

public java.util.Collection<Attribute> createCollectionAttributesWithoutPushNotification(final String collectionId, final java.util.Collection<Attribute> attributes) {
    final Collection collection = collectionDao.getCollectionById(collectionId);
    final Collection originalCollection = collection.copy();
    permissionsChecker.checkRole(collection, RoleType.AttributeEdit);
    permissionsChecker.checkAttributesFunctionAccess(attributes);
    final Set<RoleType> actualRoles = permissionsChecker.getActualRoles(collection);
    var sortedAttributes = attributes.stream().sorted((a, b) -> a.getId().compareToIgnoreCase(b.getId())).collect(Collectors.toList());
    for (Attribute attribute : sortedAttributes) {
        attribute.patchCreation(actualRoles);
        collection.createAttribute(attribute);
    }
    permissionsChecker.checkFunctionsLimit(collection);
    collection.setLastTimeUsed(ZonedDateTime.now());
    collectionDao.updateCollection(collection.getId(), collection, originalCollection, false);
    return attributes;
}
Also used : TaskExecutor(io.lumeer.core.task.TaskExecutor) CollectionUtil(io.lumeer.api.util.CollectionUtil) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) LinkTypeDao(io.lumeer.storage.api.dao.LinkTypeDao) AutoLinkRule(io.lumeer.api.model.rule.AutoLinkRule) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) ResourceType(io.lumeer.api.model.ResourceType) DefaultViewConfigDao(io.lumeer.storage.api.dao.DefaultViewConfigDao) Map(java.util.Map) ResourceCommentDao(io.lumeer.storage.api.dao.ResourceCommentDao) CollectionAdapter(io.lumeer.core.adapter.CollectionAdapter) Permission(io.lumeer.api.model.Permission) RoleType(io.lumeer.api.model.RoleType) View(io.lumeer.api.model.View) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Document(io.lumeer.api.model.Document) Set(java.util.Set) NoResourcePermissionException(io.lumeer.core.exception.NoResourcePermissionException) Collectors(java.util.stream.Collectors) LinkType(io.lumeer.api.model.LinkType) Objects(java.util.Objects) AttributesResource(io.lumeer.api.model.common.AttributesResource) List(java.util.List) ResourceUtils(io.lumeer.api.util.ResourceUtils) PostConstruct(javax.annotation.PostConstruct) FavoriteItemDao(io.lumeer.storage.api.dao.FavoriteItemDao) Attribute(io.lumeer.api.model.Attribute) ContextualTaskFactory(io.lumeer.core.task.ContextualTaskFactory) UserDao(io.lumeer.storage.api.dao.UserDao) HashMap(java.util.HashMap) SelectionListDao(io.lumeer.storage.api.dao.SelectionListDao) AllowedPermissions(io.lumeer.api.model.AllowedPermissions) Function(java.util.function.Function) CollectionPurpose(io.lumeer.api.model.CollectionPurpose) GroupDao(io.lumeer.storage.api.dao.GroupDao) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) DataDao(io.lumeer.storage.api.dao.DataDao) ViewDao(io.lumeer.storage.api.dao.ViewDao) CodeGenerator(io.lumeer.core.util.CodeGenerator) Rule(io.lumeer.api.model.Rule) DocumentDao(io.lumeer.storage.api.dao.DocumentDao) Permissions(io.lumeer.api.model.Permissions) ResourceAdapter(io.lumeer.core.adapter.ResourceAdapter) DocumentUtils(io.lumeer.core.util.DocumentUtils) FileAttachment(io.lumeer.api.model.FileAttachment) Project(io.lumeer.api.model.Project) LinkInstanceDao(io.lumeer.storage.api.dao.LinkInstanceDao) UnsuccessfulOperationException(io.lumeer.engine.api.exception.UnsuccessfulOperationException) ConversionFacade(io.lumeer.core.facade.conversion.ConversionFacade) RuleTask(io.lumeer.core.task.RuleTask) RequestScoped(javax.enterprise.context.RequestScoped) CronRule(io.lumeer.api.model.rule.CronRule) AutoLinkBatchTask(io.lumeer.core.task.AutoLinkBatchTask) Collection(io.lumeer.api.model.Collection) Attribute(io.lumeer.api.model.Attribute) RoleType(io.lumeer.api.model.RoleType) Collection(io.lumeer.api.model.Collection)

Example 3 with RoleType

use of io.lumeer.api.model.RoleType in project engine by Lumeer.

the class CollectionFacade method createCollectionAttributes.

public java.util.Collection<Attribute> createCollectionAttributes(final Collection collection, final java.util.Collection<Attribute> attributes) {
    permissionsChecker.checkRole(collection, RoleType.AttributeEdit);
    permissionsChecker.checkAttributesFunctionAccess(attributes);
    final Collection bookedAttributesCollection = collectionDao.bookAttributesNum(collection.getId(), collection, attributes.size());
    int lastAttributeNum = bookedAttributesCollection.getLastAttributeNum() - attributes.size() + 1;
    final Set<RoleType> actualRoles = permissionsChecker.getActualRoles(collection);
    for (Attribute attribute : attributes) {
        attribute.setId(AttributesResource.ATTRIBUTE_PREFIX + lastAttributeNum++);
        attribute.patchCreation(actualRoles);
        bookedAttributesCollection.createAttribute(attribute);
    }
    mapResourceUpdateValues(bookedAttributesCollection);
    permissionsChecker.checkFunctionsLimit(collection);
    bookedAttributesCollection.setLastTimeUsed(ZonedDateTime.now());
    collectionDao.updateCollection(collection.getId(), bookedAttributesCollection, collection);
    return attributes;
}
Also used : Attribute(io.lumeer.api.model.Attribute) RoleType(io.lumeer.api.model.RoleType) Collection(io.lumeer.api.model.Collection)

Example 4 with RoleType

use of io.lumeer.api.model.RoleType in project engine by Lumeer.

the class PermissionsChecker method getCollectionPermissions.

public AllowedPermissions getCollectionPermissions(final Collection collection) {
    User user = authenticatedUser.getCurrentUser();
    Set<RoleType> roles = permissionAdapter.getUserRolesInResource(getOrganization(), getProject(), collection, user);
    Set<RoleType> rolesWithView = new HashSet<>(permissionAdapter.getUserRolesInCollectionWithView(getOrganization(), getProject(), collection, user));
    rolesWithView.addAll(roles);
    return new AllowedPermissions(roles, rolesWithView);
}
Also used : AllowedPermissions(io.lumeer.api.model.AllowedPermissions) User(io.lumeer.api.model.User) RoleType(io.lumeer.api.model.RoleType) HashSet(java.util.HashSet)

Example 5 with RoleType

use of io.lumeer.api.model.RoleType in project engine by Lumeer.

the class PermissionsChecker method getLinkTypePermissions.

public AllowedPermissions getLinkTypePermissions(final LinkType linkType) {
    User user = authenticatedUser.getCurrentUser();
    Set<RoleType> roles = permissionAdapter.getUserRolesInLinkType(getOrganization(), getProject(), linkType, user);
    Set<RoleType> rolesWithView = new HashSet<>(permissionAdapter.getUserRolesInLinkTypeWithView(getOrganization(), getProject(), linkType, user));
    rolesWithView.addAll(roles);
    return new AllowedPermissions(roles, rolesWithView);
}
Also used : AllowedPermissions(io.lumeer.api.model.AllowedPermissions) User(io.lumeer.api.model.User) RoleType(io.lumeer.api.model.RoleType) HashSet(java.util.HashSet)

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