Skip to content

Commit

Permalink
Add updated_at to REST responses
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Mar 18, 2021
1 parent 97a421f commit 9336481
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 5 deletions.
6 changes: 6 additions & 0 deletions doc/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ JSON array of objects representing available layers with following structure:
- **title**: String. Title of the layer.
- **uuid**: String. UUID of the layer.
- **url**: String. URL of the layer. It points to [GET Workspace Layer](#get-workspace-layer).
- **updated_at**: String. Date and time of last POST/PATCH of the publication. Format is [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601), more specifically `YYYY-MM-DDThh:mm:ss.sss±hh:mm`, always in UTC. Sample value: `"2021-03-18T09:29:53.769233+00:00"`
- **access_rights**:
- **read**: Array of strings. Names of [users](./models.md#user) and [roles](./models.md#role) with [read access](./security.md#Authorization).
- **write**: Array of strings. Names of [users](./models.md#user) and [roles](./models.md#role) with [write access](./security.md#Authorization).
Expand All @@ -72,6 +73,7 @@ JSON array of objects representing available layers with following structure:
- **title**: String. Title of the layer.
- **uuid**: String. UUID of the layer.
- **url**: String. URL of the layer. It points to [GET Workspace Layer](#get-workspace-layer).
- **updated_at**: String. Date and time of last POST/PATCH of the publication. Format is [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601), more specifically `YYYY-MM-DDThh:mm:ss.sss±hh:mm`, always in UTC. Sample value: `"2021-03-18T09:29:53.769233+00:00"`
- **access_rights**:
- **read**: Array of strings. Names of [users](./models.md#user) and [roles](./models.md#role) with [read access](./security.md#Authorization).
- **write**: Array of strings. Names of [users](./models.md#user) and [roles](./models.md#role) with [write access](./security.md#Authorization).
Expand Down Expand Up @@ -196,6 +198,7 @@ JSON object with following structure:
- **url**: String. URL pointing to this endpoint.
- **title**: String.
- **description**: String.
- **updated_at**: String. Date and time of last POST/PATCH of the publication. Format is [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601), more specifically `YYYY-MM-DDThh:mm:ss.sss±hh:mm`, always in UTC. Sample value: `"2021-03-18T09:29:53.769233+00:00"`
- **wms**
- *url*: String. URL of WMS endpoint. It points to WMS endpoint of appropriate GeoServer workspace.
- *status*: Status information about GeoServer import and availability of WMS layer. No status object means the source is available. Usual state values are
Expand Down Expand Up @@ -412,6 +415,7 @@ JSON array of objects representing available maps with following structure:
- **title**: String. Title of the map.
- **uuid**: String. UUID of the map.
- **url**: String. URL of the map. It points to [GET Workspace Map](#get-workspace-map).
- **updated_at**: String. Date and time of last POST/PATCH of the publication. Format is [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601), more specifically `YYYY-MM-DDThh:mm:ss.sss±hh:mm`, always in UTC. Sample value: `"2021-03-18T09:29:53.769233+00:00"`
- **access_rights**:
- **read**: Array of strings. Names of [users](./models.md#user) and [roles](./models.md#role) with [read access](./security.md#Authorization).
- **write**: Array of strings. Names of [users](./models.md#user) and [roles](./models.md#role) with [write access](./security.md#Authorization).
Expand All @@ -435,6 +439,7 @@ JSON array of objects representing available maps with following structure:
- **title**: String. Title of the map.
- **uuid**: String. UUID of the map.
- **url**: String. URL of the map. It points to [GET Workspace Map](#get-workspace-map).
- **updated_at**: String. Date and time of last POST/PATCH of the publication. Format is [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601), more specifically `YYYY-MM-DDThh:mm:ss.sss±hh:mm`, always in UTC. Sample value: `"2021-03-18T09:29:53.769233+00:00"`
- **access_rights**:
- **read**: Array of strings. Names of [users](./models.md#user) and [roles](./models.md#role) with [read access](./security.md#Authorization).
- **write**: Array of strings. Names of [users](./models.md#user) and [roles](./models.md#role) with [write access](./security.md#Authorization).
Expand Down Expand Up @@ -527,6 +532,7 @@ JSON object with following structure:
- **url**: String. URL pointing to this endpoint.
- **title**: String. Taken from `title` attribute of JSON root object
- **description**: String. Taken from `abstract` attribute of JSON root object.
- **updated_at**: String. Date and time of last POST/PATCH of the publication. Format is [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601), more specifically `YYYY-MM-DDThh:mm:ss.sss±hh:mm`, always in UTC. Sample value: `"2021-03-18T09:29:53.769233+00:00"`
- **file**
- *url*: String. URL of map-composition JSON file. It points to [GET Workspace Map File](#get-workspace-map-file).
- *path*: String. Path to map-composition JSON file, relative to workspace directory.
Expand Down
4 changes: 3 additions & 1 deletion src/layman/common/prime_db_schema/publications.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def get_publication_infos(workspace_name=None, pub_type=None, style_type=None,
p.title,
p.uuid::text,
p.style_type,
p.updated_at,
(select rtrim(concat(case when u.id is not null then w.name || ',' end,
string_agg(w2.name, ',') || ',',
case when p.everyone_can_read then %s || ',' end
Expand Down Expand Up @@ -130,10 +131,11 @@ def get_publication_infos(workspace_name=None, pub_type=None, style_type=None,
'uuid': uuid,
'type': type,
'style_type': style_type,
'updated_at': updated_at,
'access_rights': {'read': [x for x in can_read_users.split(',')],
'write': [x for x in can_write_users.split(',')]}
}
for id_publication, workspace_name, type, publication_name, title, uuid, style_type, can_read_users, can_write_users
for id_publication, workspace_name, type, publication_name, title, uuid, style_type, updated_at, can_read_users, can_write_users
in values}
return infos

Expand Down
1 change: 1 addition & 0 deletions src/layman/common/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def get_publications(publication_type, user, request_args):
'url': layman_util.get_workspace_publication_url(publication_type, workspace, name),
'uuid': info["uuid"],
'access_rights': info['access_rights'],
'updated_at': info['updated_at'].isoformat(),
}
for (workspace, _, name), info in publication_infos_whole.items()
]
Expand Down
1 change: 1 addition & 0 deletions src/layman/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ def clear_publication_info(info):
del info[key]
except KeyError:
pass
info['updated_at'] = info['updated_at'].isoformat()
return info
1 change: 1 addition & 0 deletions src/layman/layer/rest_workspace_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def get(username):
'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()
Expand Down
1 change: 1 addition & 0 deletions src/layman/map/rest_workspace_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get(username):
'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()
Expand Down
20 changes: 16 additions & 4 deletions src/layman/rest_publication_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import datetime
from dateutil.parser import parse

from test import process_client
from layman import LaymanError, settings, app
Expand Down Expand Up @@ -133,8 +134,13 @@ def test_updated_at(publication_type):
with app.app_context():
results = db_util.run_query(query, (workspace, publication_type, publication))
assert len(results) == 1 and len(results[0]) == 1, results
updated_at = results[0][0]
assert timestamp1 < updated_at < timestamp2
updated_at_db = results[0][0]
assert timestamp1 < updated_at_db < timestamp2

info = process_client.get_workspace_publication(publication_type, workspace, publication)
updated_at_rest_str = info['updated_at']
updated_at_rest = parse(updated_at_rest_str)
assert timestamp1 < updated_at_rest < timestamp2

timestamp3 = datetime.datetime.now(datetime.timezone.utc)
process_client.patch_workspace_publication(publication_type, workspace, publication, title='Title')
Expand All @@ -143,6 +149,12 @@ def test_updated_at(publication_type):
with app.app_context():
results = db_util.run_query(query, (workspace, publication_type, publication))
assert len(results) == 1 and len(results[0]) == 1, results
updated_at = results[0][0]
assert timestamp3 < updated_at < timestamp4
updated_at_db = results[0][0]
assert timestamp3 < updated_at_db < timestamp4

info = process_client.get_workspace_publication(publication_type, workspace, publication)
updated_at_rest_str = info['updated_at']
updated_at_rest = parse(updated_at_rest_str)
assert timestamp3 < updated_at_rest < timestamp4

process_client.delete_workspace_publication(publication_type, workspace, publication)
2 changes: 2 additions & 0 deletions src/layman/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ def test_get_publication_infos(publication_type):
for publication_name in publication_infos:
if publication_infos[publication_name].get('id'):
del publication_infos[publication_name]['id']
if publication_infos[publication_name].get('updated_at'):
del publication_infos[publication_name]['updated_at']
assert publication_infos == expected_result, (publication_infos, expected_result)

process_client.delete_workspace_publication(publication_type, workspace, publication)
Expand Down

0 comments on commit 9336481

Please sign in to comment.