Skip to content

Commit 3a1de2e

Browse files
authored
fix manager transaction evaluation (#1104)
1 parent 8778f50 commit 3a1de2e

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

pycsw/ogc/api/oapi.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import logging
3232

3333
from pycsw import __version__
34+
from pycsw.core.util import str2bool
3435
from pycsw.ogc.api.util import yaml_load
3536

3637
LOGGER = logging.getLogger(__name__)
@@ -429,7 +430,7 @@ def gen_oapi(config, oapi_filepath, mode='ogcapi-records'):
429430
}
430431
}
431432

432-
if config['manager'].get('transactions', False):
433+
if str2bool(config['manager'].get('transactions', False)):
433434
LOGGER.debug('Transactions enabled; adding post')
434435

435436
path['post'] = {
@@ -499,7 +500,7 @@ def gen_oapi(config, oapi_filepath, mode='ogcapi-records'):
499500
}
500501
}
501502

502-
if config['manager'].get('transactions', False):
503+
if str2bool(config['manager'].get('transactions', False)):
503504
LOGGER.debug('Transactions enabled; adding put/delete')
504505

505506
path['put'] = {

pycsw/ogc/api/records.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def landing_page(self, headers_, args):
286286
'type': 'application/json',
287287
'title': 'Main collection',
288288
'href': f"{self.config['server']['url']}/collections/metadata:main"
289-
},{
289+
}, {
290290
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/ogc-catalog',
291291
'type': 'application/json',
292292
'title': 'Record catalogue collection',
@@ -912,7 +912,7 @@ def manage_collection_item(self, headers_, action='create', item=None, data=None
912912
:returns: tuple of headers, status code, content
913913
"""
914914

915-
if not self.config['manager']['transactions']:
915+
if not str2bool(self.config['manager'].get('transactions', False)):
916916
return self.get_exception(
917917
405, headers_, 'InvalidParameterValue',
918918
'transactions not allowed')
@@ -1284,10 +1284,15 @@ def record2json(record, url, collection, mode='ogcapi-records'):
12841284
try:
12851285
for theme in json.loads(record.themes):
12861286
try:
1287-
ogcapi_themes.append({
1288-
'scheme': theme['thesaurus'].get('url') or theme['thesaurus'].get('title'),
1287+
theme_ = {
12891288
'concepts': [{'id': c.get('name', '')} for c in theme.get('keywords', []) if 'name' in c and c['name'] not in [None, '']]
1290-
})
1289+
}
1290+
if 'thesaurus' in theme:
1291+
theme_['scheme'] = theme['thesaurus'].get('url') or theme['thesaurus'].get('title'),
1292+
elif 'scheme' in theme:
1293+
theme_['scheme'] = theme['scheme']
1294+
1295+
ogcapi_themes.append(theme_)
12911296
except Exception as err:
12921297
LOGGER.exception(f"failed to parse theme of {record.identifier}: {err}")
12931298
except Exception as err:

pycsw/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ def _gen_soap_wrapper(self):
745745

746746
def _gen_manager(self):
747747
""" Update self.context.model with CSW-T advertising """
748-
if self.config['manager'].get('transactions', False):
748+
if util.str2bool(self.config['manager'].get('transactions', False)):
749749

750750
self.manager = True
751751

@@ -792,7 +792,7 @@ def _gen_manager(self):
792792
def _test_manager(self):
793793
""" Verify that transactions are allowed """
794794

795-
if not self.config['manager'].get('transactions', False):
795+
if not util.str2bool(self.config['manager'].get('transactions', False)):
796796
raise RuntimeError('CSW-T interface is disabled')
797797

798798
# get the client first forwarded ip

tests/functionaltests/suites/oarec/test_oarec_functional.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#
3232
# =================================================================
3333

34+
from copy import deepcopy
3435
import json
3536
from xml.etree import ElementTree as etree
3637

@@ -131,6 +132,7 @@ def test_items(config):
131132

132133
params = {'q': 'Lorem'}
133134
content = json.loads(api.items({}, None, params)[2])
135+
134136
assert content['numberMatched'] == 5
135137
assert content['numberReturned'] == 5
136138
assert len(content['features']) == content['numberReturned']
@@ -357,6 +359,33 @@ def test_json_transaction(config, sample_record):
357359

358360
assert status == 404
359361

362+
config2 = deepcopy(config)
363+
config2['manager']['transactions'] = False
364+
365+
api = API(config2)
366+
request_headers = {
367+
'Content-Type': 'application/json'
368+
}
369+
370+
# fail on insert record attempt
371+
headers, status, content = api.manage_collection_item(
372+
request_headers, 'create', data=sample_record)
373+
374+
assert status == 405
375+
376+
config2['manager']['transactions'] = 'false'
377+
378+
api = API(config2)
379+
request_headers = {
380+
'Content-Type': 'application/json'
381+
}
382+
383+
# fail on insert record attempt
384+
headers, status, content = api.manage_collection_item(
385+
request_headers, 'create', data=sample_record)
386+
387+
assert status == 405
388+
360389

361390
def test_xml_transaction(config):
362391
api = API(config)

0 commit comments

Comments
 (0)