Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATCH Workspace Layer/Map returns only short response #1027

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .remarkrc
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@
"lint-no-dead-urls": {
"skipLocalhost": true,
"deadOrAliveOptions": {
"timeout": 20000,
"maxRetries": 2
"timeout": 30000,
"maxRetries": 3
},
"skipUrlPatterns": [
"https://security.stackexchange.com",
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
#### Schema migrations
#### Data migrations
### Changes
- [#1009](https://github.com/LayerManager/layman/issues/1009) PATCH Workspace [Layer](doc/rest.md#patch-workspace-layer)/[Map](doc/rest.md#patch-workspace-map) returns same response as POST Workspace [Layers](doc/rest.md#post-workspace-layers)/[Maps](doc/rest.md#post-workspace-maps) with only `name`, `uuid`, `url` and for Layer also optional `files_to_upload` keys.
- [#1028](https://github.com/LayerManager/layman/issues/1028) Upgrade Node.js of Laymen Test Client from v18 to v22 and dependencies:
- eslint-config-next 13 -> 14
- next 13 -> 14
5 changes: 2 additions & 3 deletions doc/rest.md
Original file line number Diff line number Diff line change
@@ -429,8 +429,7 @@ Body parameters:
#### Response
Content-Type: `application/json`

JSON object, same as in case of [GET Workspace Layer](#get-workspace-layer), possibly extended with one extra property:
- *files_to_upload*: List of objects. It's present only if **file** parameter contained file names. See [POST Workspace Layers](#post-workspace-layers) response to find out more.
JSON object, same as in case of [POST Workspace Layers](#post-workspace-layers).

### DELETE Workspace Layer
Delete existing layer and all associated sources except external DB table published using `external_table_uri`. So it deletes e.g. data file, vector internal DB table or normalized raster file. The currently running [asynchronous tasks](async-tasks.md) of affected layer are aborted.
@@ -710,7 +709,7 @@ Body parameters:
#### Response
Content-Type: `application/json`

JSON object, same as in case of [GET Workspace Map](#get-workspace-map).
JSON object, same as in case of [POST Workspace Maps](#post-workspace-maps).

### DELETE Workspace Map
Delete existing map and all associated sources, including map-composition JSON file and map thumbnail. The currently running [asynchronous tasks](async-tasks.md) of affected map are aborted.
6 changes: 5 additions & 1 deletion src/layman/layer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from enum import Enum
from collections import namedtuple, OrderedDict

from layman import settings
@@ -30,6 +29,10 @@ def get_layer_info_keys(*, geodata_type, original_data_source):
return result


def get_layer_patch_keys():
return get_layer_type_def()['patch_keys']


LAYER_REST_PATH_NAME = "layers"


@@ -132,6 +135,7 @@ def get_layer_info_keys(*, geodata_type, original_data_source):
},
},
'multi_info_keys_to_remove': [],
'patch_keys': ['name', 'uuid', 'url', 'files_to_upload'],
}
}

7 changes: 5 additions & 2 deletions src/layman/layer/rest_workspace_layer.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
from layman import settings, authn, util as layman_util
from layman.authn import authenticate
from layman.authz import authorize_workspace_publications_decorator
from . import util, LAYER_REST_PATH_NAME, LAYER_TYPE
from . import util, LAYER_REST_PATH_NAME, LAYER_TYPE, get_layer_patch_keys
from .filesystem import input_file, input_style, input_chunk, util as fs_util

bp = Blueprint('rest_workspace_layer', __name__)
@@ -262,8 +262,11 @@ def patch(workspace, layername):
)

app.logger.info('PATCH Layer changes done')
info = util.get_complete_layer_info(workspace, layername, x_forwarded_items=x_forwarded_items)
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'] = layman_util.get_workspace_publication_url(info['type'], workspace, layername, x_forwarded_items=x_forwarded_items)
info.update(layer_result)
info = {key: value for key, value in info.items() if key in patch_keys}

return jsonify(info), 200

14 changes: 7 additions & 7 deletions src/layman/layer/rest_workspace_test.py
Original file line number Diff line number Diff line change
@@ -657,9 +657,9 @@ def test_patch_layer_title(client):
chain_info = util.get_layer_chain(workspace, layername)
assert chain_info is not None and celery_util.is_chain_ready(chain_info)

resp_json = response.get_json()
assert resp_json['title'] == new_title
assert resp_json['description'] == new_description
get_json = client.get(rest_path).get_json()
assert get_json['title'] == new_title
assert get_json['description'] == new_description

with app.app_context():
expected_md_values = {
@@ -716,8 +716,8 @@ def test_patch_layer_style(client):
flask_client.wait_till_layer_ready(workspace, layername)
# last_task['last'].get()

resp_json = response.get_json()
assert resp_json['title'] == "countries in blue"
get_json = client.get(rest_path).get_json()
assert get_json['title'] == "countries in blue"

wms_url = geoserver_wms.get_wms_url(workspace)
wms = wms_proxy(wms_url)
@@ -772,10 +772,10 @@ def test_patch_layer_data(client):

chain_info = util.get_layer_chain(workspace, layername)
assert chain_info is not None and not celery_util.is_chain_ready(chain_info)
resp_json = response.get_json()
get_json = client.get(rest_path).get_json()
keys_to_check = ['db', 'wms', 'wfs', 'thumbnail', 'metadata']
for key_to_check in keys_to_check:
assert 'status' in resp_json[key_to_check]
assert 'status' in get_json[key_to_check]
flask_client.wait_till_layer_ready(workspace, layername)
# last_task['last'].get()

5 changes: 5 additions & 0 deletions src/layman/map/__init__.py
Original file line number Diff line number Diff line change
@@ -19,6 +19,10 @@ def get_map_info_keys():
return get_map_type_def()['info_keys']


def get_map_patch_keys():
return get_map_type_def()['patch_keys']


MAP_REST_PATH_NAME = "maps"


@@ -81,6 +85,7 @@ def get_map_info_keys():
'info_keys': {'name', 'uuid', 'layman_metadata', 'url', 'title', 'description', 'updated_at',
'thumbnail', 'file', 'metadata', 'access_rights', 'bounding_box', },
'multi_info_keys_to_remove': ['file', 'geodata_type', 'wfs_wms_status', ],
'patch_keys': ['name', 'uuid', 'url'],
}
}

7 changes: 5 additions & 2 deletions src/layman/map/rest_workspace_map.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
from layman.util import check_workspace_name_decorator
from layman.authn import authenticate
from layman.authz import authorize_workspace_publications_decorator
from . import util, MAP_REST_PATH_NAME
from . import util, MAP_REST_PATH_NAME, get_map_patch_keys
from .filesystem import input_file, thumbnail

bp = Blueprint('rest_workspace_map', __name__)
@@ -108,7 +108,10 @@ def patch(workspace, mapname):
'layman.map.filesystem.input_file' if file_changed else None
)

info = util.get_complete_map_info(workspace, mapname, x_forwarded_items=x_forwarded_items)
patch_keys = get_map_patch_keys()
info = util.get_map_info(workspace, mapname, context={'keys': patch_keys, 'x_forwarded_items': x_forwarded_items})
info['url'] = layman_util.get_workspace_publication_url(info['type'], workspace, mapname, x_forwarded_items=x_forwarded_items)
info = {key: value for key, value in info.items() if key in patch_keys}

return jsonify(info), 200

21 changes: 11 additions & 10 deletions src/layman/map/rest_workspace_test.py
Original file line number Diff line number Diff line change
@@ -456,13 +456,14 @@ def test_patch_map(client):

assert resp_json['uuid'] == uuid_str
assert resp_json['url'] == url_for_external('rest_workspace_map.get', workspace=workspace, mapname=mapname)
assert resp_json['title'] == "Jiné administrativn\u00ed \u010dlen\u011bn\u00ed Libereck\u00e9ho kraje"
assert resp_json['description'] == "Jiný popis"
map_file = resp_json['file']
get_json = client.get(rest_path).get_json()
assert get_json['title'] == "Jiné administrativn\u00ed \u010dlen\u011bn\u00ed Libereck\u00e9ho kraje"
assert get_json['description'] == "Jiný popis"
map_file = get_json['file']
assert 'status' not in map_file
assert 'path' in map_file
assert map_file['url'] == url_for_external('rest_workspace_map_file.get', workspace=workspace, mapname=mapname)
thumbnail = resp_json['thumbnail']
thumbnail = get_json['thumbnail']
assert 'status' in thumbnail
assert thumbnail['status'] in ['PENDING', 'STARTED']

@@ -510,19 +511,19 @@ def test_patch_map(client):
'title': title,
})
assert response.status_code == 200, response.get_json()
resp_json = response.get_json()
assert resp_json['title'] == "Nový název"
assert resp_json['description'] == "Jiný popis"
get_json = client.get(rest_path).get_json()
assert get_json['title'] == "Nový název"
assert get_json['description'] == "Jiný popis"

with app.app_context():
description = 'Nový popis'
response = client.patch(rest_path, data={
'description': description,
})
assert response.status_code == 200
resp_json = response.get_json()
assert resp_json['title'] == "Nový název"
assert resp_json['description'] == "Nový popis"
get_json = client.get(rest_path).get_json()
assert get_json['title'] == "Nový název"
assert get_json['description'] == "Nový popis"

uuid.check_redis_consistency(expected_publ_num_by_type={
f'{MAP_TYPE}': publication_counter.get()
6 changes: 6 additions & 0 deletions test_tools/process_client.py
Original file line number Diff line number Diff line change
@@ -296,6 +296,12 @@ def patch_workspace_publication(publication_type,
)
raise_layman_error(response)

assert response.json()['name'] == name or not name, f'name={name}, response.name={response.json()[0]["name"]}'
expected_resp_keys = ['name', 'uuid', 'url']
if with_chunks:
expected_resp_keys.append('files_to_upload')
assert all(key in response.json() for key in expected_resp_keys), f'name={name}, response.name={response.json()[0]["name"]}'

if with_chunks and not do_not_upload_chunks:
upload_file_chunks(publication_type,
workspace,