Compare commits

...
5 Commits
Author SHA1 Message Date
parkel d34654c956 Merge pull request 'Adopt the Coulobre ribbon logo' (#141) from feature/lint-brand into main
Coulobre Panel CI / Checks (Python 3.12) (push) Canceled after 0s
Coulobre Panel CI / Checks (Python 3.14) (push) Canceled after 0s
Reviewed-on: #141
2026-11-22 23:47:48 +01:00
parkel f4a889660f Adopt the Coulobre ribbon logo
Coulobre Panel CI / Checks (Python 3.12) (pull_request) Canceled after 0s
Coulobre Panel CI / Checks (Python 3.14) (pull_request) Canceled after 0s
2026-11-22 23:46:37 +01:00
parkel 187c80ff6d Merge pull request 'Queue database provisioning and new DNS publications on creation' (#140) from feature/automatic-provisioning into main
Coulobre Panel CI / Checks (Python 3.12) (push) Canceled after 0s
Coulobre Panel CI / Checks (Python 3.14) (push) Canceled after 0s
Reviewed-on: #140
2026-11-22 23:30:44 +01:00
parkel 0f12e7c456 Report and link effective DNS defaults in About Coulobre
Coulobre Panel CI / Checks (Python 3.12) (pull_request) Canceled after 0s
Coulobre Panel CI / Checks (Python 3.14) (pull_request) Canceled after 0s
2026-11-22 23:27:26 +01:00
parkel a8985c3041 Queue managed databases and DNS zones on creation 2026-11-22 23:27:26 +01:00
22 changed files with 257 additions and 97 deletions

No files matched your search

+2
View File
@@ -1,5 +1,7 @@
# Coulobre Panel
<img src="src/coulobre/hosting/static/hosting/coulobre-mark.svg" alt="" width="72">
Coulobre Panel is an open-source web hosting control panel for hosting providers
and resellers. The project is in early development.
+20 -5
View File
@@ -11,10 +11,11 @@ from urllib.parse import parse_qs
from .cli import comma_separated, number
from .config import REMOTE_MODES, InstallError, parse_plan, port
from .engine import Installer
from .engine import SOURCE, Installer
COOKIE = "coulobre_installer"
MAX_FORM = 16384
BRAND_MARK = SOURCE / "src/coulobre/hosting/static/hosting/coulobre-mark.svg"
FORM = """<form method="post" action="/review">
<p>Full-service setup is recommended for a public single server. The panel,
websites, databases, DNS and mail run locally. Adjust the settings below
@@ -44,7 +45,10 @@ for a different deployment.</p>
<input name="mail_sending_addresses"></label>
</fieldset>
<button type="submit">Review installation</button></form>"""
STYLE = """body{font:1rem system-ui,sans-serif;max-width:46rem;margin:auto;
STYLE = """:root{color-scheme:light}
h1{display:flex;align-items:center;gap:.65rem}
h1 img{width:1.9rem;height:1.9rem;flex:none}
body{font:1rem system-ui,sans-serif;max-width:46rem;margin:auto;
padding:1rem;color:#14372e} fieldset{margin:1rem 0;border:1px solid #a9beb2;
border-radius:.4rem;padding:1rem} label{display:block;margin-bottom:.75rem}
input,select{display:block;box-sizing:border-box;width:100%;padding:.45rem;
@@ -223,8 +227,10 @@ class WizardHandler(BaseHTTPRequestHandler):
head = '<meta http-equiv="refresh" content="2">' if refresh else ""
html = f"""<!doctype html><html lang="en"><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
{head}<title>Install Coulobre Panel</title><style>{STYLE}</style></head>
<body><main><h1>Install Coulobre Panel</h1>{body}</main></body>
<body><main><h1><img src="/favicon.svg" alt="">Install Coulobre Panel</h1>
{body}</main></body>
</html>""".encode()
self.send_response(status)
self.send_header("Cache-Control", "no-store")
@@ -234,7 +240,7 @@ class WizardHandler(BaseHTTPRequestHandler):
self.send_header("Referrer-Policy", "no-referrer")
self.send_header(
"Content-Security-Policy",
"default-src 'none'; style-src 'unsafe-inline'; "
"default-src 'none'; style-src 'unsafe-inline'; img-src 'self'; "
"form-action 'self'; frame-ancestors 'none'; base-uri 'none'",
)
if cookie:
@@ -254,12 +260,21 @@ class WizardHandler(BaseHTTPRequestHandler):
return self.headers.get("Host") == self.server.authority
def do_GET(self):
if not self.host_allowed() or self.path != "/":
if not self.host_allowed() or self.path not in {"/", "/favicon.svg"}:
self.page(
"<p>Use the installer address shown in the terminal.</p>",
status=403,
)
return
if self.path == "/favicon.svg":
svg = BRAND_MARK.read_bytes()
self.send_response(200)
self.send_header("Content-Type", "image/svg+xml")
self.send_header("Content-Length", str(len(svg)))
self.send_header("X-Content-Type-Options", "nosniff")
self.end_headers()
self.wfile.write(svg)
return
state = self.server.wizard
if not self.authorized():
self.page(
+11 -8
View File
@@ -1115,10 +1115,12 @@ sudo systemctl restart coulobre-panel coulobre-worker coulobre-beat
sudo systemctl enable --now coulobre-database-provisioner.service
```
Open a hosting account and select **Provision database** for a database request.
Reload the account page to see the status. Use **Retry provisioning** after a
reported failure. Operators need permission to view hosting accounts and
database requests and the **Can add database provisioning** permission.
Select **Add database** on a hosting account to queue its provisioning.
Customers can add databases on their own accounts. Customer managers need
permission to manage resources for their assigned accounts. For a pending
request, an operator can select **Provision database**. Operators need
permission to view hosting accounts and databases and the **Can add database
provisioning** permission. Use **Retry provisioning** after a reported failure.
The MariaDB node stores the application login in the root-only file
`/var/lib/coulobre/database-node/<database-name>.json`. Use the credentials
@@ -1774,10 +1776,11 @@ sudo systemctl restart coulobre-panel coulobre-worker coulobre-beat
sudo systemctl enable --now coulobre-dns-publisher.service
```
Open a hosting account and select **Publish zone**. Reload the account page to
see progress and the last SOA serial confirmed by the local BIND9 node.
Operators need permission to view hosting accounts and DNS zones and the
**Can add DNS publication** permission.
Select **Save and publish zone** to queue a new zone from a hosting account.
Use **Publish zone** to publish a pending revision of an existing zone.
The account page shows progress and the last SOA serial confirmed by the
local BIND9 node. Operators need permission to view hosting accounts and DNS
zones and the **Can add DNS publication** permission.
Each request captures the reviewed SOA serial and records. You can edit the
zone while it publishes. Publish the newer revision after the current request
+1
View File
@@ -42,6 +42,7 @@ server = ["gunicorn>=27.0.1,<28"]
"coulobre.hosting" = [
"static/hosting/*.js",
"static/hosting/*.css",
"static/hosting/*.svg",
"templates/*.html",
"templates/hosting/*.conf",
"templates/hosting/*.html",
+4 -2
View File
@@ -7,6 +7,7 @@ from django.views.decorators.cache import never_cache
from django.views.generic import TemplateView
from .access import OperatorOnlyMixin
from .dns_defaults import zone_defaults
@method_decorator(never_cache, name="dispatch")
@@ -22,6 +23,7 @@ class InstallationView(
except PackageNotFoundError:
installed_version = "Unavailable"
dns_defaults = zone_defaults()
features = (
("Local website provisioning", settings.LOCAL_WEB_ACTIVATION),
("Managed website certificates", settings.LOCAL_WEB_HTTPS),
@@ -31,8 +33,8 @@ class InstallationView(
(
"Default managed DNS zones for new accounts",
settings.LOCAL_DNS_PUBLISHING
and settings.HOSTING_NAMESERVERS
and settings.HOSTING_PUBLIC_ADDRESSES,
and dns_defaults.nameservers
and dns_defaults.addresses,
),
(
"Local mailbox provisioning",
+8 -2
View File
@@ -27,7 +27,9 @@ def lock_hosting_account(account_id, customer_id):
@transaction.atomic
def create_database_request(account_id, suffix, *, customer_id=None):
def create_database_request(
account_id, suffix, *, customer_id=None, auto_provision=False
):
account = lock_hosting_account(account_id, customer_id)
require_open_account(account)
databases = account.databases
@@ -45,7 +47,11 @@ def create_database_request(account_id, suffix, *, customer_id=None):
raise ValidationError(
"This hosting account has reached its database limit."
)
return databases.create(suffix=suffix)
database = databases.create(suffix=suffix)
if auto_provision:
require_active_services(account)
DatabaseProvisioning.objects.queue(database=database)
return database
@transaction.atomic
@@ -0,0 +1,16 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-12 -12 312 312">
<style>
path { fill: #15392f; }
@media (prefers-color-scheme: dark) {
path { fill: #c7e8ca; }
}
</style>
<path d="M0 199 V132 C0 104 27 89 61 78 L217 36
C245 28 263 19 263 0 C272 1 279 11 279 21 V73
C279 91 267 101 244 108 L48 169 C24 177 8 186 0 199 Z"/>
<path d="M208 124 C246 136 288 151 288 178 V239
C277 221 246 211 208 202 Z"/>
<path d="M46 175 L218 211 C259 220 280 233 286 246
C294 266 269 288 228 288 C217 288 207 287 195 284
L45 249 C16 242 0 227 0 212 C0 197 18 185 46 175 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 684 B

+15 -3
View File
@@ -168,9 +168,21 @@ button, input, select, textarea {
place-items: center;
border-radius: 0.55rem;
background: var(--brand-bg);
color: var(--brand-ink);
font-size: 1.12rem;
font-weight: 800;
}
.brand-mark::before {
content: "";
width: 66%;
height: 66%;
background: var(--brand-ink);
mask: url("coulobre-mark.svg") center / contain no-repeat;
}
@media (forced-colors: active) {
.brand-mark::before {
forced-color-adjust: none;
background: CanvasText;
}
}
.brand-product {
@@ -133,7 +133,7 @@
<section id="databases" data-account-section tabindex="-1" class="surface" aria-labelledby="databases-heading">
<header class="section-heading">
<div>
<h2 id="databases-heading" tabindex="-1">MariaDB database requests</h2>
<h2 id="databases-heading" tabindex="-1">MariaDB databases</h2>
{% if is_tenant or perms.hosting.view_hostingplan %}
{% if account.hosting_plan and account.hosting_plan.database_limit is not None %}
<p class="heading-meta">{{ databases|length }} of {{ account.hosting_plan.database_limit }} databases requested</p>
@@ -141,51 +141,50 @@
{% endif %}
</div>
{% if is_customer or reseller_resource_management or is_operator and perms.hosting.add_hostingdatabase %}
<a class="button primary" href="{% url 'panel:database_create' account.pk %}">Request database</a>
<a class="button primary" href="{% url 'panel:database_create' account.pk %}">{% if automatic_database_provisioning %}Add{% else %}Request{% endif %} database</a>
{% endif %}
</header>
{% if databases %}
<div class="table-scroll">
<table>
<thead><tr><th scope="col">Database</th>{% if is_operator or manage_database_provisioning %}<th scope="col">Deployment</th>{% endif %}</tr></thead>
<thead><tr><th scope="col">Database</th><th scope="col">Status and actions</th></tr></thead>
<tbody>
{% for database in databases %}
<tr>
<td class="domain">
{{ database }}
{% if show_database_credentials %}
<div><a class="record-link" href="{% url 'panel:database_credentials' database.pk %}" aria-label="Connection details for {{ database }}">Connection details</a></div>
{% endif %}
{% if show_phpmyadmin %}
<form method="post" action="{% url 'panel:phpmyadmin_launch' database.pk %}">
{% csrf_token %}
<button class="button secondary" type="submit">Open phpMyAdmin</button>
</form>
<th scope="row" class="domain">{{ database }}</th>
<td>
<div class="table-actions">
{% if manage_database_provisioning %}
{% url 'panel:database_provision' database.pk as provision_url %}
{% include "hosting/resource_provisioning.html" with provisioning=database.provisioning enabled=local_database_enabled action=provision_url resource=database provision_label="Provision database" %}
{% else %}
{% include "hosting/resource_provisioning.html" with provisioning=database.provisioning enabled=False %}
{% endif %}
{% if not database.provisioning %}<span class="status pending">Requested</span>{% endif %}
{% if show_database_credentials %}
<a class="record-link" href="{% url 'panel:database_credentials' database.pk %}" aria-label="Connection details for {{ database }}">Connection details</a>
{% endif %}
{% if show_phpmyadmin %}
<form method="post" action="{% url 'panel:phpmyadmin_launch' database.pk %}">
{% csrf_token %}
<button class="button secondary" type="submit">Open phpMyAdmin</button>
</form>
{% endif %}
{% if is_operator %}
<a class="record-link" href="{% url 'panel:database_manifest' database.pk %}" aria-label="Download manifest for {{ database }}">Download manifest</a>
{% endif %}
</div>
{% if is_operator and manage_database_provisioning and database.provisioning.problem %}
<p class="heading-meta">{{ database.provisioning.problem }}</p>
{% endif %}
</td>
{% if is_operator or manage_database_provisioning %}
<td>
<div class="form-actions">
{% if is_operator %}
<a class="record-link" href="{% url 'panel:database_manifest' database.pk %}" aria-label="Download manifest for {{ database }}">Download manifest</a>
{% endif %}
{% if manage_database_provisioning %}
{% url 'panel:database_provision' database.pk as provision_url %}
{% include "hosting/resource_provisioning.html" with provisioning=database.provisioning enabled=local_database_enabled action=provision_url resource=database provision_label="Provision database" %}
{% endif %}
</div>
{% if is_operator and manage_database_provisioning and database.provisioning.problem %}
<p class="heading-meta">{{ database.provisioning.problem }}</p>
{% endif %}
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<p class="empty">No databases requested yet.</p>
<p class="empty">No databases yet.</p>
{% endif %}
</section>
{% endif %}
@@ -4,8 +4,7 @@
<main class="sign-in">
<div class="sign-in-inner">
<div class="brand sign-in-brand">
<span class="brand-mark" aria-hidden="true">C</span>
<span>Coulobre <span class="brand-product">Panel</span></span>
{% include "hosting/brand.html" %}
</div>
<section class="sign-in-card">
{% block authentication_content %}{% include "hosting/authentication_card.html" %}{% endblock %}
@@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}Coulobre Panel{% endblock %}</title>
<link rel="icon" type="image/svg+xml" href="{% static 'hosting/coulobre-mark.svg' %}">
<link rel="stylesheet" href="{% static 'hosting/panel.css' %}">
{% if custom_panel_theme %}<link rel="stylesheet" href="{% url 'panel:theme_stylesheet' %}">{% endif %}
<script src="{% static 'hosting/panel-appearance.js' %}"></script>
@@ -14,8 +15,7 @@
<div class="panel">
<aside class="sidebar">
<a class="brand" href="{% url 'panel:accounts' %}">
<span class="brand-mark" aria-hidden="true">C</span>
<span>Coulobre <span class="brand-product">Panel</span></span>
{% include "hosting/brand.html" %}
</a>
<button class="menu-toggle" type="button" aria-controls="panel-navigation" aria-expanded="true" hidden>
<span class="menu-icon" aria-hidden="true"></span>
@@ -0,0 +1,2 @@
<span class="brand-mark" aria-hidden="true"></span>
<span>Coulobre <span class="brand-product">Panel</span></span>
@@ -1,15 +1,15 @@
{% extends "hosting/base.html" %}
{% block title %}Request MariaDB database · Coulobre Panel{% endblock %}
{% block title %}{% if auto_provision %}Add{% else %}Request{% endif %} MariaDB database · Coulobre Panel{% endblock %}
{% block content %}
<a class="back-link" href="{{ account.get_absolute_url }}">← {{ account.name }}</a>
<header class="page-heading"><h1>Request MariaDB database</h1></header>
<header class="page-heading"><h1>{% if auto_provision %}Add{% else %}Request{% endif %} MariaDB database</h1></header>
<section class="surface editor-surface">
<form method="post" class="editor">
{% include "hosting/customer_action_fields.html" %}
{{ form.as_div }}
<div class="form-actions">
{% if can_request_resource %}
<button class="button primary" type="submit">Request database</button>
<button class="button primary" type="submit">{% if auto_provision %}Add{% else %}Request{% endif %} database</button>
{% endif %}
<a class="button secondary" href="{{ account.get_absolute_url }}">Cancel</a>
</div>
@@ -37,7 +37,7 @@
<script src="{% static 'hosting/dns-record-editor.js' %}" defer></script>
{% endif %}
<div class="form-actions">
<button class="button primary" type="submit">Save zone</button>
<button class="button primary" type="submit">{% if publish_on_create %}Save and publish zone{% else %}Save zone{% endif %}</button>
<a class="button secondary" href="{{ account.get_absolute_url }}">Cancel</a>
</div>
</form>
@@ -25,7 +25,14 @@
{% for name, enabled in features %}
<tr>
<th scope="row">{{ name }}</th>
<td>{% if enabled %}<span class="status active">Enabled</span>{% else %}Disabled{% endif %}</td>
<td>
<div class="table-actions">
{% if enabled %}<span class="status active">Enabled</span>{% else %}<span>Disabled</span>{% endif %}
{% if request.user.is_superuser and name == 'Default managed DNS zones for new accounts' %}
<a class="record-link" href="{% url 'panel:dns_defaults' %}">Configure DNS defaults</a>
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
@@ -4,8 +4,7 @@
<main class="sign-in">
<div class="sign-in-inner">
<div class="brand sign-in-brand">
<span class="brand-mark" aria-hidden="true">C</span>
<span>Coulobre <span class="brand-product">Panel</span></span>
{% include "hosting/brand.html" %}
</div>
<section class="sign-in-card">
<h1>Sign in</h1>
@@ -1,10 +1,10 @@
{% extends "hosting/base.html" %}
{% block title %}{% if automatic_mailbox_provisioning %}Add{% else %}Request{% endif %} mailbox · Coulobre Panel{% endblock %}
{% block title %}{% if auto_provision %}Add{% else %}Request{% endif %} mailbox · Coulobre Panel{% endblock %}
{% block content %}
<a class="back-link" href="{{ account.get_absolute_url }}">← {{ account.name }}</a>
<header class="page-heading">
<div>
<h1>{% if automatic_mailbox_provisioning %}Add{% else %}Request{% endif %} mailbox</h1>
<h1>{% if auto_provision %}Add{% else %}Request{% endif %} mailbox</h1>
<p class="heading-meta domain">{{ account.primary_domain }}</p>
</div>
</header>
@@ -14,7 +14,7 @@
{{ form.as_div }}
<div class="form-actions">
{% if can_request_resource %}
<button class="button primary" type="submit">{% if automatic_mailbox_provisioning %}Add{% else %}Request{% endif %} mailbox</button>
<button class="button primary" type="submit">{% if auto_provision %}Add{% else %}Request{% endif %} mailbox</button>
{% endif %}
<a class="button secondary" href="{{ account.get_absolute_url }}">Cancel</a>
</div>
@@ -87,6 +87,34 @@ class DatabaseProvisioningTests(TestCase):
self.assertEqual(self.client.post(self.url).status_code, 403)
self.assertFalse(DatabaseProvisioning.objects.exists())
def test_customer_creation_queues_a_database_and_shows_its_status(self):
self.client.force_login(self.user)
url = reverse("panel:database_create", args=[self.account.pk])
self.assertContains(self.client.get(url), "Add database")
self.assertRedirects(
self.client.post(url, {"suffix": "new"}), self.detail
)
job = DatabaseProvisioning.objects.get(database__suffix="new")
self.assertEqual(job.state, "queued")
self.assertContains(self.client.get(self.detail), "Queued")
def test_operator_without_provisioning_permission_creates_a_request(self):
requester = get_user_model().objects.create_user("requester")
requester.user_permissions.add(
*self.permissions.exclude(codename="add_databaseprovisioning"),
Permission.objects.get(codename="add_hostingdatabase"),
)
self.client.force_login(requester)
url = reverse("panel:database_create", args=[self.account.pk])
self.assertContains(self.client.get(url), "Request database")
self.assertRedirects(
self.client.post(url, {"suffix": "request"}), self.detail
)
self.assertTrue(
self.account.databases.filter(suffix="request").exists()
)
self.assertFalse(DatabaseProvisioning.objects.exists())
@override_settings(LOCAL_DATABASE_PROVISIONING=False)
def test_disabled_provisioning_preserves_existing_manifest_download(self):
detail = self.client.get(self.detail)
@@ -42,6 +42,31 @@ class DnsPublicationTests(TestCase):
self.url = reverse("panel:dns_zone_publish", args=[self.zone.pk])
self.detail = self.account.get_absolute_url()
def test_creating_a_managed_zone_queues_its_first_snapshot(self):
account = HostingAccount.objects.create(
name="Example DNS", primary_domain="new.example"
)
url = reverse("panel:dns_zone_create", args=[account.pk])
self.assertContains(self.client.get(url), "Save and publish zone")
self.assertRedirects(
self.client.post(
url,
{
"nameservers": "ns.provider.example",
"responsible_name": "hostmaster.new.example",
"addresses": "new.example 192.0.2.20",
},
),
account.get_absolute_url(),
)
zone = account.dns_zones.get()
self.assertEqual(
(zone.publication.state, zone.publication.serial), ("queued", 1)
)
self.assertEqual(
DnsZone.from_manifest(zone.publication.manifest), zone.spec
)
def test_queued_snapshot_survives_edits_and_next_revision_can_publish(
self,
):
@@ -196,13 +196,11 @@ class ResellerOnboardingTests(TestCase):
for model, resource in (("database", database), ("mailbox", mailbox)):
url = reverse(f"panel:{model}_provision", args=[resource.pk])
manifest = reverse(f"panel:{model}_manifest", args=[resource.pk])
if model == "database":
self.assertContains(
self.client.get(detail), "Provision database"
)
else:
self.assertEqual(mailbox.provisioning.state, "queued")
self.assertContains(self.client.get(detail), "Queued")
self.assertEqual(resource.provisioning.state, "queued")
self.assertContains(self.client.get(detail), "Queued")
self.assertNotContains(
self.client.get(detail), f"Provision {model}"
)
self.assertEqual(self.client.get(manifest).status_code, 403)
for _ in range(2):
self.assertRedirects(self.client.post(url), detail)
@@ -214,7 +212,7 @@ class ResellerOnboardingTests(TestCase):
"action", flat=True
)
),
[Action.RESOURCE_REQUEST] * 2 + [Action.RESOURCE_PROVISION] * 2,
[Action.RESOURCE_REQUEST, Action.RESOURCE_PROVISION] * 2,
)
DatabaseProvisioning.objects.update(
finished_at=timezone.now(), problem="Failed"
+19 -1
View File
@@ -20,7 +20,7 @@ from coulobre.service_health import (
main,
)
from .models import Customer, Reseller, ServiceHealth
from .models import Customer, DnsZoneDefaults, Reseller, ServiceHealth
TARGETS = (
HealthTarget("panel-01", "local", ("mariadb", "apache")),
@@ -196,6 +196,24 @@ class ServiceHealthPanelTests(TestCase):
self.assertNotContains(response, "test-only-bridge-key")
self.assertNotContains(response, "https://webmail.example.net")
@override_settings(
LOCAL_DNS_PUBLISHING=True,
HOSTING_NAMESERVERS=(),
HOSTING_PUBLIC_ADDRESSES=(),
)
def test_installation_reports_dns_defaults_saved_in_the_panel(self):
DnsZoneDefaults.objects.create(
pk=1, nameservers=["ns.example.net"], addresses=["192.0.2.20"]
)
self.client.force_login(self.admin)
response = self.client.get(reverse("panel:installation"))
self.assertTrue(
dict(response.context["features"])[
"Default managed DNS zones for new accounts"
]
)
self.assertContains(response, "Configure DNS defaults")
def test_view_marks_missing_and_old_observations_distinctly(self):
now = timezone.now()
for node, service, result, observed_at in (
+52 -24
View File
@@ -238,10 +238,8 @@ PROVISION_MAILBOX = (
CHANGE_MAILBOX_QUOTA = (*PROVISION_MAILBOX, "hosting.change_hostingmailbox")
def automatic_mailbox_provisioning(user):
return settings.LOCAL_MAILBOX_PROVISIONING and (
is_tenant(user) or user.has_perms(PROVISION_MAILBOX)
)
def automatic_resource_provisioning(user, enabled, permissions):
return enabled and (is_tenant(user) or user.has_perms(permissions))
def missing_account_setup(account, actor):
@@ -830,11 +828,17 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
"show_mailbox_credentials"
] and roundcube_available(self.request)
if tenant or user.has_perm(VIEW_DATABASES):
databases = self.object.databases.all()
context["automatic_database_provisioning"] = (
automatic_resource_provisioning(
user,
settings.LOCAL_DATABASE_PROVISIONING,
PROVISION_DATABASE,
)
)
databases = self.object.databases.select_related("provisioning")
if manage_resources or (
not tenant and user.has_perms(PROVISION_DATABASE)
):
databases = databases.select_related("provisioning")
context["manage_database_provisioning"] = True
context["local_database_enabled"] = (
settings.LOCAL_DATABASE_PROVISIONING
@@ -898,7 +902,11 @@ class AccountDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
)
if tenant or user.has_perm(VIEW_MAILBOXES):
context["automatic_mailbox_provisioning"] = (
automatic_mailbox_provisioning(user)
automatic_resource_provisioning(
user,
settings.LOCAL_MAILBOX_PROVISIONING,
PROVISION_MAILBOX,
)
)
context["manage_mail_routing"] = mail_policy_enabled(
self.request, "routing"
@@ -1932,6 +1940,8 @@ def provisioning_conflict(error):
class ResourceRequestCreate(PermissionRequiredMixin, CreateView):
audit_operation = None
provisioning_setting = None
provisioning_permissions = ()
@cached_property
def customer(self):
@@ -1959,9 +1969,23 @@ class ResourceRequestCreate(PermissionRequiredMixin, CreateView):
return super().get_context_data(
account=self.account,
can_request_resource=can_edit_customer_resource(self.request),
auto_provision=self.auto_provision,
**kwargs,
)
@cached_property
def auto_provision(self):
return automatic_resource_provisioning(
self.request.user,
getattr(settings, self.provisioning_setting),
self.provisioning_permissions,
)
def create_request(self, account_id, **values):
return self.create_resource(
account_id, auto_provision=self.auto_provision, **values
)
def get_form(self, form_class=None):
form = super().get_form(form_class)
if not can_edit_customer_resource(self.request):
@@ -2008,7 +2032,9 @@ class DatabaseCreate(ResourceRequestCreate):
template_name = "hosting/database_form.html"
permission_required = CUSTOMER_WRITE_PERMISSIONS["panel:database_create"]
audit_operation = CustomerImpersonationAction.Operation.DATABASE
create_request = staticmethod(create_database_request)
provisioning_setting = "LOCAL_DATABASE_PROVISIONING"
provisioning_permissions = PROVISION_DATABASE
create_resource = staticmethod(create_database_request)
class DownloadDatabaseManifest(
@@ -2129,6 +2155,17 @@ class DnsZoneCreate(OperatorOnlyMixin, DnsZoneEditor):
"record_rows": "[]",
}
@cached_property
def publish_on_create(self):
return settings.LOCAL_DNS_PUBLISHING and self.request.user.has_perms(
PUBLISH_DNS
)
def get_context_data(self, **kwargs):
return super().get_context_data(
publish_on_create=self.publish_on_create, **kwargs
)
def form_valid(self, form):
try:
with transaction.atomic():
@@ -2136,12 +2173,14 @@ class DnsZoneCreate(OperatorOnlyMixin, DnsZoneEditor):
self.account.pk, customer_id=None
)
require_open_account(account)
HostingDnsZone.objects.create(
zone = HostingDnsZone.objects.create(
account=account,
domain=account.primary_domain,
**form.cleaned_data,
)
except ValidationError as error:
if self.publish_on_create:
queue_dns_publication(zone.pk, str(zone.serial))
except (ValidationError, ValueError) as error:
form.add_error(None, error)
return self.form_invalid(form)
except IntegrityError:
@@ -2332,20 +2371,9 @@ class MailboxCreate(ResourceRequestCreate):
permission_required = CUSTOMER_WRITE_PERMISSIONS["panel:mailbox_create"]
audit_operation = CustomerImpersonationAction.Operation.MAILBOX
def create_request(self, account_id, **values):
return create_mailbox_request(
account_id,
auto_provision=automatic_mailbox_provisioning(self.request.user),
**values,
)
def get_context_data(self, **kwargs):
return super().get_context_data(
automatic_mailbox_provisioning=automatic_mailbox_provisioning(
self.request.user
),
**kwargs,
)
provisioning_setting = "LOCAL_MAILBOX_PROVISIONING"
provisioning_permissions = PROVISION_MAILBOX
create_resource = staticmethod(create_mailbox_request)
def get_form(self, form_class=None):
form = super().get_form(form_class)