Skip to content

Commit 923030e

Browse files
MarcelGeowonder-sk
authored andcommitted
Updated:
- filter only qgis files from changes and conflicted copy
1 parent 2d72fc0 commit 923030e

File tree

2 files changed

+21
-80
lines changed

2 files changed

+21
-80
lines changed

mergin/editor.py

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,7 @@
1111
Returns:
1212
bool: True if the file change should be disallowed, False otherwise.
1313
"""
14-
disallowed_added_changes: Callable[[dict], bool] = lambda change: is_qgis_file(change["path"]) or is_mergin_config(
15-
change["path"]
16-
)
17-
"""
18-
Determines whether a given file change should be disallowed from being updated.
19-
20-
The function checks the following conditions:
21-
- If the file path matches a QGIS file
22-
- If the file path matches a Mergin configuration file
23-
- If the file is versioned and the change does not have a diff
24-
25-
Returns:
26-
bool: True if the change should be disallowed, False otherwise.
27-
"""
28-
_disallowed_updated_changes: Callable[[dict], bool] = (
29-
lambda change: is_qgis_file(change["path"])
30-
or is_mergin_config(change["path"])
31-
or (is_versioned_file(change["path"]) and change.get("diff") is None)
32-
)
33-
"""
34-
Determines whether a given file change should be disallowed from being removed.
35-
36-
The function checks if the file path of the change matches any of the following conditions:
37-
- The file is a QGIS file (e.g. .qgs, .qgz)
38-
- The file is a Mergin configuration file (mergin-config.json)
39-
- The file is a versioned file (.gpkg, .sqlite)
40-
41-
If any of these conditions are met, the change is considered disallowed from being removed.
42-
"""
43-
_disallowed_removed_changes: Callable[[dict], bool] = (
44-
lambda change: is_qgis_file(change["path"]) or is_mergin_config(change["path"]) or is_versioned_file(change["path"])
45-
)
14+
_disallowed_changes: Callable[[dict], bool] = lambda change: is_qgis_file(change["path"])
4615

4716

4817
def is_editor_enabled(mc, project_info: dict) -> bool:
@@ -65,14 +34,9 @@ def _apply_editor_filters(changes: dict[str, list[dict]]) -> dict[str, list[dict
6534
Returns:
6635
dict[str, list[dict]]: The filtered changes dictionary.
6736
"""
68-
added = changes.get("added", [])
6937
updated = changes.get("updated", [])
70-
removed = changes.get("removed", [])
7138

72-
# filter out files that are not in the editor's list of allowed files
73-
changes["added"] = list(filterfalse(disallowed_added_changes, added))
74-
changes["updated"] = list(filterfalse(_disallowed_updated_changes, updated))
75-
changes["removed"] = list(filterfalse(_disallowed_removed_changes, removed))
39+
changes["updated"] = list(filterfalse(_disallowed_changes, updated))
7640
return changes
7741

7842

@@ -106,4 +70,4 @@ def prevent_conflicted_copy(path: str, mc, project_info: dict) -> bool:
10670
Returns:
10771
bool: True if the file path should be prevented from ceating conflicted copy, False otherwise.
10872
"""
109-
return is_editor_enabled(mc, project_info) and any([is_qgis_file(path), is_mergin_config(path)])
73+
return is_editor_enabled(mc, project_info) and any([is_qgis_file(path)])

mergin/test/test_client.py

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,28 +2545,7 @@ def test_editor(mc: MerginClient):
25452545
"removed": [{"path": "/folder/project.removed.qgs"}],
25462546
}
25472547
qgs_changeset = filter_changes(mc, project_info, qgs_changeset)
2548-
assert sum(len(v) for v in qgs_changeset.values()) == 0
2549-
2550-
mergin_config_changeset = {
2551-
"added": [{"path": "/.mergin/mergin-config.json"}],
2552-
"updated": [{"path": "/.mergin/mergin-config.json"}],
2553-
"removed": [{"path": "/.mergin/mergin-config.json"}],
2554-
}
2555-
mergin_config_changeset = filter_changes(mc, project_info, mergin_config_changeset)
2556-
assert sum(len(v) for v in mergin_config_changeset.values()) == 0
2557-
2558-
gpkg_changeset = {
2559-
"added": [{"path": "/.mergin/data.gpkg"}],
2560-
"updated": [
2561-
{"path": "/.mergin/conflict-data.gpkg"},
2562-
{"path": "/.mergin/data.gpkg", "diff": {}},
2563-
],
2564-
"removed": [{"path": "/.mergin/data.gpkg"}],
2565-
}
2566-
gpkg_changeset = filter_changes(mc, project_info, gpkg_changeset)
2567-
assert sum(len(v) for v in gpkg_changeset.values()) == 2
2568-
assert gpkg_changeset["added"][0]["path"] == "/.mergin/data.gpkg"
2569-
assert gpkg_changeset["updated"][0]["path"] == "/.mergin/data.gpkg"
2548+
assert sum(len(v) for v in qgs_changeset.values()) == 2
25702549

25712550

25722551
def test_editor_push(mc: MerginClient, mc2: MerginClient):
@@ -2591,24 +2570,21 @@ def test_editor_push(mc: MerginClient, mc2: MerginClient):
25912570
qgs_file_name = "test.qgs"
25922571
txt_file_name = "test.txt"
25932572
gpkg_file_name = "base.gpkg"
2594-
files_to_push = [qgs_file_name, txt_file_name, gpkg_file_name]
2573+
files_to_push = [txt_file_name, gpkg_file_name]
25952574
for file in files_to_push:
25962575
shutil.copy(os.path.join(TEST_DATA_DIR, file), project_dir)
25972576
# it's possible to push allowed files if editor
25982577
mc2.push_project(project_dir)
25992578
project_info = mc2.project_info(test_project_fullname)
2600-
assert len(project_info.get("files")) == len(files_to_push) - 1 # ggs is not pushed
2579+
assert len(project_info.get("files")) == len(files_to_push) # ggs is not pushed
26012580
# find pushed files in server
2602-
assert any(file["path"] == qgs_file_name for file in project_info.get("files")) is False
26032581
assert any(file["path"] == txt_file_name for file in project_info.get("files")) is True
26042582
assert any(file["path"] == gpkg_file_name for file in project_info.get("files")) is True
26052583
pull_changes, push_changes, push_changes_summary = mc.project_status(project_dir)
26062584
assert not sum(len(v) for v in pull_changes.values())
2607-
assert sum(len(v) for v in push_changes.values()) == 1
2608-
# ggs is still waiting to push
2609-
assert any(file["path"] == qgs_file_name for file in push_changes.get("added")) is True
2585+
assert not sum(len(v) for v in push_changes.values())
26102586

2611-
# editor is trying to psuh row to gpkg file -> it's possible
2587+
# editor is trying to push row to gpkg file -> it's possible
26122588
shutil.copy(
26132589
os.path.join(TEST_DATA_DIR, "inserted_1_A.gpkg"),
26142590
os.path.join(project_dir, gpkg_file_name),
@@ -2619,19 +2595,20 @@ def test_editor_push(mc: MerginClient, mc2: MerginClient):
26192595
assert any(file["path"] == gpkg_file_name for file in project_info.get("files")) is True
26202596
assert any(file["path"] == gpkg_file_name for file in push_changes.get("updated")) is False
26212597

2622-
# editor is trying to insert tables to gpkg file
2623-
shutil.copy(
2624-
os.path.join(TEST_DATA_DIR, "two_tables.gpkg"),
2625-
os.path.join(project_dir, gpkg_file_name),
2626-
)
2627-
mc2.push_project(project_dir)
2598+
# add qgis file as editor
2599+
shutil.copy(os.path.join(TEST_DATA_DIR, qgs_file_name), project_dir)
2600+
with pytest.raises(ClientError, match=f"You do not have permissions for this project"):
2601+
mc2.push_project(project_dir)
2602+
mc.push_project(project_dir)
2603+
2604+
# editor is trying to update qgis file
2605+
with open(os.path.join(project_dir, qgs_file_name), "a") as f:
2606+
f.write("Editor is here!")
2607+
project_info = mc2.project_info(test_project_fullname)
26282608
pull_changes, push_changes, push_changes_summary = mc.project_status(project_dir)
2629-
assert not sum(len(v) for v in pull_changes.values())
2630-
# gpkg was filter by editor_handler in push_project, because new tables added
2631-
assert sum(len(v) for v in push_changes.values()) == 2
2632-
# ggs and gpkg are still waiting to push
2633-
assert any(file["path"] == qgs_file_name for file in push_changes.get("added")) is True
2634-
assert any(file["path"] == gpkg_file_name for file in push_changes.get("updated")) is True
2609+
# ggs is still waiting to push
2610+
assert any(file["path"] == qgs_file_name for file in push_changes.get("updated")) is True
2611+
26352612
# push as owner do cleanup local changes and preparation to conflicited copy simulate
26362613
mc.push_project(project_dir)
26372614

0 commit comments

Comments
 (0)