Add read-only customer impersonation for administrators #18
No files matched your search
@@ -4,7 +4,8 @@ Coulobre Panel is an open-source web hosting control panel for hosting providers
|
||||
and resellers. The project is in early development.
|
||||
|
||||
The web panel gives operators a workspace to manage hosting accounts, request
|
||||
Apache configuration previews, and follow their progress.
|
||||
Apache configuration previews, and follow their progress. Administrators with
|
||||
permission can view the panel as a customer in a read-only support session.
|
||||
See [Local development](docs/development.md) to run it.
|
||||
See [Single-server deployment](docs/deployment.md) to install it with Apache,
|
||||
MariaDB, and RabbitMQ.
|
||||
@@ -13,8 +14,6 @@ MariaDB, and RabbitMQ.
|
||||
|
||||
- Self-hosted installation on a single Ubuntu server, with Debian support planned.
|
||||
- Hosting plans and self-service access for administrators, resellers, and customers.
|
||||
- Customer impersonation for administrator support, with a dedicated permission,
|
||||
a visible session indicator, and an audit trail.
|
||||
- Domains, TLS certificates, SFTP, and databases using Apache, PHP-FPM, and MariaDB.
|
||||
- Mail and DNS on the hosting server or on separate servers.
|
||||
- Account backups, restore, and migration from DirectAdmin.
|
||||
|
||||
@@ -79,6 +79,26 @@ and select a customer on hosting accounts they can create or edit. **Can add
|
||||
customer** enables customer creation. **Can change customer** enables
|
||||
sign-in suspension and restoration.
|
||||
|
||||
## View the panel as a customer
|
||||
|
||||
In **Customers**, select **View as customer** next to an active customer.
|
||||
The panel shows the customer's assigned hosting accounts and resource pages.
|
||||
Request forms are visible with their inputs disabled. The banner identifies
|
||||
the customer and offers **End customer view**. Ending the view returns you
|
||||
to your administrator account. Signing out ends the view and signs you out
|
||||
of the panel.
|
||||
|
||||
A support session lasts up to 30 minutes and applies to the current browser
|
||||
session. The panel checks that both users remain eligible on each request.
|
||||
For example, suspending the customer or removing the administrator's
|
||||
permission ends the view on the next request.
|
||||
|
||||
A staff user needs both **Can view customer** and **Can view the panel as a
|
||||
customer**. The second permission is listed under **Customer impersonation
|
||||
sessions**. In `/admin/`, users with **Can view customer impersonation
|
||||
session** can review the administrator, customer, timestamps, and outcome
|
||||
for each session. The audit records are read-only in Django admin.
|
||||
|
||||
## Request a MariaDB database
|
||||
|
||||
Open a hosting account and select **Request database**. Choose a short suffix
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
from django.utils.timezone import now
|
||||
|
||||
from .models import (
|
||||
Customer,
|
||||
CustomerImpersonation,
|
||||
HostingAccount,
|
||||
HostingPlan,
|
||||
Reseller,
|
||||
@@ -75,6 +77,45 @@ class CustomerAdmin(admin.ModelAdmin):
|
||||
search_fields = ("user__username",)
|
||||
|
||||
|
||||
@admin.register(CustomerImpersonation)
|
||||
class CustomerImpersonationAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
"operator_username",
|
||||
"customer_username",
|
||||
"started_at",
|
||||
"expires_at",
|
||||
"ended_at",
|
||||
"outcome",
|
||||
)
|
||||
search_fields = ("operator_username", "customer_username")
|
||||
fields = (
|
||||
"operator_username",
|
||||
"customer_username",
|
||||
"started_at",
|
||||
"expires_at",
|
||||
"ended_at",
|
||||
"outcome",
|
||||
)
|
||||
readonly_fields = fields
|
||||
|
||||
@admin.display(description="Outcome")
|
||||
def outcome(self, obj):
|
||||
if obj.ended_at is not None:
|
||||
return obj.get_end_reason_display()
|
||||
if obj.expires_at <= now():
|
||||
return CustomerImpersonation.EndReason.EXPIRED.label
|
||||
return "Open"
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return False
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
|
||||
@admin.register(WebProvisioningPlan)
|
||||
class WebProvisioningPlanAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import Customer, CustomerImpersonation
|
||||
|
||||
|
||||
class CustomerImpersonationAuditTests(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
users = get_user_model().objects
|
||||
cls.operator = users.create_superuser("operator")
|
||||
cls.customer = Customer.objects.create(user=users.create_user("alice"))
|
||||
cutoff = timezone.now() - timedelta(minutes=1)
|
||||
cls.entry = CustomerImpersonation.objects.create(
|
||||
operator=cls.operator,
|
||||
customer=cls.customer,
|
||||
operator_username="operator",
|
||||
customer_username="alice",
|
||||
started_at=cutoff - timedelta(minutes=30),
|
||||
expires_at=cutoff,
|
||||
)
|
||||
|
||||
def test_audit_list_requires_the_separate_view_permission(self):
|
||||
auditor = get_user_model().objects.create_user(
|
||||
"auditor", is_staff=True
|
||||
)
|
||||
auditor.user_permissions.add(
|
||||
Permission.objects.get(
|
||||
content_type__app_label="hosting",
|
||||
codename="impersonate_customer",
|
||||
)
|
||||
)
|
||||
self.client.force_login(auditor)
|
||||
audit_url = reverse("admin:hosting_customerimpersonation_changelist")
|
||||
self.assertEqual(self.client.get(audit_url).status_code, 403)
|
||||
|
||||
auditor.user_permissions.add(
|
||||
Permission.objects.get(
|
||||
content_type__app_label="hosting",
|
||||
codename="view_customerimpersonation",
|
||||
)
|
||||
)
|
||||
response = self.client.get(audit_url)
|
||||
self.assertContains(response, "alice")
|
||||
self.assertContains(response, "Expired")
|
||||
|
||||
def test_audit_retains_usernames_and_disallows_manual_edits(self):
|
||||
self.customer.delete()
|
||||
self.client.force_login(self.operator)
|
||||
url = reverse(
|
||||
"admin:hosting_customerimpersonation_change",
|
||||
args=[self.entry.pk],
|
||||
)
|
||||
response = self.client.get(url)
|
||||
self.assertContains(response, "alice")
|
||||
self.assertNotContains(response, 'name="_save"')
|
||||
self.assertEqual(self.client.post(url).status_code, 403)
|
||||
for view, args in (
|
||||
("admin:hosting_customerimpersonation_add", ()),
|
||||
("admin:hosting_customerimpersonation_delete", (self.entry.pk,)),
|
||||
):
|
||||
with self.subTest(view=view):
|
||||
self.assertEqual(
|
||||
self.client.post(reverse(view, args=args)).status_code,
|
||||
403,
|
||||
)
|
||||
self.entry.refresh_from_db()
|
||||
self.assertIsNone(self.entry.customer)
|
||||
self.assertEqual(self.entry.customer_username, "alice")
|
||||
Reference in new issue
Block a user