diff --git a/src/layman/common/rest.py b/src/layman/common/rest.py index 7d663077e..8681c2419 100644 --- a/src/layman/common/rest.py +++ b/src/layman/common/rest.py @@ -102,7 +102,7 @@ def setup_post_access_rights(request_form, kwargs, actor_name): kwargs['access_rights'][type] = access_rights -def get_publications(publication_type, user, request_args=None): +def get_publications(publication_type, user, request_args=None, workspace=None): request_args = request_args or {} known_order_by_values = [consts.ORDER_BY_TITLE, consts.ORDER_BY_FULL_TEXT, consts.ORDER_BY_LAST_CHANGE, ] @@ -129,6 +129,7 @@ def get_publications(publication_type, user, request_args=None): order_by_list = [consts.ORDER_BY_FULL_TEXT] publication_infos_whole = layman_util.get_publication_infos(publ_type=publication_type, + workspace=workspace, context={'actor_name': user, 'access_type': 'read' }, diff --git a/src/layman/layer/rest_workspace_layers.py b/src/layman/layer/rest_workspace_layers.py index d2cef1ccf..fee7cfef3 100644 --- a/src/layman/layer/rest_workspace_layers.py +++ b/src/layman/layer/rest_workspace_layers.py @@ -7,9 +7,9 @@ from layman import settings, authn, util as layman_util from . import util, LAYER_TYPE, LAYER_REST_PATH_NAME from .filesystem import input_file, input_style, input_chunk, uuid -from layman.authn import authenticate +from layman.authn import authenticate, get_authn_username from layman.authz import authorize_workspace_publications_decorator -from layman.common import redis as redis_util +from layman.common import redis as redis_util, rest as rest_common bp = Blueprint('rest_workspace_layers', __name__) @@ -32,22 +32,8 @@ def after_request(response): def get(username): app.logger.info(f"GET Layers, user={g.user}") - layer_infos_whole = layman_util.get_publication_infos(username, LAYER_TYPE) - - infos = [ - { - 'name': info["name"], - 'workspace': workspace, - 'title': info.get("title", None), - 'url': url_for('rest_workspace_layer.get', layername=name, username=username), - 'uuid': info["uuid"], - 'updated_at': info['updated_at'].isoformat(), - 'access_rights': info['access_rights'], - } - for (workspace, publication_type, name), info in layer_infos_whole.items() - ] - sorted_infos = sorted(infos, key=lambda x: x['name']) - return jsonify(sorted_infos), 200 + user = get_authn_username() or settings.ANONYM_USER + return rest_common.get_publications(LAYER_TYPE, user, workspace=username) @bp.route(f"/{LAYER_REST_PATH_NAME}", methods=['POST']) diff --git a/src/layman/map/rest_workspace_maps.py b/src/layman/map/rest_workspace_maps.py index 7752150a0..72a5f1ca7 100644 --- a/src/layman/map/rest_workspace_maps.py +++ b/src/layman/map/rest_workspace_maps.py @@ -9,10 +9,10 @@ from layman.util import check_username_decorator, url_for from . import util, MAP_TYPE, MAP_REST_PATH_NAME from .filesystem import input_file, uuid -from layman import authn, util as layman_util -from layman.authn import authenticate +from layman import authn, util as layman_util, settings +from layman.authn import authenticate, get_authn_username from layman.authz import authorize_workspace_publications_decorator -from layman.common import redis as redis_util +from layman.common import redis as redis_util, rest as rest_common bp = Blueprint('rest_workspace_maps', __name__) @@ -35,22 +35,8 @@ def after_request(response): def get(username): app.logger.info(f"GET Maps, user={g.user}") - mapinfos_whole = layman_util.get_publication_infos(username, MAP_TYPE) - - infos = [ - { - 'name': info["name"], - 'workspace': workspace, - 'title': info.get("title", None), - 'url': url_for('rest_workspace_map.get', mapname=name, username=username), - 'uuid': info['uuid'], - 'updated_at': info['updated_at'].isoformat(), - 'access_rights': info['access_rights'], - } - for (workspace, publication_type, name), info in mapinfos_whole.items() - ] - sorted_infos = sorted(infos, key=lambda x: x['name']) - return jsonify(sorted_infos), 200 + user = get_authn_username() or settings.ANONYM_USER + return rest_common.get_publications(MAP_TYPE, user, workspace=username) @bp.route(f"/{MAP_REST_PATH_NAME}", methods=['POST'])