use of io.lumeer.api.model.QueryStem in project engine by Lumeer.
the class ViewFacadeIT method testCollectionAccessViaView.
@Test
public void testCollectionAccessViaView() {
// non-existing user
final String NON_EXISTING_USER = "aaaaa4444400000000111111";
final String COLLECTION_NAME = "kolekce1";
final String COLLECTION_ICON = "fa-eye";
final String COLLECTION_COLOR = "#abcdea";
setOrganizationUserRoles(Set.of(new Role(RoleType.Read), new Role(RoleType.UserConfig)));
setProjectUserRoles(Set.of(new Role(RoleType.Read), new Role(RoleType.ViewContribute), new Role(RoleType.CollectionContribute), new Role(RoleType.UserConfig)));
Permission workspacePermission = Permission.buildWithRoles(NON_EXISTING_USER, Set.of(new Role(RoleType.Read)));
organizationFacade.updateUserPermissions(organization.getId(), Set.of(workspacePermission));
projectFacade.updateUserPermissions(project.getId(), Set.of(workspacePermission));
// create collection under a different user
Permissions collectionPermissions = new Permissions();
Permission userPermission = Permission.buildWithRoles(NON_EXISTING_USER, Collection.ROLES);
collectionPermissions.updateUserPermissions(userPermission);
Collection collection = collectionFacade.createCollection(new Collection("", COLLECTION_NAME, COLLECTION_ICON, COLLECTION_COLOR, collectionPermissions));
collectionFacade.updateUserPermissions(collection.getId(), Set.of(Permission.buildWithRoles(this.user.getId(), Collections.emptySet())));
removeOrganizationManagePermission();
removeProjectManagePermission();
// we are not able to read the collection now
try {
collectionFacade.getCollection(collection.getId());
fail("Still able to access collection where I have no access rights");
} catch (Exception e) {
assertThat(e).isInstanceOf(NoResourcePermissionException.class);
}
// create a view under a different user
View view = createView(CODE2);
view.setAuthorId(NON_EXISTING_USER);
view.setQuery(new Query(new QueryStem(collection.getId())));
Permissions permissions = new Permissions();
permissions.updateUserPermissions(Set.of(Permission.buildWithRoles(NON_EXISTING_USER, View.ROLES), Permission.buildWithRoles(this.user.getId(), Collections.emptySet())));
view.setPermissions(permissions);
viewDao.updateView(view.getId(), view);
try {
viewFacade.getViewById(view.getId());
fail("Still able to access view where I have no access rights");
} catch (Exception e) {
assertThat(e).isInstanceOf(NoResourcePermissionException.class);
}
try {
viewFacade.updateUserPermissions(view.getId(), Set.of(Permission.buildWithRoles(this.user.getId(), Set.of(new Role(RoleType.Read)))));
fail("Can manage view without manage rights");
} catch (Exception e) {
assertThat(e).isInstanceOf(NoResourcePermissionException.class);
}
// share the view and make sure we can see it now
Permissions viewPermissions = new Permissions();
viewPermissions.updateUserPermissions(Permission.buildWithRoles(NON_EXISTING_USER, View.ROLES));
viewPermissions.updateUserPermissions(Permission.buildWithRoles(this.user.getId(), Collections.singleton(new Role(RoleType.Read))));
view.setPermissions(viewPermissions);
// since we lost manage rights, we can only do it directly
viewDao.updateView(view.getId(), view);
// now this should be all possible
viewFacade.getViewById(view.getId());
// access the collection via the view with the current user
PermissionCheckerUtil.setViewId(permissionsChecker, view.getId());
collectionFacade.getCollection(collection.getId());
}
use of io.lumeer.api.model.QueryStem in project engine by Lumeer.
the class SearchFacade method modifyQueryForTasks.
private Query modifyQueryForTasks(boolean isPublic, final Query query, final List<Collection> collections) {
if (isPublic || !query.isEmpty()) {
return query;
}
final List<QueryStem> stems = collections.stream().map(collection -> {
final String assigneeAttributeId = collection.getPurpose().getAssigneeAttributeId();
final Attribute assigneeAttribute = ResourceUtils.findAttribute(collection.getAttributes(), assigneeAttributeId);
if (assigneeAttribute != null) {
final CollectionAttributeFilter filter = CollectionAttributeFilter.createFromTypes(collection.getId(), assigneeAttribute.getId(), ConditionType.HAS_SOME, ConditionValueType.CURRENT_USER.getValue());
return new QueryStem(null, collection.getId(), Collections.emptyList(), Collections.emptySet(), Collections.singletonList(filter), Collections.emptyList());
}
if (permissionsChecker.hasAnyRole(collection, Set.of(RoleType.DataRead, RoleType.DataContribute))) {
return new QueryStem(null, collection.getId(), Collections.emptyList(), Collections.emptySet(), Collections.emptyList(), Collections.emptyList());
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
return stems.isEmpty() ? null : new Query(stems);
}
use of io.lumeer.api.model.QueryStem in project engine by Lumeer.
the class UserNotificationFacade method getResourceDescription.
private DataDocument getResourceDescription(final Resource resource) {
final DataDocument data = new DataDocument();
if (resource.getType() == ResourceType.ORGANIZATION) {
appendOrganization((Organization) resource, data);
} else if (resource.getType() == ResourceType.PROJECT) {
appendOrganization(getOrganization(), data);
appendProject((Project) resource, data);
} else if (resource.getType() == ResourceType.COLLECTION) {
appendOrganization(getOrganization(), data);
appendProject(getProject(), data);
data.append(UserNotification.CollectionShared.COLLECTION_ID, resource.getId());
data.append(UserNotification.CollectionShared.COLLECTION_NAME, resource.getName());
data.append(UserNotification.CollectionShared.COLLECTION_ICON, resource.getIcon());
data.append(UserNotification.CollectionShared.COLLECTION_COLOR, resource.getColor());
final String query = new Query(List.of(new QueryStem(resource.getId())), null, null, null).toQueryString();
data.append(UserNotification.CollectionShared.COLLECTION_QUERY, Utils.encodeQueryParam(query));
} else if (resource.getType() == ResourceType.VIEW) {
appendOrganization(getOrganization(), data);
appendProject(getProject(), data);
data.append(UserNotification.ViewShared.VIEW_CODE, resource.getCode());
data.append(UserNotification.ViewShared.VIEW_ICON, resource.getIcon());
data.append(UserNotification.ViewShared.VIEW_COLOR, resource.getColor());
data.append(UserNotification.ViewShared.VIEW_PERSPECTIVE, ((View) resource).getPerspective());
data.append(UserNotification.ViewShared.VIEW_NAME, resource.getName());
}
return data;
}
use of io.lumeer.api.model.QueryStem in project engine by Lumeer.
the class ViewCreator method translateQuery.
private Query translateQuery(final Query query) {
var newStems = new ArrayList<QueryStem>();
query.getStems().forEach(stem -> {
var collectionId = stem.getCollectionId() != null ? templateParser.getDict().getCollectionId(stem.getCollectionId()) : null;
List<String> linkTypeIds = new ArrayList<>();
var linkTypeIdsUsed = false;
if (stem.getLinkTypeIds() != null) {
linkTypeIdsUsed = true;
stem.getLinkTypeIds().forEach(linkTypeId -> linkTypeIds.add(templateParser.getDict().getLinkTypeId(linkTypeId)));
}
Set<String> documentIds = new HashSet<>();
var documentIdsUsed = false;
if (stem.getDocumentIds() != null) {
documentIdsUsed = true;
stem.getDocumentIds().forEach(documentId -> documentIds.add(templateParser.getDict().getDocumentId(documentId)));
}
List<CollectionAttributeFilter> collectionAttributeFilters = new ArrayList<>();
var filtersUsed = false;
if (stem.getFilters() != null) {
filtersUsed = true;
stem.getFilters().forEach(filter -> collectionAttributeFilters.add(new CollectionAttributeFilter(templateParser.getDict().getCollectionId(filter.getCollectionId()), filter.getAttributeId(), filter.getCondition(), filter.getConditionValues())));
}
List<LinkAttributeFilter> linkAttributeFilters = new ArrayList<>();
var linkFiltersUsed = false;
if (stem.getCollectionId() != null) {
linkFiltersUsed = true;
stem.getLinkFilters().forEach(filter -> linkAttributeFilters.add(new LinkAttributeFilter(templateParser.getDict().getLinkTypeId(filter.getLinkTypeId()), filter.getAttributeId(), filter.getCondition(), filter.getConditionValues())));
}
newStems.add(new QueryStem(null, collectionId, linkTypeIdsUsed ? linkTypeIds : null, documentIdsUsed ? documentIds : null, filtersUsed ? collectionAttributeFilters : null, linkFiltersUsed ? linkAttributeFilters : null));
});
return new Query(newStems, query.getFulltexts(), query.getPage(), query.getPageSize());
}
use of io.lumeer.api.model.QueryStem in project engine by Lumeer.
the class ZapierFacade method updateDocument.
public List<DataDocument> updateDocument(final String collectionId, final String key, final Map<String, Object> data) {
final List<DataDocument> results = new ArrayList<>();
final Collection collection = collectionFacade.getCollection(collectionId);
List<Document> documents;
if (key.equals("_id")) {
if (data != null && data.containsKey("_id")) {
documents = List.of(documentFacade.getDocument(collectionId, data.get("_id").toString()));
} else {
return List.of();
}
} else {
documents = searchFacade.searchDocuments(new Query(new QueryStem(null, collectionId, null, null, Collections.singletonList(CollectionAttributeFilter.createFromValues(collectionId, key, ConditionType.EQUALS, data.get(key))), null)), true);
}
documents.forEach(document -> {
results.add(translateAttributes(collection, addMissingAttributes(documentFacade.patchDocumentData(collectionId, document.getId(), new DataDocument(data)).getData(), collection)));
});
return results;
}
Aggregations