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