Skip to content

Commit

Permalink
Fix patch saving map file before access right validation
Browse files Browse the repository at this point in the history
(cherry picked from commit 629ad6c)
  • Loading branch information
index-git authored and jirik committed Nov 9, 2023
1 parent 740c305 commit 46b9af0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/layman/map/rest_workspace_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ def patch(workspace, mapname):

props_to_refresh = util.get_same_or_missing_prop_names(workspace, mapname)
metadata_properties_to_refresh = props_to_refresh
if file is not None:
thumbnail.delete_map(workspace, mapname)
file = FileStorage(
io.BytesIO(json.dumps(file_json).encode()),
file.filename
)
input_file.save_map_files(
workspace, mapname, [file])

file_changed = file is not None
kwargs = {
'title': title,
Expand All @@ -101,6 +92,15 @@ def patch(workspace, mapname):
kwargs,
)

if file is not None:
thumbnail.delete_map(workspace, mapname)
file = FileStorage(
io.BytesIO(json.dumps(file_json).encode()),
file.filename
)
input_file.save_map_files(
workspace, mapname, [file])

util.patch_map(
workspace,
mapname,
Expand Down
2 changes: 2 additions & 0 deletions test_tools/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def oauth2_provider_mock():
'dynamic_test_layer_patch_without_data_user': None,
'test_fix_issuer_id_user': None,
'layer_map_relation_user': None,
'wrong_input_owner': None,
'wrong_input_editor': None,
},
},
'host': '0.0.0.0',
Expand Down
50 changes: 46 additions & 4 deletions tests/dynamic_data/publications/wrong_input/wrong_input_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ class Key(Enum):
RUN_ONLY_CASES = 'run_only_cases'
SPECIFIC_CASES = 'specific_params'
POST_BEFORE_TEST_ARGS = 'post_before_test_args'
WORKSPACE = 'workspace'


WORKSPACE = 'dynamic_test_workspace_wrong_input'
OWNER = 'wrong_input_owner'
EDITOR = 'wrong_input_editor'


ALL_CASES = frozenset([RestMethod, WithChunksDomain, CompressDomain])
Expand Down Expand Up @@ -1312,6 +1315,44 @@ class Key(Enum):
Key.RUN_ONLY_CASES: frozenset([RestMethod, WithChunksDomain.FALSE, CompressDomain.FALSE]),
Key.SPECIFIC_CASES: {},
},
# issue 952
'patch_map_write_rights_without_owner': {
Key.PUBLICATION_TYPE: process_client.MAP_TYPE,
Key.WORKSPACE: OWNER,
Key.POST_BEFORE_TEST_ARGS: {
'access_rights': {
'read': 'EVERYONE',
'write': 'EVERYONE',
},
'actor_name': OWNER,
},
Key.REST_ARGS: {
'file_paths': ['sample/layman.map/small_map.json'],
'access_rights': {
'read': 'EVERYONE',
'write': EDITOR,
},
'actor_name': EDITOR,
},
Key.EXCEPTION: LaymanError,
Key.EXPECTED_EXCEPTION: {
'http_code': 400,
'sync': True,
'code': 43,
'message': 'Wrong access rights.',
'data': {
'access_rights': {'read': ['EVERYONE'], 'write': ['wrong_input_editor']},
'message': 'Owner of the personal workspace have to keep write right.',
'actor_name': 'wrong_input_editor',
'owner': 'wrong_input_owner',
'publication_name': 'patch_map_write_rights_without_owner_patch',
'workspace_name': 'wrong_input_owner'
},
},
Key.MANDATORY_CASES: frozenset([RestMethod.PATCH, WithChunksDomain.FALSE, CompressDomain.FALSE]),
Key.RUN_ONLY_CASES: frozenset([RestMethod.PATCH, WithChunksDomain.FALSE, CompressDomain.FALSE]),
Key.SPECIFIC_CASES: {},
},
}


Expand All @@ -1335,10 +1376,10 @@ def generate_test_cases():
publ_type = all_params.pop(Key.PUBLICATION_TYPE)

publication_name = rest_args.pop('name', None)
publication = Publication(workspace=WORKSPACE,
publication = Publication(workspace=test_case_params.get(Key.WORKSPACE, WORKSPACE),
type=publ_type,
name=publication_name,
) if publication_name else None
name=publication_name if publication_name else None,
)

test_case = base_test.TestCaseType(key=key,
publication=publication,
Expand All @@ -1356,11 +1397,12 @@ def generate_test_cases():
return tc_list


@pytest.mark.usefixtures('ensure_external_db')
@pytest.mark.usefixtures('ensure_external_db', 'oauth2_provider_mock')
class TestPublication(base_test.TestSingleRestPublication):
workspace = WORKSPACE
test_cases = generate_test_cases()
publication_type = None
usernames_to_reserve = [OWNER, EDITOR]
rest_parametrization = [
RestMethod,
WithChunksDomain,
Expand Down

0 comments on commit 46b9af0

Please sign in to comment.