diff --git a/CHANGELOG.md b/CHANGELOG.md index fe70079b7..2e2c6fbec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Current (in progress) - Display correct business documentation url link [#595](https://github.com/datagouv/udata-front/pull/595) +- Remove old display from api.gouv.fr in datasets pages [#597](https://github.com/datagouv/udata-front/pull/597) - Change link to reuses search page instead of datasets search page in dataservice search page [#599](https://github.com/datagouv/udata-front/pull/599) ## 6.0.1 (2024-11-13) diff --git a/setup.py b/setup.py index 8b925ee66..1ac45e5d0 100644 --- a/setup.py +++ b/setup.py @@ -53,9 +53,6 @@ def get_requirements(): 'udata.harvesters': [ 'maaf = udata_front.harvesters.maaf:MaafBackend', ], - 'udata.tasks': [ - 'front = udata_front.tasks', - ], }, license='LGPL', zip_safe=False, diff --git a/udata_front/__init__.py b/udata_front/__init__.py index 85c9f1e3b..76ff93868 100644 --- a/udata_front/__init__.py +++ b/udata_front/__init__.py @@ -4,14 +4,3 @@ __version__ = '6.0.2.dev' __description__ = 'udata customizations for data.gouv.fr' - -APIGOUVFR_EXTRAS_KEY = 'apigouvfr:apis' -APIGOUVFR_EXPECTED_FIELDS = [ - 'title', - 'tagline', - 'path', - 'slug', - 'owner', - 'openness', - 'logo', -] diff --git a/udata_front/settings.py b/udata_front/settings.py index 0d1a3867c..614950ea1 100644 --- a/udata_front/settings.py +++ b/udata_front/settings.py @@ -34,10 +34,6 @@ PAGES_GH_REPO_NAME = 'etalab/datagouvfr-pages' PAGES_REPO_BRANCH = 'master' -# api.gouv.fr -APIGOUVFR_URL = 'https://api.gouv.fr/api/v1/apis' -APIGOUVFR_ALLOW_OPENNESS = ['open', 'semi_open'] - # catalogue.data.gouv.fr CATALOG_URL = 'https://catalogue.data.gouv.fr/' diff --git a/udata_front/tasks.py b/udata_front/tasks.py deleted file mode 100644 index c6bac5af0..000000000 --- a/udata_front/tasks.py +++ /dev/null @@ -1,63 +0,0 @@ -import mongoengine -import requests - -from collections import defaultdict -from flask import current_app - -from udata.commands import success, error -from udata.core.dataset.models import Dataset -from udata.tasks import job - -from udata_front import ( - APIGOUVFR_EXTRAS_KEY, - APIGOUVFR_EXPECTED_FIELDS, -) - - -def get_dataset(id_or_slug): - obj = Dataset.objects(slug=id_or_slug).first() - return obj or Dataset.objects.get(id=id_or_slug) - - -def process_dataset(d_id, apis): - try: - dataset = get_dataset(d_id) - except (Dataset.DoesNotExist, mongoengine.errors.ValidationError): - return error(f'Dataset {d_id} not found') - dataset.extras[APIGOUVFR_EXTRAS_KEY] = apis - dataset.save() - success(f'Imported {len(apis)} API(s) for {str(dataset)}') - - -@job('apigouvfr-load-apis') -def apigouvfr_load_apis(self): - '''Load dataset-related APIs from api.gouv.fr''' - r = requests.get(current_app.config['APIGOUVFR_URL'], timeout=10) - r.raise_for_status() - - # cleanup existing mappings - Dataset.objects.filter(**{ - f'extras__{APIGOUVFR_EXTRAS_KEY}__exists': True, - }).update(**{ - f'unset__extras__{APIGOUVFR_EXTRAS_KEY}': True, - }) - - apis = r.json() - datasets_apis = defaultdict(list) - for api in apis: - d_ids = api.pop('datagouv_uuid', []) - if not d_ids: - continue - if not all([k in api for k in APIGOUVFR_EXPECTED_FIELDS]): - error(f'Missing field in payload: {api}') - continue - if api['openness'] not in current_app.config.get('APIGOUVFR_ALLOW_OPENNESS', []): - continue - for d_id in d_ids: - if api not in datasets_apis[d_id]: - datasets_apis[d_id].append(api) - - for d_id, d_apis in datasets_apis.items(): - process_dataset(d_id, d_apis) - - success('Done.') diff --git a/udata_front/tests/test_tasks.py b/udata_front/tests/test_tasks.py deleted file mode 100644 index 412a11815..000000000 --- a/udata_front/tests/test_tasks.py +++ /dev/null @@ -1,39 +0,0 @@ -import copy -import pytest - -from flask import current_app - -from udata.core.dataset.factories import DatasetFactory -from udata_front import APIGOUVFR_EXTRAS_KEY -from udata_front.tests import GouvFrSettings -from udata_front.tasks import apigouvfr_load_apis - - -@pytest.mark.usefixtures('clean_db') -class ApiGouvFrTasksTest: - settings = GouvFrSettings - modules = [] - - def test_apigouvfr_load_apis(app, rmock): - dataset = DatasetFactory() - url = current_app.config.get('APIGOUVFR_URL') - apis = [{ - 'title': 'une API', - 'tagline': 'tagline', - 'path': '/path', - 'slug': 'slug', - 'owner': 'owner', - 'openness': 'open', - 'logo': '/logo.png', - }] - payload = copy.deepcopy(apis) - payload[0]['datagouv_uuid'] = [str(dataset.id), 'nope'] - # missing fields, won't be processed - payload.append({ - 'title': 'une autre API', - 'datagouv_uuid': [str(dataset.id)], - }) - rmock.get(url, json=payload) - apigouvfr_load_apis() - dataset.reload() - assert dataset.extras.get(APIGOUVFR_EXTRAS_KEY) == apis diff --git a/udata_front/tests/tests.py b/udata_front/tests/tests.py index 6714d775e..cb654a5ae 100644 --- a/udata_front/tests/tests.py +++ b/udata_front/tests/tests.py @@ -24,7 +24,6 @@ from udata.tests.helpers import assert200, assert404, assert_redirects, assert_equal_dates from udata.frontend.markdown import md -from udata_front import APIGOUVFR_EXTRAS_KEY from udata_front.models import SPD, TERRITORY_DATASETS from udata_front.tests import GouvFrSettings @@ -72,24 +71,6 @@ def test_render_dataset_page(self, client): response = client.get(url_for('datasets.show', dataset=dataset)) assert200(response) - def test_render_dataset_w_api(self, client): - '''It should render the dataset page''' - dataset = DatasetFactory() - dataset.extras[APIGOUVFR_EXTRAS_KEY] = [{ - 'title': 'une API', - 'tagline': 'tagline', - 'path': '/path', - 'slug': 'slug', - 'owner': 'owner', - 'openness': 'open', - 'logo': '/logo.png', - }] - dataset.save() - - response = client.get(url_for('datasets.show', dataset=dataset)) - assert200(response) - assert 'une API' in response.data.decode('utf8') - def test_render_organization_page(self, client): '''It should render the organization page''' org = OrganizationFactory() diff --git a/udata_front/theme/gouvfr/assets/js/components/search/Search/Search.stories.ts b/udata_front/theme/gouvfr/assets/js/components/search/Search/Search.stories.ts index 96f2acf18..d8dadf178 100644 --- a/udata_front/theme/gouvfr/assets/js/components/search/Search/Search.stories.ts +++ b/udata_front/theme/gouvfr/assets/js/components/search/Search/Search.stories.ts @@ -93,38 +93,6 @@ const meta = { } } } - ], - "apigouvfr:apis": [ - { - "title": "API Conventions collectives", - "tagline": "Retrouvez les conventions collectives d'une entreprise \u00e0 partir de son num\u00e9ro SIRET", - "path": "/les-api/api-conventions-collectives", - "slug": "api-conventions-collectives", - "openness": "open", - "owner": "Minist\u00e8re du Travail, de l'Emploi et de l'Insertion", - "owner_acronym": "MTEI", - "logo": "/images/api-logo/logo-mtei.png" - }, - { - "title": "API Recherche d\u2019entreprises", - "tagline": "Rechercher une entreprise fran\u00e7aise, par sa d\u00e9nomination, ou son adresse", - "path": "/les-api/api-recherche-entreprises", - "slug": "api-recherche-entreprises", - "openness": "open", - "owner": "Direction Interminist\u00e9rielle du Num\u00e9rique", - "owner_acronym": "DINUM", - "logo": "/images/api-logo/dinum.png" - }, - { - "title": "API Sirene", - "tagline": "Acc\u00e9der aux informations concernant les entreprises et les \u00e9tablissements immatricul\u00e9s au r\u00e9pertoire interadministratif Sirene de l'Insee", - "path": "/les-api/sirene_v3", - "slug": "sirene_v3", - "openness": "semi_open", - "owner": "Institut national de la statistique et des \u00e9tudes \u00e9conomiques", - "owner_acronym": "Insee", - "logo": "/images/api-logo/Logo_Insee.svg" - } ] }, "metrics": { @@ -475,18 +443,6 @@ const meta = { "frequency": "quarterly", "frequency_date": "2019-04-08T20:00:00+00:00", "extras": { - "apigouvfr:apis": [ - { - "title": "API Recherche d\u2019entreprises", - "tagline": "Rechercher une entreprise fran\u00e7aise, par sa d\u00e9nomination, ou son adresse", - "path": "/les-api/api-recherche-entreprises", - "slug": "api-recherche-entreprises", - "openness": "open", - "owner": "Direction Interminist\u00e9rielle du Num\u00e9rique", - "owner_acronym": "DINUM", - "logo": "/images/api-logo/dinum.png" - } - ], "recommendations": [ { "id": "53699924a3a729239d205175", @@ -849,28 +805,6 @@ const meta = { ], "recommendations:sources": [ "edito" - ], - "apigouvfr:apis": [ - { - "title": "API Annuaire de l\u2019administration et des services publics", - "tagline": "Consultez les donn\u00e9es publiques de l\u2019annuaire de l\u2019administration \u2013 Service-public.fr.", - "path": "/les-api/api-annuaire-administration-services-publics", - "slug": "api-annuaire-administration-services-publics", - "openness": "open", - "owner": "Direction de l'information l\u00e9gale et administrative", - "owner_acronym": "DILA", - "logo": "/images/api-logo/dila.png" - }, - { - "title": "Annuaire des \u00e9tablissements publics de l'administration", - "tagline": "L\u2019API qui r\u00e9f\u00e9rence les guichets publics locaux", - "path": "/les-api/api_etablissements_publics", - "slug": "api_etablissements_publics", - "openness": "open", - "owner": "Direction Interminist\u00e9rielle du Num\u00e9rique", - "owner_acronym": "DINUM", - "logo": "/images/api-logo/dinum.png" - } ] }, "metrics": { @@ -1402,18 +1336,6 @@ const meta = { } ], "transport:url": "https://transport.data.gouv.fr/datasets/base-adresse-nationale", - "apigouvfr:apis": [ - { - "title": "API Adresse (Base Adresse Nationale - BAN)", - "tagline": "Interrogez la Base Adresse Nationale, base de donn\u00e9es de l\u2019int\u00e9gralit\u00e9 des adresses du territoire fran\u00e7ais", - "path": "/les-api/base-adresse-nationale", - "slug": "base-adresse-nationale", - "openness": "open", - "owner": "Direction Interminist\u00e9rielle du Num\u00e9rique", - "owner_acronym": "DINUM", - "logo": "/images/api-logo/dinum.png" - } - ], "recommendations:sources": [ "edito", "matomo" @@ -3445,18 +3367,6 @@ const sampleResults = JSON.stringify([ "frequency": "punctual", "frequency_date": null, "extras": { - "apigouvfr:apis": [ - { - "title": "API Bulletin officiel des annonces des marchés publics (BOAMP)", - "tagline": "Rechercher et consulter les annonces du Bulletin Officiel des Annonces de Marchés Publics", - "path": "/les-api/api-annonces-marches-publics-boamp", - "slug": "api-annonces-marches-publics-boamp", - "openness": "open", - "owner": "Direction de l'information légale et administrative", - "owner_acronym": "DILA", - "logo": "/images/api-logo/dila.png" - } - ] }, "metrics": { "discussions": 33, diff --git a/udata_front/views/gouvfr.py b/udata_front/views/gouvfr.py index 51f8b1b33..cf3c8c34d 100644 --- a/udata_front/views/gouvfr.py +++ b/udata_front/views/gouvfr.py @@ -12,8 +12,6 @@ from udata.models import Reuse, Dataset from udata.i18n import I18nBlueprint -from udata_front import APIGOUVFR_EXTRAS_KEY - log = logging.getLogger(__name__) blueprint = I18nBlueprint('gouvfr', __name__, @@ -135,17 +133,6 @@ def suivi(): abort(404) -def has_apis(ctx): - dataset = ctx['dataset'] - return dataset.extras.get(APIGOUVFR_EXTRAS_KEY, []) - - -@template_hook('dataset.display.after-files', when=has_apis) -def dataset_apis(ctx): - dataset = ctx['dataset'] - return theme.render('dataset-apis.html', apis=dataset.extras.get(APIGOUVFR_EXTRAS_KEY)) - - @template_hook('oauth_authorize_theme_content') def oauth_authorize_theme_content(ctx): grant = ctx['grant']