Skip to content
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
6 changes: 0 additions & 6 deletions Mergin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
icon_path,
mm_symbol_path,
mergin_project_local_path,
refresh_project_role,
remove_project_variables,
set_qgis_project_mergin_variables,
unsaved_project_check,
Expand Down Expand Up @@ -248,9 +247,6 @@ def create_manager(self):
if self.mc is not None:
self.choose_active_workspace()
self.manager = MerginProjectsManager(self)
if self.mergin_proj_dir is not None:
refresh_project_role(self.mc, self.mergin_proj_dir)
set_qgis_project_mergin_variables(self.mergin_proj_dir)
else:
error = "Configure the Mergin Maps plugin \nto access your projects"
except (URLError, ClientError, LoginError):
Expand Down Expand Up @@ -543,8 +539,6 @@ def on_qgis_project_changed(self):
self.mergin_proj_dir = mergin_project_local_path()
if self.mergin_proj_dir is not None:
self.enable_toolbar_actions()
if self.mc is not None:
refresh_project_role(self.mc, self.mergin_proj_dir)
set_qgis_project_mergin_variables(self.mergin_proj_dir)
# re-render Browser items so the opened-project indicator follows the active QGIS project.
if self.has_browser_item():
Expand Down
14 changes: 1 addition & 13 deletions Mergin/projects_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
LoginError,
find_qgis_files,
login_error_message,
mergin_project_local_path,
same_dir,
send_logs,
set_qgis_project_mergin_variables,
storage_limit_fail,
unhandled_exception_message,
unsaved_project_check,
Expand Down Expand Up @@ -222,7 +220,7 @@ def create_project(self, project_name, project_dir, is_public, namespace):
project_dir == QgsProject.instance().absolutePath()
or project_dir + "/" in QgsProject.instance().absolutePath()
):
write_project_variables(project_name, full_project_name, "v1", mp.project_role())
write_project_variables(project_name, full_project_name, "v1")

QMessageBox.information(
None,
Expand All @@ -233,11 +231,6 @@ def create_project(self, project_name, project_dir, is_public, namespace):

return True

def refresh_project_variables(self, project_dir):
"""Re-read the Mergin Maps variables from the project metadata, if that project is the open one."""
if same_dir(project_dir, mergin_project_local_path()):
set_qgis_project_mergin_variables(project_dir)

def project_status(self, project_dir):
if project_dir is None:
return
Expand All @@ -261,7 +254,6 @@ def project_status(self, project_dir):
if qgis_proj_filename in find_qgis_files(project_dir):
AuthSync().export_auth(self.mc)
pull_changes, push_changes, push_changes_summary = self.mc.project_status(project_dir)
self.refresh_project_variables(project_dir)
dlg = ProjectStatusDialog(
pull_changes,
push_changes,
Expand Down Expand Up @@ -407,9 +399,6 @@ def sync_project(self, project_dir, project_name=None):
QMessageBox.critical(None, "Project syncing", msg, QMessageBox.StandardButton.Close)
return

# a role change creates no project version, so it only arrives with the status we just fetched
self.refresh_project_variables(project_dir)

if not sum(len(v) for v in list(pull_changes.values()) + list(push_changes.values())):
QMessageBox.information(
None,
Expand Down Expand Up @@ -521,7 +510,6 @@ def sync_project(self, project_dir, project_name=None):
_, has_push_changes = get_push_changes_batch(self.mc, project_dir)
error_retries_attempts = 0
if not has_push_changes:
self.refresh_project_variables(project_dir)
# TODO: report success only when we have actually done anything
msg = "Mergin Maps project {} synchronised successfully".format(project_name)
QMessageBox.information(None, "Project sync", msg, QMessageBox.StandardButton.Close)
Expand Down
22 changes: 2 additions & 20 deletions Mergin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,15 +943,13 @@ def unhandled_exception_message(error_details, dialog_title, error_text, mm_clie
box.exec()


def write_project_variables(project_name, project_full_name, version, role=""):
def write_project_variables(project_name, project_full_name, version):
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "mergin_project_name", project_name)
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "mergin_project_full_name", project_full_name)
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "mergin_project_version", int_version(version))
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "mm_project_name", project_name)
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "mm_project_full_name", project_full_name)
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "mm_project_version", int_version(version))
# projects downloaded with an older client have no role in their metadata
QgsExpressionContextUtils.setProjectVariable(QgsProject.instance(), "mm_project_role", role or "")


def remove_project_variables():
Expand All @@ -961,7 +959,6 @@ def remove_project_variables():
QgsExpressionContextUtils.removeProjectVariable(QgsProject.instance(), "mm_project_name")
QgsExpressionContextUtils.removeProjectVariable(QgsProject.instance(), "mm_project_full_name")
QgsExpressionContextUtils.removeProjectVariable(QgsProject.instance(), "mm_project_version")
QgsExpressionContextUtils.removeProjectVariable(QgsProject.instance(), "mm_project_role")


def pretty_summary(summary):
Expand Down Expand Up @@ -1019,28 +1016,13 @@ def get_local_mergin_projects_info(workspace=None):
return local_projects_info


def refresh_project_role(mc, project_dir):
"""Ask the server for the user's current role on the project and store it in the project metadata."""
try:
mp = MerginProject(project_dir)
try:
role = mc.project_info_v2(mp.project_id()).role
except (NotImplementedError, ClientError):
# servers below 2025.8.2 have no v2 project info, and old projects have no id in their metadata
role = mc.project_info(mp.project_full_name())["role"]
mp.update_project_role(role)
except (InvalidProject, ClientError, URLError):
# keep whatever the metadata holds, the variable has to stay usable offline
pass


def set_qgis_project_mergin_variables(project_dir):
"""Check if QGIS project project_dir is a local Mergin Maps project and set QGIS project variables for Mergin Maps."""

try:
mp = MerginProject(project_dir)

write_project_variables(mp.project_name(), mp.project_full_name(), mp.version(), mp.project_role())
write_project_variables(mp.project_name(), mp.project_full_name(), mp.version())
except InvalidProject:
remove_project_variables()

Expand Down
Loading