diff --git a/src/layman/common/prime_db_schema/publications.py b/src/layman/common/prime_db_schema/publications.py index 816c99f9b..071db2546 100644 --- a/src/layman/common/prime_db_schema/publications.py +++ b/src/layman/common/prime_db_schema/publications.py @@ -6,7 +6,7 @@ import crs as crs_def from db import util as db_util, TableUri from geoserver.util import RESERVED_ROLE_NAMES -from layman import settings, LaymanError +from layman import settings, LaymanError, util as layman_util from layman.authn import is_user_with_name from layman.authz import split_user_and_role_names, role_service from layman.common import get_publications_consts as consts, bbox as bbox_util @@ -27,8 +27,9 @@ class CalculatedColumnType: params: tuple = tuple() -def get_publication_infos(workspace_name=None, pub_type=None, style_type=None, ): - return get_publication_infos_with_metainfo(workspace_name, pub_type, style_type,)['items'] +def get_publication_infos(workspace_name=None, pub_type=None, context=None, style_type=None, ): + x_forwarded_items = (context or {}).get('x_forwarded_items') + return get_publication_infos_with_metainfo(workspace_name, pub_type, style_type, x_forwarded_items=x_forwarded_items)['items'] def get_publication_infos_with_metainfo(workspace_name=None, pub_type=None, style_type=None, @@ -42,6 +43,8 @@ def get_publication_infos_with_metainfo(workspace_name=None, pub_type=None, styl ordering_full_text=None, ordering_bbox=None, ordering_bbox_crs=None, + *, + x_forwarded_items=None, ): order_by_list = order_by_list or [] @@ -287,6 +290,7 @@ def get_publication_infos_with_metainfo(workspace_name=None, pub_type=None, styl '_map_layers': map_layers or [], '_layer_maps': layer_maps or [], '_wfs_wms_status': settings.EnumWfsWmsStatus(wfs_wms_status) if wfs_wms_status else None, + 'url': layman_util.get_workspace_publication_url(publication_type, workspace_name, publication_name, x_forwarded_items=x_forwarded_items), } for id_publication, workspace_name, publication_type, publication_name, title, uuid, geodata_type, style_type, image_mosaic, updated_at, xmin, ymin, xmax, ymax, srid, external_table_uri, read_users_roles, write_users_roles, map_layers, layer_maps, wfs_wms_status, _ diff --git a/src/layman/common/rest.py b/src/layman/common/rest.py index ae02569b9..109d99908 100644 --- a/src/layman/common/rest.py +++ b/src/layman/common/rest.py @@ -232,7 +232,8 @@ def get_publications(publication_type, actor, request_args=None, workspace=None, publication_infos_whole = layman_util.get_publication_infos_with_metainfo(publ_type=publication_type, workspace=workspace, context={'actor_name': actor, - 'access_type': 'read' + 'access_type': 'read', + 'x_forwarded_items': x_forwarded_items, }, limit=limit, offset=offset, full_text_filter=full_text_filter, @@ -251,7 +252,7 @@ def get_publications(publication_type, actor, request_args=None, workspace=None, 'workspace': res_workspace, 'publication_type': info['type'].split('.')[1], 'title': info.get("title"), - 'url': layman_util.get_workspace_publication_url(info['type'], res_workspace, name, x_forwarded_items=x_forwarded_items), + 'url': info['url'], 'uuid': info["uuid"], 'access_rights': info['access_rights'], 'updated_at': info['updated_at'].isoformat(), diff --git a/src/layman/layer/__init__.py b/src/layman/layer/__init__.py index 81ff51807..f0fc38f4f 100644 --- a/src/layman/layer/__init__.py +++ b/src/layman/layer/__init__.py @@ -67,7 +67,7 @@ def get_layer_patch_keys(): ('layman.layer.prime_db_schema.table', InternalSourceTypeDef(info_items=[ 'access_rights', 'name', 'title', 'uuid', 'bounding_box', 'style_type', 'native_crs', 'native_bounding_box', 'geodata_type', 'updated_at', 'id', 'type', 'image_mosaic', 'table_uri', - 'original_data_source', 'wfs_wms_status', 'layer_maps']),), + 'original_data_source', 'wfs_wms_status', 'layer_maps', 'url']),), ('layman.layer.filesystem.input_chunk', InternalSourceTypeDef(info_items=['file', ]),), ('layman.layer.filesystem.input_file', InternalSourceTypeDef(info_items=['file', ]),), ('layman.layer.filesystem.input_style', InternalSourceTypeDef(info_items=[]),), diff --git a/src/layman/layer/micka/csw.py b/src/layman/layer/micka/csw.py index d22540167..5c5661939 100644 --- a/src/layman/layer/micka/csw.py +++ b/src/layman/layer/micka/csw.py @@ -114,7 +114,7 @@ def get_template_path_and_values(workspace, layername, http_method): logger.info(f'get_template_path_and_values start calculating data for {workspace}:{layername}') assert http_method in [common.REQUEST_METHOD_POST, common.REQUEST_METHOD_PATCH] publ_info = get_publication_info(workspace, LAYER_TYPE, layername, context={ - 'keys': ['title', 'native_bounding_box', 'native_crs', 'description', 'geodata_type', 'table_uri', 'wms'], + 'keys': ['title', 'native_bounding_box', 'native_crs', 'description', 'geodata_type', 'table_uri', 'wms', 'url'], }) title = publ_info['title'] abstract = publ_info.get('description') @@ -178,7 +178,7 @@ def get_template_path_and_values(workspace, layername, http_method): 'title': title, 'publication_date': publ_datetime.strftime('%Y-%m-%d'), 'identifier': { - 'identifier': url_for('rest_workspace_layer.get', workspace=workspace, layername=layername), + 'identifier': publ_info['url'], 'label': layername, }, 'abstract': abstract, @@ -187,7 +187,7 @@ def get_template_path_and_values(workspace, layername, http_method): 'temporal_extent': temporal_extent, 'wms_url': f"{wms.add_capabilities_params_to_url(wms.get_wms_url(workspace, external_url=True))}&LAYERS={layername}", 'wfs_url': f"{wfs.add_capabilities_params_to_url(wfs_url)}&LAYERS={layername}" if wfs_url else None, - 'layer_endpoint': url_for('rest_workspace_layer.get', workspace=workspace, layername=layername), + 'layer_endpoint': publ_info['url'], 'spatial_resolution': spatial_resolution, 'language': languages, 'md_organisation_name': None, diff --git a/src/layman/layer/rest_workspace_layer.py b/src/layman/layer/rest_workspace_layer.py index c5e312af9..038685a19 100644 --- a/src/layman/layer/rest_workspace_layer.py +++ b/src/layman/layer/rest_workspace_layer.py @@ -6,7 +6,7 @@ from layman.common import rest as rest_util from layman.common.prime_db_schema import publications from layman.http import LaymanError -from layman.util import check_workspace_name_decorator, url_for +from layman.util import check_workspace_name_decorator from layman import settings, authn, util as layman_util from layman.authn import authenticate from layman.authz import authorize_workspace_publications_decorator @@ -264,7 +264,6 @@ def patch(workspace, layername): app.logger.info('PATCH Layer changes done') patch_keys = get_layer_patch_keys() info = util.get_layer_info(workspace, layername, context={'keys': patch_keys, 'x_forwarded_items': x_forwarded_items}) - info['url'] = url_for('rest_workspace_layer.get', layername=layername, workspace=workspace, x_forwarded_items=x_forwarded_items) info.update(layer_result) info = {key: value for key, value in info.items() if key in patch_keys} diff --git a/src/layman/layer/rest_workspace_layers.py b/src/layman/layer/rest_workspace_layers.py index eac646104..6cede6adb 100644 --- a/src/layman/layer/rest_workspace_layers.py +++ b/src/layman/layer/rest_workspace_layers.py @@ -260,8 +260,6 @@ def delete(workspace): util.abort_layer_chain, util.delete_layer, request.method, - 'rest_workspace_layer.get', - 'layername', x_forwarded_items=x_forwarded_items, ) return infos, 200 diff --git a/src/layman/layer/util.py b/src/layman/layer/util.py index 7e693f6b7..dc64ce7a1 100644 --- a/src/layman/layer/util.py +++ b/src/layman/layer/util.py @@ -8,7 +8,7 @@ from db import TableUri, util as db_util from layman import LaymanError, patch_mode, util as layman_util, settings from layman.util import call_modules_fn, get_providers_from_source_names, get_internal_sources, \ - to_safe_name, url_for + to_safe_name from layman import celery as celery_util, common from layman.common import redis as redis_util, tasks as tasks_util, metadata as metadata_common from layman.common.prime_db_schema import publications @@ -100,7 +100,6 @@ def _get_complete_layer_info(workspace, layername, *, x_forwarded_items=None): complete_info.update({ 'name': layername, - 'url': url_for('rest_workspace_layer.get', layername=layername, workspace=workspace, x_forwarded_items=x_forwarded_items), 'title': layername, 'description': '', }) diff --git a/src/layman/map/micka/csw.py b/src/layman/map/micka/csw.py index d4519ce7c..2e4748bb0 100644 --- a/src/layman/map/micka/csw.py +++ b/src/layman/map/micka/csw.py @@ -153,7 +153,7 @@ def get_template_path_and_values(workspace, mapname, *, http_method=None, actor_ revision_date = datetime.now() operates_on = map_to_operates_on(workspace, mapname, editor=actor_name) publ_info = get_publication_info(workspace, MAP_TYPE, mapname, context={ - 'keys': ['title', 'native_bounding_box', 'description', 'native_crs'], + 'keys': ['title', 'native_bounding_box', 'description', 'native_crs', 'url'], }) native_bbox = publ_info.get('native_bounding_box') crs = publ_info.get('native_crs') @@ -176,7 +176,7 @@ def get_template_path_and_values(workspace, mapname, *, http_method=None, actor_ publication_date=publ_datetime.strftime('%Y-%m-%d'), revision_date=revision_date.strftime('%Y-%m-%d'), md_date_stamp=date.today().strftime('%Y-%m-%d'), - identifier=url_for('rest_workspace_map.get', workspace=workspace, mapname=mapname), + identifier=publ_info['url'], identifier_label=mapname, extent=extent, crs_list=[crs], diff --git a/src/layman/map/rest_workspace_maps.py b/src/layman/map/rest_workspace_maps.py index 606e276e8..f1c6740be 100644 --- a/src/layman/map/rest_workspace_maps.py +++ b/src/layman/map/rest_workspace_maps.py @@ -143,8 +143,6 @@ def delete(workspace): util.abort_map_chain, util.delete_map, request.method, - 'rest_workspace_map.get', - 'mapname', x_forwarded_items=x_forwarded_items, ) diff --git a/src/layman/map/util.py b/src/layman/map/util.py index f86af9710..b20c74618 100644 --- a/src/layman/map/util.py +++ b/src/layman/map/util.py @@ -145,7 +145,6 @@ def _get_complete_map_info(workspace, mapname, *, x_forwarded_items=None): complete_info = { 'name': mapname, - 'url': url_for('rest_workspace_map.get', mapname=mapname, workspace=workspace, x_forwarded_items=x_forwarded_items), 'title': mapname, 'description': '', } diff --git a/src/layman/util.py b/src/layman/util.py index d1dd43a4b..90418c7c3 100644 --- a/src/layman/util.py +++ b/src/layman/util.py @@ -470,6 +470,7 @@ def get_publication_infos_with_metainfo(workspace=None, publ_type=None, context= writer = (context.get('actor_name') or settings.ANONYM_USER) if context.get('access_type') == 'write' else None reader_roles = list(get_user_roles(username=reader)) if reader and reader != settings.ANONYM_USER else None writer_roles = list(get_user_roles(username=writer)) if writer and writer != settings.ANONYM_USER else None + x_forwarded_items = context.get('x_forwarded_items') infos = publications.get_publication_infos_with_metainfo(workspace, publ_type, style_type, reader=reader, writer=writer, @@ -482,6 +483,7 @@ def get_publication_infos_with_metainfo(workspace=None, publ_type=None, context= ordering_full_text=ordering_full_text, ordering_bbox=ordering_bbox, ordering_bbox_crs=ordering_bbox_crs, + x_forwarded_items=x_forwarded_items, ) return infos @@ -505,13 +507,11 @@ def delete_publications(workspace, abort_publication_fn, delete_publication_fn, method, - url_path, - publ_param, x_forwarded_items=None, ): from layman import authn actor_name = authn.get_authn_username() - whole_infos = get_publication_infos(workspace, publ_type, {'actor_name': actor_name, 'access_type': 'write'}) + whole_infos = get_publication_infos(workspace, publ_type, {'actor_name': actor_name, 'access_type': 'write', 'x_forwarded_items': x_forwarded_items}) for (_, _, publication) in whole_infos.keys(): redis.create_lock(workspace, publ_type, publication, method) @@ -532,7 +532,7 @@ def delete_publications(workspace, { 'name': info["name"], 'title': info.get("title", None), - 'url': url_for(**{'endpoint': url_path, publ_param: publication[2], 'workspace': publication[0], 'x_forwarded_items': x_forwarded_items}), + 'url': info["url"], 'uuid': info["uuid"], 'access_rights': info['access_rights'], }