From b1be8bfb29802d4931e80dbc92e4a116e83047c7 Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Fri, 4 Dec 2026 13:49:24 +0100 Subject: [PATCH] Improve hosting package and account list workflows --- docs/panel-design.md | 3 + .../hosting/account_administration.py | 3 +- src/coulobre/hosting/package_order.py | 16 +++ src/coulobre/hosting/reseller_profiles.py | 24 +++- src/coulobre/hosting/static/hosting/panel.css | 12 +- .../templates/hosting/account_identity.html | 4 + .../templates/hosting/account_list.html | 3 +- .../hosting/cluster_account_list.html | 2 +- .../templates/hosting/hosting_plan_list.html | 4 + .../hosting/reseller_profile_form.html | 4 +- .../hosting/reseller_profile_list.html | 5 +- .../hosting/test_package_workflows.py | 127 ++++++++++++++++++ src/coulobre/hosting/urls.py | 11 ++ src/coulobre/hosting/views.py | 19 +++ src/coulobre/hosting/workspaces.py | 2 + 15 files changed, 228 insertions(+), 11 deletions(-) create mode 100644 src/coulobre/hosting/package_order.py create mode 100644 src/coulobre/hosting/templates/hosting/account_identity.html create mode 100644 src/coulobre/hosting/test_package_workflows.py diff --git a/docs/panel-design.md b/docs/panel-design.md index dbf3ab0..1cf865b 100644 --- a/docs/panel-design.md +++ b/docs/panel-design.md @@ -91,6 +91,9 @@ heading, help, fields, and actions should share a left edge. for row-level actions such as **Import mail**, **Change password**, and **Manage logins**. Use `.button danger compact` for opening a removal workflow. Keep the final destructive confirmation visually distinct. +- Keep a record name and its secondary identifier in one table cell. Use a + wrapping row when space permits, and omit the identifier when it repeats + the name. The record name remains the link. - Group table actions in a wrapping `.table-actions` container. Center them vertically within the row and allow labels to wrap instead of widening the whole table. Keep overflow within `.table-scroll`. diff --git a/src/coulobre/hosting/account_administration.py b/src/coulobre/hosting/account_administration.py index 16ea7ce..39f45d1 100644 --- a/src/coulobre/hosting/account_administration.py +++ b/src/coulobre/hosting/account_administration.py @@ -41,6 +41,7 @@ from .models import ( HostingPlan, Reseller, ) +from .package_order import by_storage_quota from .reseller_accounts import ( create_reseller_account, lock_resellers, @@ -312,7 +313,7 @@ class ManagerPackagesView(UserPassesTestMixin, ListView): return self.manager is not None def get_queryset(self): - return self.manager.hosting_plans.order_by("name") + return by_storage_quota(self.manager.hosting_plans.all()) class AllUsersView(OperatorOnlyMixin, PermissionRequiredMixin, ListView): diff --git a/src/coulobre/hosting/package_order.py b/src/coulobre/hosting/package_order.py new file mode 100644 index 0000000..ee5cbe2 --- /dev/null +++ b/src/coulobre/hosting/package_order.py @@ -0,0 +1,16 @@ +from django.db.models import F + + +def by_storage_quota(queryset): + """Sort packages by website storage first.""" + quotas = ( + "website_storage_limit_mib", + "mailbox_quota_mib", + "website_limit", + "mailbox_limit", + "database_limit", + "website_job_limit", + ) + return queryset.order_by( + *(F(field).asc(nulls_last=True) for field in quotas), "name", "pk" + ) diff --git a/src/coulobre/hosting/reseller_profiles.py b/src/coulobre/hosting/reseller_profiles.py index ed39083..07c4797 100644 --- a/src/coulobre/hosting/reseller_profiles.py +++ b/src/coulobre/hosting/reseller_profiles.py @@ -1,7 +1,9 @@ from django import forms from django.contrib.auth.mixins import PermissionRequiredMixin from django.db import IntegrityError, transaction +from django.shortcuts import get_object_or_404 from django.urls import reverse_lazy +from django.utils.functional import cached_property from django.views.generic import CreateView, ListView, UpdateView from .access import OperatorOnlyMixin @@ -31,7 +33,7 @@ class ResellerProfileForm(forms.ModelForm): super().__init__(*args, **kwargs) add_unlimited_fields(self, ("account_limit",)) if not self.instance.pk: - self.initial["account_limit"] = 0 + self.initial.setdefault("account_limit", 0) self.initial["use_as_default"] = self.instance.default_slot == 1 def clean(self): @@ -87,5 +89,25 @@ class ResellerProfileCreate(ProfileEditor, CreateView): pass +class ResellerProfileDuplicate(ResellerProfileCreate): + extra_context = {"page_title": "Duplicate manager package"} + + @cached_property + def source(self): + return get_object_or_404(ResellerProfile, pk=self.kwargs["pk"]) + + def get_initial(self): + return { + "account_limit": self.source.account_limit, + "hosting_plans": list( + self.source.hosting_plans.values_list("pk", flat=True) + ), + } + + def form_valid(self, form): + form.instance.manage_resources = self.source.manage_resources + return super().form_valid(form) + + class ResellerProfileEdit(ProfileEditor, UpdateView): pass diff --git a/src/coulobre/hosting/static/hosting/panel.css b/src/coulobre/hosting/static/hosting/panel.css index 885c82b..b083cc0 100644 --- a/src/coulobre/hosting/static/hosting/panel.css +++ b/src/coulobre/hosting/static/hosting/panel.css @@ -713,8 +713,16 @@ h3, h4, h5, h6 { flex: 1 1 25rem; } -.account-domain { - margin-top: 0.22rem; +.account-identity { + display: flex; + flex-wrap: wrap; + align-items: baseline; + gap: 0.15rem 0.65rem; +} + +.account-identity > * { + min-width: 0; + overflow-wrap: anywhere; } .account-heading-meta { diff --git a/src/coulobre/hosting/templates/hosting/account_identity.html b/src/coulobre/hosting/templates/hosting/account_identity.html new file mode 100644 index 0000000..c95467a --- /dev/null +++ b/src/coulobre/hosting/templates/hosting/account_identity.html @@ -0,0 +1,4 @@ +
+ {{ name }} + {% if primary_domain|lower != name|lower %}{{ primary_domain }}{% endif %} +
diff --git a/src/coulobre/hosting/templates/hosting/account_list.html b/src/coulobre/hosting/templates/hosting/account_list.html index 32cf2ed..58be9d2 100644 --- a/src/coulobre/hosting/templates/hosting/account_list.html +++ b/src/coulobre/hosting/templates/hosting/account_list.html @@ -53,8 +53,7 @@ {% for account in accounts %} - {{ account.name }} -
{{ account.primary_domain }}
+ {% include "hosting/account_identity.html" with account_url=account.get_absolute_url name=account.name primary_domain=account.primary_domain only %} {% if is_customer %}
{% if show_customer_website_link %}Websites{% endif %} diff --git a/src/coulobre/hosting/templates/hosting/cluster_account_list.html b/src/coulobre/hosting/templates/hosting/cluster_account_list.html index 12d1d94..b05af74 100644 --- a/src/coulobre/hosting/templates/hosting/cluster_account_list.html +++ b/src/coulobre/hosting/templates/hosting/cluster_account_list.html @@ -38,7 +38,7 @@ {% for account in page.accounts %} - {{ account.name }} + {% include "hosting/account_identity.html" with account_url=account.url name=account.name primary_domain=account.primary_domain only %} {% include "hosting/hosting_node.html" with node=page.node only %} {% include "hosting/account_status.html" %} diff --git a/src/coulobre/hosting/templates/hosting/hosting_plan_list.html b/src/coulobre/hosting/templates/hosting/hosting_plan_list.html index bfdeac7..6ac0e96 100644 --- a/src/coulobre/hosting/templates/hosting/hosting_plan_list.html +++ b/src/coulobre/hosting/templates/hosting/hosting_plan_list.html @@ -24,6 +24,7 @@ Default website limit Scheduled jobs PHP overrides + {% if perms.hosting.add_hostingplan %}Actions{% endif %} @@ -44,6 +45,9 @@ {% if hosting_plan.website_storage_limit_mib is not None %}{{ hosting_plan.website_storage_limit_mib }} MiB{% else %}Unlimited{% endif %} {{ hosting_plan.website_job_limit|default_if_none:"Unlimited" }} {% if hosting_plan.get_php_settings.has_overrides %}Configured{% else %}Server defaults{% endif %} + {% if perms.hosting.add_hostingplan %} + + {% endif %} {% endfor %} diff --git a/src/coulobre/hosting/templates/hosting/reseller_profile_form.html b/src/coulobre/hosting/templates/hosting/reseller_profile_form.html index 37b541e..6a811ee 100644 --- a/src/coulobre/hosting/templates/hosting/reseller_profile_form.html +++ b/src/coulobre/hosting/templates/hosting/reseller_profile_form.html @@ -1,7 +1,7 @@ {% extends "hosting/workspace_page.html" %} {% load panel_assets %} -{% block title %}{% if object %}Edit manager package{% else %}Add manager package{% endif %} · Coulobre Panel{% endblock %} -{% block page_title %}{% if object %}Edit manager package{% else %}Add manager package{% endif %}{% endblock %} +{% block title %}{% if page_title %}{{ page_title }}{% elif object %}Edit manager package{% else %}Add manager package{% endif %} · Coulobre Panel{% endblock %} +{% block page_title %}{% if page_title %}{{ page_title }}{% elif object %}Edit manager package{% else %}Add manager package{% endif %}{% endblock %} {% block page_context %} ← Manager packages {% endblock %} diff --git a/src/coulobre/hosting/templates/hosting/reseller_profile_list.html b/src/coulobre/hosting/templates/hosting/reseller_profile_list.html index c5e558e..bf045f9 100644 --- a/src/coulobre/hosting/templates/hosting/reseller_profile_list.html +++ b/src/coulobre/hosting/templates/hosting/reseller_profile_list.html @@ -13,15 +13,16 @@
- + {% for profile in object_list %} + {% empty %} - + {% endfor %}
PackageAccount limit
PackageAccount limitActions
{{ profile.name }}{% if profile.default_slot %} · Default{% endif %} {% if profile.account_limit == 0 %}Manage existing accounts only{% else %}{{ profile.account_limit|default_if_none:"Unlimited" }}{% endif %}
No manager packages yet. Add one to reuse account limits and a set of hosting packages.
No manager packages yet. Add one to reuse account limits and a set of hosting packages.
diff --git a/src/coulobre/hosting/test_package_workflows.py b/src/coulobre/hosting/test_package_workflows.py new file mode 100644 index 0000000..4629e21 --- /dev/null +++ b/src/coulobre/hosting/test_package_workflows.py @@ -0,0 +1,127 @@ +from django.contrib.auth import get_user_model +from django.test import TestCase +from django.urls import reverse + +from .models import HostingAccount, HostingPlan, Reseller, ResellerProfile + + +class PackageWorkflowTests(TestCase): + @classmethod + def setUpTestData(cls): + users = get_user_model().objects + cls.operator = users.create_superuser("operator") + cls.manager = Reseller.objects.create( + user=users.create_user("manager") + ) + + def setUp(self): + self.client.force_login(self.operator) + + def test_package_order_is_numeric_and_scoped(self): + plans = [ + HostingPlan.objects.create( + name=name, + website_storage_limit_mib=storage, + mailbox_limit=mail, + ) + for name, storage, mail in ( + ("Unlimited", None, 1), + ("10 GiB", 10240, 1), + ("5 GiB", 5120, 1), + ("1 GiB high mail", 1024, 9), + ("1 GiB low mail", 1024, 2), + ) + ] + self.manager.hosting_plans.add(*plans[:4]) + response = self.client.get(reverse("panel:hosting_plans")) + self.assertEqual(list(response.context["hosting_plans"]), plans[::-1]) + self.client.force_login(self.manager.user) + response = self.client.get(reverse("panel:manager_packages")) + self.assertEqual(list(response.context["plans"]), plans[3::-1]) + + def test_hosting_package_copy_is_prefilled_and_independent(self): + plan = HostingPlan.objects.create( + name="Source", + description="Package description", + website_limit=None, + website_storage_limit_mib=1024, + website_job_limit=0, + allow_external_mail_forwarding=True, + php_memory_limit_mib=0, + ) + account = HostingAccount.objects.create( + name="Example", primary_domain="example.org", hosting_plan=plan + ) + url = reverse("panel:hosting_plan_duplicate", args=[plan.pk]) + self.assertContains( + self.client.get(reverse("panel:hosting_plans")), url + ) + form = self.client.get(url).context["form"] + self.assertEqual(form["description"].value(), plan.description) + self.assertIsNone(form["website_limit"].value()) + self.assertEqual(form["php_memory_limit_mib"].value(), 0) + self.assertRedirects( + self.client.post( + url, + { + "name": "Copy", + "description": plan.description, + "website_limit_unlimited": "on", + "website_job_limit": "0", + "website_storage_limit_mib": "1024", + "allow_external_mail_forwarding": "on", + "php_memory_limit_mib_unlimited": "on", + }, + ), + reverse("panel:hosting_plans"), + ) + copy = HostingPlan.objects.get(name="Copy") + self.assertTrue(copy.allow_external_mail_forwarding) + self.assertIsNone(copy.website_limit) + self.assertEqual(copy.php_memory_limit_mib, 0) + account.refresh_from_db() + self.assertEqual(account.hosting_plan, plan) + self.client.force_login(self.manager.user) + self.assertEqual(self.client.get(url).status_code, 403) + + def test_manager_package_copy_keeps_policy_without_default(self): + plan = HostingPlan.objects.create(name="Allowed") + source = ResellerProfile.objects.create( + name="Source", manage_resources=True, default_slot=1 + ) + source.hosting_plans.add(plan) + url = reverse("panel:reseller_profile_duplicate", args=[source.pk]) + form = self.client.get(url).context["form"] + self.assertIsNone(form["account_limit"].value()) + self.assertFalse(form["use_as_default"].value()) + self.assertEqual(form["hosting_plans"].value(), [plan.pk]) + self.assertRedirects( + self.client.post( + url, + { + "name": "Copy", + "account_limit_unlimited": "on", + "hosting_plans": [plan.pk], + }, + ), + reverse("panel:reseller_profiles"), + ) + copy = ResellerProfile.objects.get(name="Copy") + self.assertTrue(copy.manage_resources) + self.assertIsNone(copy.default_slot) + self.assertIsNone(copy.account_limit) + self.assertEqual(list(copy.hosting_plans.all()), [plan]) + source.refresh_from_db() + self.assertEqual(source.default_slot, 1) + + def test_account_domain_is_not_repeated_when_it_matches_the_name(self): + HostingAccount.objects.create( + name="Same.example", primary_domain="same.example" + ) + HostingAccount.objects.create( + name="Different", primary_domain="different.example" + ) + response = self.client.get(reverse("panel:accounts")) + self.assertContains(response, 'class="account-identity"', count=2) + self.assertNotContains(response, ">same.example") + self.assertContains(response, ">different.example") diff --git a/src/coulobre/hosting/urls.py b/src/coulobre/hosting/urls.py index ec258ec..924fd3f 100644 --- a/src/coulobre/hosting/urls.py +++ b/src/coulobre/hosting/urls.py @@ -97,6 +97,7 @@ from .reseller_onboarding_views import ( ) from .reseller_profiles import ( ResellerProfileCreate, + ResellerProfileDuplicate, ResellerProfileEdit, ResellerProfileList, ) @@ -645,6 +646,11 @@ urlpatterns = [ ResellerProfileEdit.as_view(), name="reseller_profile_edit", ), + path( + "resellers/profiles//duplicate/", + ResellerProfileDuplicate.as_view(), + name="reseller_profile_duplicate", + ), path("resellers/new/", ResellerCreate.as_view(), name="reseller_create"), path("resellers//", ResellerDetail.as_view(), name="reseller"), path( @@ -818,6 +824,11 @@ urlpatterns = [ views.HostingPlanEdit.as_view(), name="hosting_plan_edit", ), + path( + "hosting-plans//duplicate/", + views.HostingPlanDuplicate.as_view(), + name="hosting_plan_duplicate", + ), path("plans/", views.PlanList.as_view(), name="plans"), path("plans//", views.PlanDetail.as_view(), name="plan"), path( diff --git a/src/coulobre/hosting/views.py b/src/coulobre/hosting/views.py index 5e7207e..541503d 100644 --- a/src/coulobre/hosting/views.py +++ b/src/coulobre/hosting/views.py @@ -130,6 +130,7 @@ from .models import ( ) from .offsite_backups import queue_offsite_recovery, retry_offsite_transfer from .offsite_destinations import offsite_destinations +from .package_order import by_storage_quota from .php_settings import ( SitePhpSettingsForm, last_applied_php_settings, @@ -2821,6 +2822,9 @@ class HostingPlanList(OperatorOnlyMixin, PermissionRequiredMixin, ListView): context_object_name = "hosting_plans" paginate_by = 20 + def get_queryset(self): + return by_storage_quota(super().get_queryset()) + class HostingPlanEditor: model = HostingPlan @@ -2954,6 +2958,21 @@ class HostingPlanCreate( } +class HostingPlanDuplicate(HostingPlanCreate): + extra_context = { + "page_title": "Duplicate hosting package", + "submit_label": "Create package copy", + } + + def get_initial(self): + source = get_object_or_404(HostingPlan, pk=self.kwargs["pk"]) + return { + field: getattr(source, field) + for field in self.fields + if field != "name" + } + + class HostingPlanEdit( OperatorOnlyMixin, PermissionRequiredMixin, HostingPlanEditor, UpdateView ): diff --git a/src/coulobre/hosting/workspaces.py b/src/coulobre/hosting/workspaces.py index 5a30302..0f9af16 100644 --- a/src/coulobre/hosting/workspaces.py +++ b/src/coulobre/hosting/workspaces.py @@ -92,8 +92,10 @@ WORKSPACE_PARENT_ROUTES = { "reseller_edit": ("resellers", ()), "hosting_plan_create": ("hosting_plans", ()), "hosting_plan_edit": ("hosting_plans", ()), + "hosting_plan_duplicate": ("hosting_plans", ()), "reseller_profile_create": ("reseller_profiles", ()), "reseller_profile_edit": ("reseller_profiles", ()), + "reseller_profile_duplicate": ("reseller_profiles", ()), "manager_assign_plan": ("manager_packages", ()), "account": ("accounts", ()), } -- 2.43.0