Skip to content

Commit

Permalink
mergin-config check
Browse files Browse the repository at this point in the history
  • Loading branch information
harminius committed Jun 3, 2024
1 parent 4d85def commit 050eac4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
6 changes: 2 additions & 4 deletions Mergin/project_status_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def show_changes(self):
dlg_diff_viewer.exec_()

def link_clicked(self, url):
# url may contain specific layer paths to reset
# url may contain specific layer path to reset
if "?" in url.toString():
function_name = url.toString().split("?")[0]
layer_path = url.toString().split("?")[-1]
Expand All @@ -240,9 +240,7 @@ def link_clicked(self, url):
if msg is not None:
self.ui.messageBar.pushMessage("Mergin", f"Failed to fix issue: {msg}", Qgis.Warning)
return
if function_name == "#reset_qgs_file":
self.reset_local_changes(layer_path)
if function_name == "#reset_layer":
if function_name == "#reset_file":
self.reset_local_changes(layer_path)

self.validate_project()
Expand Down
21 changes: 12 additions & 9 deletions Mergin/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Warning(Enum):
SVG_NOT_EMBEDDED = 23
EDITOR_PROJECT_FILE_CHANGE = 24
EDITOR_NON_DIFFABLE_CHANGE = 25
JSON_CONFIG_CHANGE = 26

class MultipleLayersWarning:
"""Class for warning which is associated with multiple layers.
Expand Down Expand Up @@ -388,27 +389,27 @@ def check_svgs_embedded(self):

def check_editor_perms(self):
if self.project_permission == "editor":
# check if project file has changed
for file in self.changes["updated"]:
# editor cannot change specific files - QGS project file, mergin-config.json file (e.g. selective sync changes)
for file in self.changes["updated"] or self.changes["added"] or self.changes["deleted"]:
if file["path"].lower().endswith(('.qgs', '.qgz')):
url = f"#reset_qgs_file?{file['path']}"
url = f"#reset_file?{file['path']}"
self.issues.append(MultipleLayersWarning(Warning.EDITOR_PROJECT_FILE_CHANGE, url))
# check changes are diff-based not override
elif file["path"].lower().endswith("mergin-config.json"):
url = f"#reset_file?{file['path']}"
self.issues.append(MultipleLayersWarning(Warning.JSON_CONFIG_CHANGE, url))
# check data changes are diff-based not override (e.g. schema change)
for lid, layer in self.layers.items():
if lid not in self.editable:
continue
layer_path = layer.dataProvider().dataSourceUri().split("/")[-1]
url = f"#reset_file?{layer_path}"
dp = layer.dataProvider()
if dp.storageType() == "GPKG":
has_change, msg = has_schema_change(self.mp, layer)
if has_change:
layer_path = layer.dataProvider().dataSourceUri().split("/")[-1]
url = f"#reset_layer?{layer_path}"
self.issues.append(SingleLayerWarning(lid, Warning.EDITOR_NON_DIFFABLE_CHANGE, url))
else:
layer_path = layer.dataProvider().dataSourceUri().split("/")[-1]
url = f"#reset_layer?{layer_path}"
self.issues.append(SingleLayerWarning(lid, Warning.EDITOR_NON_DIFFABLE_CHANGE, url))
# TODO: check mergin-config.json has changed


def warning_display_string(warning_id, url=None):
Expand Down Expand Up @@ -464,3 +465,5 @@ def warning_display_string(warning_id, url=None):
return f"You don't have permission to edit QGS project file. Ask workspace admin to upgrade you permission or <a href='{url}'>reset QGS project file</a> to be able to sync data changes. This might involve deleting layers you created locally."
elif warning_id == Warning.EDITOR_NON_DIFFABLE_CHANGE:
return f"You don't have permission to edit layer schema. Ask workspace admin to upgrade you permission or <a href='{url}'>reset the layer</a> to be able to sync changes in other layers."
elif warning_id == Warning.JSON_CONFIG_CHANGE:
return f"You don't have permission to change the config file. <a href='{url}'>Reset the file</a> to be able to sync data changes."

0 comments on commit 050eac4

Please sign in to comment.