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

541 sync permission error #547

Merged
merged 2 commits into from
Nov 21, 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
14 changes: 11 additions & 3 deletions spinta/datasets/keymaps/synchronize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from typer import echo
from typing import List

from spinta.auth import authorized
Expand All @@ -18,16 +19,23 @@ def sync_keymap(context: Context, keymap: KeyMap, client, server: str, models: L
counters = {
'_total': tqdm.tqdm(desc='SYNCHRONIZING KEYMAP', ascii=True)
}
echo()

for model in models:
model_keymaps = [model.model_type()]
for combination in model.required_keymap_properties:
model_keymaps.append(f'{model.model_type()}.{"_".join(combination)}')
primary_keys = model.external.pkeys
skip_model = False
for key in primary_keys:
is_authorized = authorized(context, key, action=Action.SEARCH)
if not is_authorized:
raise UnauthorizedKeymapSync(model)
echo(f"SKIPPED '{model.model_type()}' MODEL SYNC, NO PERMISSION.")
skip_model = True
break
if skip_model:
continue

for combination in model.required_keymap_properties:
model_keymaps.append(f'{model.model_type()}.{"_".join(combination)}')

# Get min cid (in case new model was added, or models are out of sync)
sync_cid = 0
Expand Down
1 change: 1 addition & 0 deletions tests/cli/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ def test_push_sync(
assert listdata(resp_city, '_id', 'id', 'name', 'country')[0] == (city_id, 1, 'Vilnius', {'_id': country_id})


@pytest.mark.skip("Private now sends warning that model has been skipped syncing rather throwing exception")
def test_push_sync_to_private_error(
postgresql,
rc: RawConfig,
Expand Down