diff --git a/Mergin/help.py b/Mergin/help.py index 951da21c..3526d18a 100644 --- a/Mergin/help.py +++ b/Mergin/help.py @@ -1,11 +1,14 @@ -HELP_ROOT = "https://merginmaps.com/docs" +MAIN_ROOT = "https://merginmaps.com/" class MerginHelp: """Class for generating Mergin plugin help URLs.""" def howto_attachment_widget(self): - return f"{HELP_ROOT}/layer/settingup_forms/" + return f"{MAIN_ROOT}/docs/layer/settingup_forms/" def howto_background_maps(self): - return f"{HELP_ROOT}/gis/settingup_background_map/" + return f"{MAIN_ROOT}/docs/gis/settingup_background_map/" + + def mergin_subscription_link(self): + return f"{MAIN_ROOT}/pricing/" diff --git a/Mergin/monthly_contributors_error_dialog.py b/Mergin/monthly_contributors_error_dialog.py new file mode 100644 index 00000000..c0f9bb05 --- /dev/null +++ b/Mergin/monthly_contributors_error_dialog.py @@ -0,0 +1,35 @@ +import os +from qgis.PyQt import uic +from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox +from qgis.PyQt.QtCore import QUrl +from qgis.PyQt.QtGui import QDesktopServices + +from .help import MerginHelp + +ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "ui_monthly_contributors_error_dialog.ui") + + +class MonthlyContributorsErrorDialog(QDialog): + def __init__(self, e, parent=None): + QDialog.__init__(self, parent) + self.ui = uic.loadUi(ui_file, self) + + self.server_response = e.server_response + self.set_dialog_style() + + self.buttonBox.accepted.connect(self.open_upgrade_link) + self.buttonBox.rejected.connect(self.reject) + + def set_dialog_style(self): + upgrade_button = self.buttonBox.button(QDialogButtonBox.Ok) + upgrade_button.setText("Upgrade") + + quota = self.server_response.get("contributors_quota", "#NA") + quota_text = ( + f"You've reached the maximum number of active monthly contributors ({quota}) for your current subscription." + ) + self.label.setText(quota_text) + + def open_upgrade_link(self): + QDesktopServices.openUrl(QUrl(MerginHelp().mergin_subscription_link())) + self.accept() diff --git a/Mergin/projects_manager.py b/Mergin/projects_manager.py index 2823ac5c..c0b5d528 100644 --- a/Mergin/projects_manager.py +++ b/Mergin/projects_manager.py @@ -29,6 +29,7 @@ from .mergin.merginproject import MerginProject from .project_status_dialog import ProjectStatusDialog +from .monthly_contributors_error_dialog import MonthlyContributorsErrorDialog class MerginProjectsManager(object): @@ -95,6 +96,10 @@ def create_project(self, project_name, project_dir, is_public, namespace): # User friendly error messages if e.http_error == 409: msg = f'Project named "{project_name}" already exists in the workspace "{namespace}".\nPlease try renaming the project.' + elif e.server_code == ErrorCode.MonthlyContributorsLimitHit.value: + dlg = MonthlyContributorsErrorDialog(e) + dlg.exec() + return False elif e.server_code == ErrorCode.ProjectsLimitHit.value: msg = ( "Maximum number of projects reached. Please upgrade your subscription to create new projects.\n" @@ -104,7 +109,6 @@ def create_project(self, project_name, project_dir, is_public, namespace): msg = ( f"{e.detail}\nCurrent limit: {bytes_to_human_size(dlg.exception.server_response['storage_limit'])}" ) - QMessageBox.critical(None, "Create Project", "Failed to create Mergin Maps project.\n" + msg) return False except Exception as e: @@ -375,6 +379,10 @@ def sync_project(self, project_dir, project_name=None): if dlg.exception.http_error == 400 and "Another process" in dlg.exception.detail: # To note we check for a string since error in flask doesn't return server error code msg = "Somebody else is syncing, please try again later" + elif dlg.exception.server_code == ErrorCode.MonthlyContributorsLimitHit.value: + dlg = MonthlyContributorsErrorDialog(dlg.exception) + dlg.exec() + return elif dlg.exception.server_code == ErrorCode.StorageLimitHit.value: msg = f"{e.detail}\nCurrent limit: {bytes_to_human_size(dlg.exception.server_response['storage_limit'])}" else: diff --git a/Mergin/ui/ui_monthly_contributors_error_dialog.ui b/Mergin/ui/ui_monthly_contributors_error_dialog.ui new file mode 100644 index 00000000..579c443d --- /dev/null +++ b/Mergin/ui/ui_monthly_contributors_error_dialog.ui @@ -0,0 +1,84 @@ + + + Dialog + + + + 0 + 0 + 367 + 163 + + + + Monthly Contributors Limit Hit + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + true + + + + + + + + + + 0 + 0 + + + + + 16 + 75 + true + + + + You've reached the maximum number of active monthly contributors for your current subscription. + + + Qt::AutoText + + + Qt::AlignCenter + + + true + + + + + + + Upgrade your subscription or wait until next month +for the limit to reset. + + + Qt::AlignCenter + + + + + + + +