Search in sources :

Example 1 with ConceptElement

use of com.bakdata.conquery.models.datasets.concepts.ConceptElement in project conquery by bakdata.

the class ManagedExecution method setAdditionalFieldsForStatusWithSource.

/**
 * Sets additional fields of an {@link ExecutionStatus} when a more specific status is requested.
 */
protected void setAdditionalFieldsForStatusWithSource(Subject subject, FullExecutionStatus status) {
    QueryDescription query = getSubmitted();
    NamespacedIdentifiableCollector namespacesIdCollector = new NamespacedIdentifiableCollector();
    query.visit(namespacesIdCollector);
    final Set<Concept> concepts = namespacesIdCollector.getIdentifiables().stream().filter(ConceptElement.class::isInstance).map(ConceptElement.class::cast).map(ConceptElement::getConcept).collect(Collectors.toSet());
    boolean canExpand = subject.isPermittedAll(concepts, Ability.READ);
    status.setCanExpand(canExpand);
    status.setQuery(canExpand ? getSubmitted() : null);
}
Also used : Concept(com.bakdata.conquery.models.datasets.concepts.Concept) NamespacedIdentifiableCollector(com.bakdata.conquery.util.QueryUtils.NamespacedIdentifiableCollector) ConceptElement(com.bakdata.conquery.models.datasets.concepts.ConceptElement) QueryDescription(com.bakdata.conquery.apiv1.query.QueryDescription)

Example 2 with ConceptElement

use of com.bakdata.conquery.models.datasets.concepts.ConceptElement in project conquery by bakdata.

the class QueryDescription method authorize.

/**
 * Check implementation specific permissions. Is called after all visitors have been registered and executed.
 */
default void authorize(Subject subject, Dataset submittedDataset, @NonNull ClassToInstanceMap<QueryVisitor> visitors) {
    NamespacedIdentifiableCollector nsIdCollector = QueryUtils.getVisitor(visitors, NamespacedIdentifiableCollector.class);
    ExternalIdChecker externalIdChecker = QueryUtils.getVisitor(visitors, QueryUtils.ExternalIdChecker.class);
    if (nsIdCollector == null) {
        throw new IllegalStateException();
    }
    // Generate DatasetPermissions
    final Set<Dataset> datasets = nsIdCollector.getIdentifiables().stream().map(NamespacedIdentifiable::getDataset).collect(Collectors.toSet());
    subject.authorize(datasets, Ability.READ);
    // Generate ConceptPermissions
    final Set<Concept> concepts = nsIdCollector.getIdentifiables().stream().filter(ConceptElement.class::isInstance).map(ConceptElement.class::cast).map(ConceptElement::getConcept).collect(Collectors.toSet());
    subject.authorize(concepts, Ability.READ);
    subject.authorize(collectRequiredQueries(), Ability.READ);
    // Check if the query contains parts that require to resolve external IDs. If so the subject must have the preserve_id permission on the dataset.
    if (externalIdChecker.resolvesExternalIds()) {
        subject.authorize(submittedDataset, Ability.PRESERVE_ID);
    }
}
Also used : Concept(com.bakdata.conquery.models.datasets.concepts.Concept) NamespacedIdentifiableCollector(com.bakdata.conquery.util.QueryUtils.NamespacedIdentifiableCollector) ConceptElement(com.bakdata.conquery.models.datasets.concepts.ConceptElement) QueryUtils(com.bakdata.conquery.util.QueryUtils) Dataset(com.bakdata.conquery.models.datasets.Dataset) ExternalIdChecker(com.bakdata.conquery.util.QueryUtils.ExternalIdChecker)

Aggregations

Concept (com.bakdata.conquery.models.datasets.concepts.Concept)2 ConceptElement (com.bakdata.conquery.models.datasets.concepts.ConceptElement)2 NamespacedIdentifiableCollector (com.bakdata.conquery.util.QueryUtils.NamespacedIdentifiableCollector)2 QueryDescription (com.bakdata.conquery.apiv1.query.QueryDescription)1 Dataset (com.bakdata.conquery.models.datasets.Dataset)1 QueryUtils (com.bakdata.conquery.util.QueryUtils)1 ExternalIdChecker (com.bakdata.conquery.util.QueryUtils.ExternalIdChecker)1