Improve hosting package and account list workflows #302
No files matched your search
@@ -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`.
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<div class="account-identity">
|
||||
<a class="record-link" href="{{ account_url }}">{{ name }}</a>
|
||||
{% if primary_domain|lower != name|lower %}<span class="domain muted">{{ primary_domain }}</span>{% endif %}
|
||||
</div>
|
||||
@@ -53,8 +53,7 @@
|
||||
{% for account in accounts %}
|
||||
<tr>
|
||||
<td>
|
||||
<a class="record-link" href="{{ account.get_absolute_url }}">{{ account.name }}</a>
|
||||
<div class="domain muted account-domain">{{ account.primary_domain }}</div>
|
||||
{% include "hosting/account_identity.html" with account_url=account.get_absolute_url name=account.name primary_domain=account.primary_domain only %}
|
||||
{% if is_customer %}
|
||||
<div class="table-actions">
|
||||
{% if show_customer_website_link %}<a href="{{ account.get_absolute_url }}#websites">Websites</a>{% endif %}
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<tbody>
|
||||
{% for account in page.accounts %}
|
||||
<tr>
|
||||
<th scope="row"><a class="record-link" href="{{ account.url }}">{{ account.name }}</a><div class="domain muted account-domain">{{ account.primary_domain }}</div></th>
|
||||
<th scope="row">{% include "hosting/account_identity.html" with account_url=account.url name=account.name primary_domain=account.primary_domain only %}</th>
|
||||
<td>{% include "hosting/hosting_node.html" with node=page.node only %}</td>
|
||||
<td>{% include "hosting/account_status.html" %}</td>
|
||||
</tr>
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<th scope="col">Default website limit</th>
|
||||
<th scope="col">Scheduled jobs</th>
|
||||
<th scope="col">PHP overrides</th>
|
||||
{% if perms.hosting.add_hostingplan %}<th scope="col">Actions</th>{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -44,6 +45,9 @@
|
||||
<td>{% if hosting_plan.website_storage_limit_mib is not None %}{{ hosting_plan.website_storage_limit_mib }} MiB{% else %}Unlimited{% endif %}</td>
|
||||
<td>{{ hosting_plan.website_job_limit|default_if_none:"Unlimited" }}</td>
|
||||
<td>{% if hosting_plan.get_php_settings.has_overrides %}Configured{% else %}Server defaults{% endif %}</td>
|
||||
{% if perms.hosting.add_hostingplan %}
|
||||
<td><div class="table-actions"><a class="button secondary compact" href="{% url 'panel:hosting_plan_duplicate' hosting_plan.pk %}" aria-label="Duplicate {{ hosting_plan.name }}">Duplicate</a></div></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
@@ -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 %}
|
||||
<a class="quiet-link" href="{% url 'panel:reseller_profiles' %}">← Manager packages</a>
|
||||
{% endblock %}
|
||||
|
||||
@@ -13,15 +13,16 @@
|
||||
<section class="surface">
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead><tr><th scope="col">Package</th><th scope="col">Account limit</th></tr></thead>
|
||||
<thead><tr><th scope="col">Package</th><th scope="col">Account limit</th><th scope="col">Actions</th></tr></thead>
|
||||
<tbody>
|
||||
{% for profile in object_list %}
|
||||
<tr>
|
||||
<td><a href="{% url 'panel:reseller_profile_edit' profile.pk %}">{{ profile.name }}</a>{% if profile.default_slot %} · Default{% endif %}</td>
|
||||
<td>{% if profile.account_limit == 0 %}Manage existing accounts only{% else %}{{ profile.account_limit|default_if_none:"Unlimited" }}{% endif %}</td>
|
||||
<td><div class="table-actions"><a class="button secondary compact" href="{% url 'panel:reseller_profile_duplicate' profile.pk %}" aria-label="Duplicate {{ profile.name }}">Duplicate</a></div></td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr><td colspan="2">No manager packages yet. Add one to reuse account limits and a set of hosting packages.</td></tr>
|
||||
<tr><td colspan="3">No manager packages yet. Add one to reuse account limits and a set of hosting packages.</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -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</span>")
|
||||
self.assertContains(response, ">different.example</span>")
|
||||
@@ -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/<int:pk>/duplicate/",
|
||||
ResellerProfileDuplicate.as_view(),
|
||||
name="reseller_profile_duplicate",
|
||||
),
|
||||
path("resellers/new/", ResellerCreate.as_view(), name="reseller_create"),
|
||||
path("resellers/<int:pk>/", ResellerDetail.as_view(), name="reseller"),
|
||||
path(
|
||||
@@ -818,6 +824,11 @@ urlpatterns = [
|
||||
views.HostingPlanEdit.as_view(),
|
||||
name="hosting_plan_edit",
|
||||
),
|
||||
path(
|
||||
"hosting-plans/<int:pk>/duplicate/",
|
||||
views.HostingPlanDuplicate.as_view(),
|
||||
name="hosting_plan_duplicate",
|
||||
),
|
||||
path("plans/", views.PlanList.as_view(), name="plans"),
|
||||
path("plans/<int:pk>/", views.PlanDetail.as_view(), name="plan"),
|
||||
path(
|
||||
|
||||
@@ -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
|
||||
):
|
||||
|
||||
@@ -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", ()),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user