Skip to content

Commit

Permalink
GET Workspace Layers/Maps uses common.rest::get_publications
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Mar 18, 2021
1 parent aca1c54 commit b0c7892
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/layman/common/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ]

Expand All @@ -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'
},
Expand Down
22 changes: 4 additions & 18 deletions src/layman/layer/rest_workspace_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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'])
Expand Down
24 changes: 5 additions & 19 deletions src/layman/map/rest_workspace_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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'])
Expand Down

0 comments on commit b0c7892

Please sign in to comment.