diff --git a/docs/development.md b/docs/development.md index bbaab14..3f1c3f5 100644 --- a/docs/development.md +++ b/docs/development.md @@ -19,6 +19,10 @@ Select **Add hosting account** and enter a name and a primary domain such as `example.org`. Open an account from the list to edit its details or request an Apache preview. Manage users, groups, and permissions at `/admin/`. +Use **Hosting plans** to add named plans with an optional description. Choose a +plan when creating or editing an account. Existing accounts start unassigned. +Operators need permission to view hosting plans before they can assign one. + The local database defaults to `db.sqlite3`. Set `COULOBRE_SQLITE_PATH` to use a different file. Keep `COULOBRE_DEBUG` for local development. diff --git a/src/coulobre/hosting/admin.py b/src/coulobre/hosting/admin.py index 395052b..6a0e11d 100644 --- a/src/coulobre/hosting/admin.py +++ b/src/coulobre/hosting/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from django.utils.html import format_html -from .models import HostingAccount, WebProvisioningPlan +from .models import HostingAccount, HostingPlan, WebProvisioningPlan @admin.register(HostingAccount) @@ -11,6 +11,17 @@ class HostingAccountAdmin(admin.ModelAdmin): ordering = ("primary_domain",) actions = ("request_web_plans",) + def get_exclude(self, request, obj=None): + if not request.user.has_perm("hosting.view_hostingplan"): + return ("hosting_plan",) + return super().get_exclude(request, obj) + + def save_model(self, request, obj, form, change): + if change: + obj.save(update_fields=form.changed_data) + else: + super().save_model(request, obj, form, change) + @admin.action(permissions=["change"], description="Request Apache plans") def request_web_plans(self, request, queryset): plans = WebProvisioningPlan.objects.bulk_create( @@ -20,6 +31,12 @@ class HostingAccountAdmin(admin.ModelAdmin): self.message_user(request, f"Queued {len(plans)} Apache plan(s).") +@admin.register(HostingPlan) +class HostingPlanAdmin(admin.ModelAdmin): + list_display = ("name", "description") + search_fields = ("name",) + + @admin.register(WebProvisioningPlan) class WebProvisioningPlanAdmin(admin.ModelAdmin): list_display = ("primary_domain", "account", "requested_at", "completed_at") diff --git a/src/coulobre/hosting/migrations/0003_hostingplan_hostingaccount_hosting_plan.py b/src/coulobre/hosting/migrations/0003_hostingplan_hostingaccount_hosting_plan.py new file mode 100644 index 0000000..12fbd4f --- /dev/null +++ b/src/coulobre/hosting/migrations/0003_hostingplan_hostingaccount_hosting_plan.py @@ -0,0 +1,42 @@ +# Generated by Django 5.2.19 on 2026-11-19 21:07 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("hosting", "0002_webprovisioningplan"), + ] + + operations = [ + migrations.CreateModel( + name="HostingPlan", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=120, unique=True)), + ("description", models.CharField(blank=True, max_length=240)), + ], + options={ + "ordering": ("name", "pk"), + }, + ), + migrations.AddField( + model_name="hostingaccount", + name="hosting_plan", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="hosting.hostingplan", + ), + ), + ] diff --git a/src/coulobre/hosting/models.py b/src/coulobre/hosting/models.py index 23eb19a..a6e9643 100644 --- a/src/coulobre/hosting/models.py +++ b/src/coulobre/hosting/models.py @@ -4,9 +4,23 @@ from django.urls import reverse from .fields import DomainNameField +class HostingPlan(models.Model): + name = models.CharField(max_length=120, unique=True) + description = models.CharField(max_length=240, blank=True) + + class Meta: + ordering = ("name", "pk") + + def __str__(self): + return self.name + + class HostingAccount(models.Model): name = models.CharField(max_length=120) primary_domain = DomainNameField(max_length=253, unique=True) + hosting_plan = models.ForeignKey( + HostingPlan, on_delete=models.PROTECT, null=True, blank=True + ) created_at = models.DateTimeField(auto_now_add=True) def get_absolute_url(self): diff --git a/src/coulobre/hosting/static/hosting/panel.css b/src/coulobre/hosting/static/hosting/panel.css index 4985ffe..986d254 100644 --- a/src/coulobre/hosting/static/hosting/panel.css +++ b/src/coulobre/hosting/static/hosting/panel.css @@ -29,7 +29,7 @@ a { text-underline-offset: 0.2em; } -button, input { +button, input, select { font: inherit; } @@ -155,6 +155,10 @@ button, input { linear-gradient(currentColor, currentColor) center 65% / 55% 1px no-repeat; } +.nav-icon-packages { + background: linear-gradient(currentColor, currentColor) center 35% / 40% 1px no-repeat; +} + .sidebar-account { display: grid; gap: 0.3rem; @@ -288,7 +292,7 @@ h2 { font-size: 0.88rem; } -input:not([type="hidden"]) { +input:not([type="hidden"]), select { min-width: 0; height: 2.55rem; padding: 0.48rem 0.68rem; @@ -463,7 +467,7 @@ dd { font-weight: 680; } -.editor input:not([type="hidden"]) { +.editor input:not([type="hidden"]), .editor select { width: 100%; } diff --git a/src/coulobre/hosting/templates/hosting/account_detail.html b/src/coulobre/hosting/templates/hosting/account_detail.html index 2865053..103b90e 100644 --- a/src/coulobre/hosting/templates/hosting/account_detail.html +++ b/src/coulobre/hosting/templates/hosting/account_detail.html @@ -13,6 +13,9 @@
| Account | Primary domain | Added | |
|---|---|---|---|
| Account | +Primary domain | + {% if perms.hosting.view_hostingplan %}Hosting plan | {% endif %} +Added | +
| {{ account.name }} | {{ account.primary_domain }} | + {% if perms.hosting.view_hostingplan %} +{% if account.hosting_plan %}{{ account.hosting_plan.name }}{% else %}Unassigned{% endif %} | + {% endif %}{{ account.created_at|date:"j M Y" }} |
| Plan | Description |
|---|---|
| + {% if perms.hosting.change_hostingplan %} + {{ hosting_plan.name }} + {% else %} + {{ hosting_plan.name }} + {% endif %} + | +{{ hosting_plan.description|default:"—" }} | +
No hosting plans yet.
+ {% endif %} + {% include "hosting/pagination.html" %} +