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

868 patch workspace layer #921

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- [#765](https://github.com/LayerManager/layman/issues/765) Remove `authn.txt` files from workspace directories. The same information as in `authn.txt` files is saved in prime DB schema.
- [#868](https://github.com/LayerManager/layman/issues/868) Fill table `map_layer` with relations between maps and [internal layers](doc/models.md#internal-map-layer) (layers published on this Layman instance). Relations to [external layers](doc/models.md#internal-map-layer) (layers of other servers) are not imported into the table.
### Changes
- [#868](https://github.com/LayerManager/layman/issues/868) Endpoints [GET Publications](doc/rest.md#get-publications), [GET Layers](doc/rest.md#get-layers), [GET Workspace Layers](doc/rest.md#get-workspace-layers), [GET Maps](doc/rest.md#get-maps), [GET Workspace Maps](doc/rest.md#get-workspace-maps), [GET Workspace Layer](doc/rest.md#get-workspace-layer), [GET Workspace Map](doc/rest.md#get-workspace-map), [POST Workspace Layers](doc/rest.md#post-workspace-layers), [DELETE Workspace Layer](doc/rest.md#delete-workspace-layer), [DELETE Workspace Layers](doc/rest.md#delete-workspace-layers), [DELETE Workspace Map](doc/rest.md#delete-workspace-map), [DELETE Workspace Maps](doc/rest.md#delete-workspace-maps), [POST Workspace Maps](doc/rest.md#post-workspace-maps) and [WMS/WFS endpoints](doc/endpoints.md) respects [HTTP header `X-Forwarded-Prefix`](doc/client-proxy.md#x-forwarded-prefix-http-header) of the request in the response.
- [#868](https://github.com/LayerManager/layman/issues/868) Endpoints [GET Publications](doc/rest.md#get-publications), [GET Layers](doc/rest.md#get-layers), [GET Workspace Layers](doc/rest.md#get-workspace-layers), [GET Maps](doc/rest.md#get-maps), [GET Workspace Maps](doc/rest.md#get-workspace-maps), [GET Workspace Layer](doc/rest.md#get-workspace-layer), [GET Workspace Map](doc/rest.md#get-workspace-map), [POST Workspace Layers](doc/rest.md#post-workspace-layers), [DELETE Workspace Layer](doc/rest.md#delete-workspace-layer), [DELETE Workspace Layers](doc/rest.md#delete-workspace-layers), [DELETE Workspace Map](doc/rest.md#delete-workspace-map), [DELETE Workspace Maps](doc/rest.md#delete-workspace-maps), [POST Workspace Maps](doc/rest.md#post-workspace-maps), [PATCH Workspace Layer](doc/rest.md#patch-workspace-layer) and [WMS/WFS endpoints](doc/endpoints.md) respects [HTTP header `X-Forwarded-Prefix`](doc/client-proxy.md#x-forwarded-prefix-http-header) of the request in the response.
- [#868](https://github.com/LayerManager/layman/issues/868) Relations between map and [internal layers](doc/models.md#internal-map-layer) are updated in `map_layer` table when calling [POST Workspace Maps](doc/rest.md#post-workspace-maps), [DELETE Workspace Map](doc/rest.md#delete-workspace-map), and [DELETE Workspace Maps](doc/rest.md#delete-workspace-maps).
- [#880](https://github.com/LayerManager/layman/issues/880) Use Docker Compose v2 (`docker compose`) in Makefile without `compatibility` flag and remove `Makefile_docker-compose_v1` file. Docker containers are named according to Docker Compose v2 and may have different name after upgrade.
- [#765](https://github.com/LayerManager/layman/issues/765) Stop saving OAuth2 claims in filesystem, use prime DB schema only.
Expand Down
7 changes: 7 additions & 0 deletions doc/client-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ Currently, value of `X-Forwarded-Prefix` affects following URLs:
* `url` key
* [POST Workspace Maps](rest.md#post-workspace-maps)
* `url` key
* [PATCH Workspace Layer](rest.md#patch-workspace-layer)
* `url` key
* `wms`.`url` key
* `wfs`.`url` key
* `style`.`url` key
* `thumbnail`.`url` key
* `metadata`.`comparison_url` key
* [OGC endpoints](endpoints.md)
* Headers `X-Forwarded-Proto`, `X-Forwarded-Host`, `X-Forwarded-For`, `X-Forwarded-Path`, `Forwarded` and `Host` are ignored
* [WMS endpoints](endpoints.md#web-map-service)
Expand Down
4 changes: 3 additions & 1 deletion src/layman/layer/rest_workspace_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def get(workspace, layername):
def patch(workspace, layername):
app.logger.info(f"PATCH Layer, actor={g.user}")

x_forwarded_prefix = layman_util.get_x_forwarded_prefix(request.headers)

info = layman_util.get_publication_info(workspace, LAYER_TYPE, layername,
context={'keys': ['title', 'name', 'description', 'table_uri', 'geodata_type', 'style_type',
'original_data_source', ]})
Expand Down Expand Up @@ -260,7 +262,7 @@ def patch(workspace, layername):
)

app.logger.info('PATCH Layer changes done')
info = util.get_complete_layer_info(workspace, layername)
info = util.get_complete_layer_info(workspace, layername, x_forwarded_prefix=x_forwarded_prefix)
info.update(layer_result)

return jsonify(info), 200
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from layman import settings
from tests import EnumTestTypes
from tests import EnumTestTypes, Publication
from tests.dynamic_data import base_test, base_test_classes
from tests.dynamic_data.publications import common_publications
from tests import Publication
from test_tools import assert_util

pytest_generate_tests = base_test.pytest_generate_tests


class RestMethodLocal(base_test_classes.RestMethodBase):
POST = ('post_publication', 'post')
DELETE = ('delete_workspace_publication', 'delete')
MULTI_DELETE = ('delete_workspace_publications', 'multi_delete')


class PublicationTypes(base_test_classes.PublicationByDefinitionBase):
LAYER = (common_publications.LAYER_VECTOR_SLD, 'layer')
MAP = (common_publications.MAP_EMPTY, 'map')
Expand All @@ -23,7 +17,7 @@ class TestPublication(base_test.TestSingleRestPublication):
publication_type = None

rest_parametrization = [
RestMethodLocal,
base_test_classes.RestMethodAll,
PublicationTypes,
]

Expand All @@ -32,11 +26,44 @@ class TestPublication(base_test.TestSingleRestPublication):
publ_def.type,
None),
type=EnumTestTypes.MANDATORY,
specific_types={
(base_test_classes.RestMethodAll.PATCH, PublicationTypes.MAP): EnumTestTypes.IGNORE,
}
)]

@staticmethod
def test_publication(publication, rest_method):
def test_publication(self, publication, rest_method):
proxy_prefix = '/layman-proxy'
response = rest_method(publication, args={'headers': {'X-Forwarded-Prefix': proxy_prefix}})
publication_response = response[0] if isinstance(response, list) and len(response) == 1 else response
assert publication_response['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}'
if rest_method == self.patch_publication: # pylint: disable=W0143
exp_resp = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}',
'thumbnail': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/thumbnail'
},
'metadata': {
'comparison_url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/metadata-comparison',
},
'wms': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/geoserver/{publication.workspace}_wms/ows',
},
'sld': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/style',
},
'style': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/style',
},
}

geodata_type = response['geodata_type']
if geodata_type == settings.GEODATA_TYPE_VECTOR:
exp_resp['wfs'] = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/geoserver/{publication.workspace}/wfs'
}
else:
exp_resp = {'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}'}

assert_util.assert_same_values_for_keys(
expected=exp_resp,
tested=publication_response,
)