Skip to content
Closed
9 changes: 6 additions & 3 deletions Mergin/help.py
Original file line number Diff line number Diff line change
@@ -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/"
35 changes: 35 additions & 0 deletions Mergin/monthly_contributors_error_dialog.py
Original file line number Diff line number Diff line change
@@ -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."
)
Comment on lines +27 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nit picking - this might seem more friendly for users in case we have issues reading the quota

Suggested change
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."
)
quota = self.server_response.get("contributors_quota", None)
quota_text = (
f"You've reached the maximum number of active monthly contributors {'(' + quota + ')' if quota else ''} for your current subscription."
)

self.label.setText(quota_text)

def open_upgrade_link(self):
QDesktopServices.openUrl(QUrl(MerginHelp().mergin_subscription_link()))
self.accept()
10 changes: 9 additions & 1 deletion Mergin/projects_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
84 changes: 84 additions & 0 deletions Mergin/ui/ui_monthly_contributors_error_dialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>367</width>
<height>163</height>
</rect>
</property>
<property name="windowTitle">
<string>Monthly Contributors Limit Hit</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>You've reached the maximum number of active monthly contributors for your current subscription.</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Upgrade your subscription or wait until next month
for the limit to reset.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Loading