Skip to content

Commit

Permalink
Publication url can be gotten from prime_db_schema source
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Dec 18, 2024
1 parent e9bb9c5 commit 8d2ef73
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 24 deletions.
10 changes: 7 additions & 3 deletions src/layman/common/prime_db_schema/publications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.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,
Expand All @@ -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 []

Expand Down Expand Up @@ -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, _
Expand Down
5 changes: 3 additions & 2 deletions src/layman/common/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/layman/layer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[]),),
Expand Down
6 changes: 3 additions & 3 deletions src/layman/layer/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/layman/layer/rest_workspace_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand Down
2 changes: 0 additions & 2 deletions src/layman/layer/rest_workspace_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions src/layman/layer/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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': '',
})
Expand Down
4 changes: 2 additions & 2 deletions src/layman/map/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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],
Expand Down
2 changes: 0 additions & 2 deletions src/layman/map/rest_workspace_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
1 change: 0 additions & 1 deletion src/layman/map/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '',
}
Expand Down
8 changes: 4 additions & 4 deletions src/layman/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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'],
}
Expand Down

0 comments on commit 8d2ef73

Please sign in to comment.