Add read-only customer impersonation for administrators
This commit is contained in:
1 parent
5ef564f506
commit
bfe199aaff
13 files changed
+657
-15
No files matched your search
@@ -56,6 +56,56 @@ class Customer(models.Model):
|
||||
def __str__(self):
|
||||
return self.user.get_username()
|
||||
|
||||
@property
|
||||
def may_be_impersonated(self):
|
||||
user = self.user
|
||||
return (
|
||||
user.is_active
|
||||
and not user.is_staff
|
||||
and not user.is_superuser
|
||||
and not hasattr(user, "hosting_reseller")
|
||||
)
|
||||
|
||||
|
||||
class CustomerImpersonation(models.Model):
|
||||
class EndReason(models.TextChoices):
|
||||
STOPPED = "stopped", "Ended by administrator"
|
||||
SIGNED_OUT = "signed_out", "Signed out"
|
||||
EXPIRED = "expired", "Expired"
|
||||
ACCESS_REVOKED = "access_revoked", "Access revoked"
|
||||
|
||||
operator = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
related_name="+",
|
||||
)
|
||||
customer = models.ForeignKey(
|
||||
Customer,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
related_name="+",
|
||||
)
|
||||
operator_username = models.CharField(max_length=150)
|
||||
customer_username = models.CharField(max_length=150)
|
||||
started_at = models.DateTimeField(default=timezone.now)
|
||||
expires_at = models.DateTimeField()
|
||||
ended_at = models.DateTimeField(null=True, blank=True)
|
||||
end_reason = models.CharField(
|
||||
max_length=16, choices=EndReason.choices, blank=True
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ("-started_at", "-pk")
|
||||
default_permissions = ("view",)
|
||||
verbose_name = "customer impersonation session"
|
||||
permissions = (
|
||||
("impersonate_customer", "Can view the panel as a customer"),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.operator_username} viewing as {self.customer_username}"
|
||||
|
||||
|
||||
class HostingPlan(models.Model):
|
||||
name = models.CharField(max_length=120, unique=True)
|
||||
|
||||
Reference in new issue
Block a user