Search in sources :

Example 11 with RoleType

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

the class PermissionsCheckerTest method testGetActualRolesIntersection.

@Test
public void testGetActualRolesIntersection() {
    Resource resource = prepareResource(Sets.newLinkedHashSet(new Role(RoleType.Read), new Role(RoleType.DataWrite)), Sets.newLinkedHashSet(new Role(RoleType.UserConfig), new Role(RoleType.PerspectiveConfig)));
    Set<RoleType> roles = permissionsChecker.getActualRoles(resource);
    assertThat(roles).containsOnly(RoleType.Read, RoleType.DataWrite, RoleType.UserConfig, RoleType.PerspectiveConfig);
}
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 12 with RoleType

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

the class PermissionsCheckerTest method testGetActualRolesGroupOnly.

@Test
public void testGetActualRolesGroupOnly() {
    Resource resource = prepareResource(Collections.emptySet(), Sets.newLinkedHashSet(new Role(RoleType.Read), new Role(RoleType.UserConfig)));
    Set<RoleType> roles = permissionsChecker.getActualRoles(resource);
    assertThat(roles).containsOnly(RoleType.Read, RoleType.UserConfig);
}
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 13 with RoleType

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

the class PermissionUtils method getUserRolesInLinkType.

public static Set<RoleType> getUserRolesInLinkType(Organization organization, @Nullable Project project, LinkType linkType, java.util.Collection<Collection> collections, User user, List<Group> groups) {
    if (linkType.getPermissionsType() == LinkPermissionsType.Custom) {
        return getUserRolesInResource(organization, project, ResourceType.LINK_TYPE, linkType.getPermissions(), user, getUserGroups(organization, user, groups));
    }
    var linkTypeCollections = collections.stream().filter(collection -> linkType.getCollectionIds().contains(collection.getId())).collect(Collectors.toList());
    var canReadCollections = linkTypeCollections.size() == 2;
    for (Collection collection : linkTypeCollections) {
        canReadCollections = canReadCollections && hasRole(organization, project, collection, RoleType.Read, user, groups);
    }
    if (!canReadCollections) {
        return Collections.emptySet();
    }
    var roles1 = getUserRolesInResource(organization, project, linkTypeCollections.get(0), user, groups);
    var roles2 = getUserRolesInResource(organization, project, linkTypeCollections.get(1), user, groups);
    roles1.retainAll(roles2);
    return roles1;
}
Also used : Permission(io.lumeer.api.model.Permission) LinkPermissionsType(io.lumeer.api.model.LinkPermissionsType) RoleType(io.lumeer.api.model.RoleType) Permissions(io.lumeer.api.model.Permissions) User(io.lumeer.api.model.User) Set(java.util.Set) Collectors(java.util.stream.Collectors) LinkType(io.lumeer.api.model.LinkType) HashSet(java.util.HashSet) Objects(java.util.Objects) Group(io.lumeer.api.model.Group) Project(io.lumeer.api.model.Project) List(java.util.List) Role(io.lumeer.api.model.Role) RolesDifference(io.lumeer.api.model.RolesDifference) ResourceType(io.lumeer.api.model.ResourceType) Resource(io.lumeer.api.model.common.Resource) Collections(java.util.Collections) Collectors.toSet(java.util.stream.Collectors.toSet) Collection(io.lumeer.api.model.Collection) Organization(io.lumeer.api.model.Organization) Nullable(javax.annotation.Nullable) Collection(io.lumeer.api.model.Collection)

Example 14 with RoleType

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

the class RoleCodec method convertFromDocument.

public static Role convertFromDocument(Document bson) {
    RoleType type = RoleType.fromString(bson.getString(TYPE));
    boolean transitive = bson.getBoolean(TRANSITIVE, false);
    return new Role(type, transitive);
}
Also used : Role(io.lumeer.api.model.Role) RoleType(io.lumeer.api.model.RoleType)

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