diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5c0e5a6..4ca4f72 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,18 +20,21 @@ jobs: # needs: lint strategy: matrix: - ckan-version: [2.9] + ckan-base-version: [2.9] + ckan-version: [py3.9] + solr-version: [solr8] fail-fast: false - name: CKAN ${{ matrix.ckan-version }} + name: CKAN ${{ matrix.ckan-base-version }} runs-on: ubuntu-latest container: - image: openknowledge/ckan-dev:${{ matrix.ckan-version }} + image: ckan/ckan-dev:${{ matrix.ckan-base-version }}-${{ matrix.ckan-version }} + options: --user root services: solr: - image: ckan/ckan-solr:${{ matrix.ckan-version }}-solr9 + image: ckan/ckan-solr:${{ matrix.ckan-base-version }}-${{ matrix.solr-version }} postgres: - image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }} + image: ckan/ckan-postgres-dev:${{ matrix.ckan-base-version }} env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres @@ -48,6 +51,8 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install CURL + run: apt install curl -y - name: Install requirements run: | pip install -r dev-requirements.txt @@ -66,8 +71,8 @@ jobs: ckan -c test.ini db init - name: Run tests run: pytest --ckan-ini=test.ini --cov=ckanext.datasetsnippets --cov-report=xml --cov-append --disable-warnings ckanext/datasetsnippets/tests - - name: Upload coverage report to codecov - uses: codecov/codecov-action@v1 - with: - file: ./coverage.xml - token: ${{secrets.CODECOV_TOKEN}} + - name: Upload coverage reports to Codecov + run: | + curl -Os https://uploader.codecov.io/latest/linux/codecov + chmod +x codecov + ./codecov diff --git a/CHANGELOG.md b/CHANGELOG.md index 655562a..15cb5b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Development +## [0.1.10](https://github.com/berlinonline/ckanext-datasetsnippets/releases/tag/0.1.10) + +_(2024-09-02)_ + +- Sanitize user input & handle author_string/author + ## [0.1.9](https://github.com/berlinonline/ckanext-datasetsnippets/releases/tag/0.1.9) _(2024-08-29)_ diff --git a/README.md b/README.md index 9aa9408..905e173 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ datasetsnippets.datenportal_title = 'Berlin Open Data' ## License -This material is copyright © [BerlinOnline Stadtportal GmbH](https://www.berlinonline.net/). +This material is copyright © [BerlinOnline GmbH](https://www.berlinonline.net/). This extension is open and licensed under the GNU Affero General Public License (AGPL) v3.0. Its full text may be found at: diff --git a/ckanext/datasetsnippets/VERSION b/ckanext/datasetsnippets/VERSION index 82551ad..345f8cc 100644 --- a/ckanext/datasetsnippets/VERSION +++ b/ckanext/datasetsnippets/VERSION @@ -1 +1 @@ -0.1.9 \ No newline at end of file +0.1.10 \ No newline at end of file diff --git a/ckanext/datasetsnippets/blueprints/feeds.py b/ckanext/datasetsnippets/blueprints/feeds.py index eb06328..c5ee730 100644 --- a/ckanext/datasetsnippets/blueprints/feeds.py +++ b/ckanext/datasetsnippets/blueprints/feeds.py @@ -363,6 +363,9 @@ def custom(): fields = request.params.get(u'fields', u'') fq = u'' search_params = {} + # some facets are not with the name used in CKAN + changed_facets = {'author_string': 'author'} + for (param, value) in request.params.items(): if param not in [u'q', u'page', u'sort'] \ and len(value) and not param.startswith(u'_'): @@ -370,8 +373,13 @@ def custom(): value_tmp = value.split('&') result_dict = dict(pair.split('=') for pair in value_tmp) for res in result_dict: - search_params[res] = result_dict[res] - fq += u' +%s:%s' % (res, result_dict[res]) + if res in changed_facets.keys(): + res_tmp = changed_facets[res] + search_params[res] = result_dict[res] + fq += u' +%s:%s' % (res_tmp, result_dict[res]) + else: + search_params[res] = result_dict[res] + fq += u' +%s:%s' % (res, result_dict[res]) else: search_params[param] = value fq += u' %s:%s' % (param, value) @@ -508,7 +516,7 @@ def _create_rss_id(resource_path, authority_name=None, date_string=None): # Construct the GUID as a full URL if authority_name: - return f"http://{authority_name}{resource_path}" + return f"https://{authority_name}{resource_path}" else: # Fallback to just the resource path if authority_name is not available return resource_path diff --git a/ckanext/datasetsnippets/blueprints/snippet_blueprint.py b/ckanext/datasetsnippets/blueprints/snippet_blueprint.py index 540a276..ec99cef 100644 --- a/ckanext/datasetsnippets/blueprints/snippet_blueprint.py +++ b/ckanext/datasetsnippets/blueprints/snippet_blueprint.py @@ -14,6 +14,7 @@ import ckan.plugins as plugins from ckan.plugins import toolkit from ckan.common import _, c, request, config +from six.moves.urllib.parse import unquote from ckanext.datasetsnippets.blueprints import feeds @@ -156,7 +157,8 @@ def search_dataset(): if k != 'root_breadcrumb'] # unicode format (decoded from utf8) - q = c.q = request.params.get('q', u'') + q = request.params.get('q', u'') + c.q = unquote(q) c.query_error = False page = h.get_page_number(request.params) diff --git a/publiccode.yml b/publiccode.yml new file mode 100644 index 0000000..c69bbd9 --- /dev/null +++ b/publiccode.yml @@ -0,0 +1,144 @@ +# This repository adheres to the publiccode.yml standard by including this +# metadata file that makes public software easily discoverable. +# More info at https://github.com/italia/publiccode.yml + +publiccodeYmlVersion: '0.2' +name: ckanext-datasetsnippets +url: 'https://github.com/berlinonline/ckanext-datasetsnippets' +releaseDate: '2022-02-22' +softwareVersion: 0.1.11 +developmentStatus: stable +softwareType: addon +categories: + - it-development + - knowledge-management +maintenance: + type: internal + contacts: + - name: Dr. Knud Möller + email: knud.moeller@berlinonline.de +legal: + license: AGPL-3.0-only + mainCopyrightOwner: BerlinOnline GmbH + repoOwner: BerlinOnline GmbH +localisation: + localisationReady: false +description: + it: + genericName: ckanext-datasetsnippets + documentation: >- + https://github.com/berlinonline/ckanext-datasetsnippets?tab=readme-ov-file#ckanext-datasetsnippets + apiDocumentation: >- + https://github.com/berlinonline/ckanext-datasetsnippets?tab=readme-ov-file#api + shortDescription: >- + ckanext-datasetsnippets provides markup snippets for dataset pages and + dataset search. These snippets can be loaded from the data portal's public + CMS + longDescription: > + This plugin belongs to a set of plugins for the _Datenregister_ – the + non-public [CKAN](https://ckan.org/) instance that is part of Berlin's + open data portal [daten.berlin.de](https://daten.berlin.de/). + _ckanext-datasetsnippets_ provides markup snippets for dataset pages and + dataset search. These snippets can be loaded from the data portal's public + CMS to handle all requests for datasets. + + + The plugin implements the following CKAN interfaces: + + + - + [ITemplateHelpers](http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html#ckan.plugins.interfaces.ITemplateHelpers) + + - + [IBlueprint](http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IBlueprint) + + - + [IAuthFunctions](http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IAuthFunctions) + + + ## Requirements + + + This plugin has been tested with CKAN 2.9.9 (which requires Python 3). + + + ## API + + + The Snippet API has the following two endpoints: + + + ### `/snippet/dataset` + + + This is the search endpoint of the snippet API, which is equivalent to + `/dataset` in the regular CKAN UI. Without additional parameters, this + returns markup for the paginated list of all datasets. Parameters (search + facets, ordering etc.) can be use to restrict the result. The parameters + are identical to the regular CKAN search parameters. + + + ### `/snippet/dataset/` + + + This is the dataset detail endpoint of the snippet API, which is + equivalent to `/dataset/` in the regular CKAN UI. `` is the name + or id of a dataset. + + + ### Parameters + + + Both endpoints allow a `root\_breadcrumb` parameter to set the root + element of the breadcrumb returned in the snippets. The + `root\_breadcrumb`-URL-parameter takes precedence over the + `datasetsnippets.default\_root\_breadcrumb` config (see below). + + + ## Configuration + + + The plugin introduces the following configuration options: + + + ### datasetsnippets.path + + + Defines the path component that is prefixed to links that the snippets + contain. In the regular CKAN UI, this would be `dataset`, but the site + calling the snippet API might require a different path. + + datasetsnippets.path = 'datensaetze' + + ### datasetsnippets.datasets\_per\_page + + + Defines how many datasets are shown per result page in pagination. The + option is equivalent to + [ckan.datasets\_per\_page](https://docs.ckan.org/en/2.9/maintaining/configuration.html#ckan-datasets-per-page), + but only applies to the snippets and leaves the regular CKAN UI untouched. + + datasetsnippets.datasets\_per\_page = 10 + + ### datasetsnippets.default\_root\_breadcrumb + + + Defines the string that is used as the root element for the breadcrumb + that is part of the returned snippets. + + datasetsnippets.default\_root\_breadcrumb = 'Berlin Open Data' + + ### datasetsnippets.datenportal\_url + + + Defines the url to the datenportal. The url will then be used for + generating the feeds using the provided url. + + datasetsnippets.datenportal\_url = link\_to\_portal + + ### datasetsnippets.datenportal\_title + + + Defines a string that will be used as a title in the feeds. + + datasetsnippets.datenportal\_title = 'Berlin Open Data'