diff --git a/README.md b/README.md index 089cdbe..ad6d58b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Tests](https://github.com/DataShades/ckanext-relationship/workflows/Tests/badge.svg)](https://github.com/DataShades/ckanext-relationship/actions/workflows/test.yml) +[![Tests](https://github.com/DataShades/ckanext-relationship/actions/workflows/test.yml/badge.svg)](https://github.com/DataShades/ckanext-relationship/actions/workflows/test.yml) # ckanext-relationship @@ -44,12 +44,10 @@ If your extension works across different versions you can add the following tabl Compatibility with core CKAN versions: -| CKAN version | Compatible? | -| --------------- | ------------- | -| 2.6 and earlier | not tested | -| 2.7 | not tested | -| 2.8 | not tested | -| 2.9 | not tested | +| CKAN version | Compatible? | +|-----------------|-------------| +| 2.9 | yes | +| 2.10 | yes | Suggested values: diff --git a/ckanext/relationship/config.py b/ckanext/relationship/config.py new file mode 100644 index 0000000..80f75f3 --- /dev/null +++ b/ckanext/relationship/config.py @@ -0,0 +1,17 @@ +from __future__ import annotations + +import ckan.plugins.toolkit as tk + +CONFIG_VIEWS_WITHOUT_RELATIONSHIPS = ( + "ckanext.relationship.views_without_relationships_in_package_show" +) +DEFAULT_VIEWS_WITHOUT_RELATIONSHIPS = ["search", "read"] + + +def views_without_relationships_in_package_show() -> list[str]: + return tk.aslist( + tk.config.get( + CONFIG_VIEWS_WITHOUT_RELATIONSHIPS, + DEFAULT_VIEWS_WITHOUT_RELATIONSHIPS, + ), + ) diff --git a/ckanext/relationship/logic/action.py b/ckanext/relationship/logic/action.py index 987115c..aeb22d3 100644 --- a/ckanext/relationship/logic/action.py +++ b/ckanext/relationship/logic/action.py @@ -1,14 +1,16 @@ from __future__ import annotations +from typing import Any + from flask import jsonify from sqlalchemy import or_ import ckan.plugins.toolkit as tk from ckan import authz, logic from ckan.logic import validate -from ckan.types import Action, Context, DataDict from ckanext.relationship import utils +from ckanext.relationship.config import views_without_relationships_in_package_show from ckanext.relationship.logic import schema from ckanext.relationship.model.relationship import Relationship from ckanext.relationship.utils import entity_name_by_id @@ -29,10 +31,7 @@ def get_actions(): @validate(schema.relation_create) -def relationship_relation_create( - context: Context, - data_dict: DataDict, -) -> list[dict[str, str]]: +def relationship_relation_create(context, data_dict) -> list[dict[str, str]]: """Create relation with specified type (relation_type) between two entities specified by ids (subject_id, object_id). Also create reverse relation.""" tk.check_access("relationship_relation_create", context, data_dict) @@ -64,10 +63,7 @@ def relationship_relation_create( @validate(schema.relation_delete) -def relationship_relation_delete( - context: Context, - data_dict: DataDict, -) -> list[dict[str, str]]: +def relationship_relation_delete(context, data_dict) -> list[dict[str, str]]: """Delete relation with specified type (relation_type) between two entities specified by ids (subject_id, object_id). Also delete reverse relation.""" tk.check_access("relationship_relation_delete", context, data_dict) @@ -128,10 +124,7 @@ def relationship_relation_delete( @validate(schema.relations_list) -def relationship_relations_list( - context: Context, - data_dict: DataDict, -) -> list[dict[str, str]]: +def relationship_relations_list(context, data_dict) -> list[dict[str, str]]: """Return a list of dictionaries representing the relations of a specified entity (object_entity, object_type) related to the specified type of relation (relation_type) with an entity specified by its id (subject_id). @@ -158,7 +151,7 @@ def relationship_relations_list( @validate(schema.relations_ids_list) -def relationship_relations_ids_list(context: Context, data_dict: DataDict) -> list[str]: +def relationship_relations_ids_list(context, data_dict) -> list[str]: """Return ids list of specified entity (object_entity, object_type) related with specified type of relation (relation_type) with entity specified by id (subject_id). @@ -171,7 +164,7 @@ def relationship_relations_ids_list(context: Context, data_dict: DataDict) -> li @validate(schema.get_entity_list) -def relationship_get_entity_list(context: Context, data_dict: DataDict) -> list[str]: +def relationship_get_entity_list(context, data_dict) -> list[str]: """Return ids list of specified entity (entity, entity_type)""" tk.check_access("relationship_get_entity_list", context, data_dict) @@ -191,7 +184,7 @@ def relationship_get_entity_list(context: Context, data_dict: DataDict) -> list[ @validate(schema.autocomplete) -def relationship_autocomplete(context: Context, data_dict: DataDict) -> DataDict: +def relationship_autocomplete(context, data_dict) -> dict[str, Any]: fq = f'type:{data_dict["entity_type"]} -id:{data_dict["current_entity_id"]}' if data_dict.get("owned_only") and not ( @@ -229,15 +222,13 @@ def relationship_autocomplete(context: Context, data_dict: DataDict) -> DataDict @tk.chained_action @tk.side_effect_free -def package_show(next_: Action, context: Context, data_dict: DataDict) -> DataDict: +def package_show(next_, context, data_dict) -> dict[str, Any]: result = next_(context, data_dict) pkg_id = result["id"] pkg_type = result["type"] - views_without_relationships = tk.config[ - "ckanext.relationship.views_without_relationships_in_package_show" - ] + views_without_relationships = views_without_relationships_in_package_show() if ( tk.get_endpoint()[1] in views_without_relationships diff --git a/ckanext/relationship/plugin.py b/ckanext/relationship/plugin.py index 1cf9a66..09d3403 100644 --- a/ckanext/relationship/plugin.py +++ b/ckanext/relationship/plugin.py @@ -114,6 +114,19 @@ def before_dataset_index(self, pkg_dict): return pkg_dict + # CKAN < 2.10 hooks + def after_create(self, context, data_dict): + return self.after_dataset_create(context, data_dict) + + def after_update(self, context, data_dict): + return self.after_dataset_update(context, data_dict) + + def after_delete(self, context, data_dict): + return self.after_dataset_delete(context, data_dict) + + def before_index(self, pkg_dict): + return self.before_dataset_index(pkg_dict) + if tk.check_ckan_version("2.10"): tk.blanket.config_declarations(RelationshipPlugin) diff --git a/setup.py b/setup.py index 919e0c8..cae381c 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # http://packaging.python.org/en/latest/tutorial.html#version - version="0.2.8", + version="0.2.9", description="""""", long_description=long_description, long_description_content_type="text/markdown",