2022-02-02 17:16:35 +01:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
from posthog.models.dashboard import Dashboard
|
|
|
|
from posthog.models.utils import UUIDModel, sane_repr
|
|
|
|
|
|
|
|
|
|
|
|
# We call models that grant a user access to some resource (which isn't a grouping of users) a "privilege"
|
|
|
|
class DashboardPrivilege(UUIDModel):
|
2024-08-22 11:42:25 +02:00
|
|
|
dashboard = models.ForeignKey(
|
2023-10-26 12:38:15 +02:00
|
|
|
"posthog.Dashboard",
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="privileges",
|
|
|
|
related_query_name="privilege",
|
2022-02-02 17:16:35 +01:00
|
|
|
)
|
2024-08-22 11:42:25 +02:00
|
|
|
user = models.ForeignKey(
|
2022-02-02 17:16:35 +01:00
|
|
|
"posthog.User",
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="explicit_dashboard_privileges",
|
|
|
|
related_query_name="explicit_dashboard_privilege",
|
|
|
|
)
|
2024-08-22 11:42:25 +02:00
|
|
|
level = models.PositiveSmallIntegerField(choices=Dashboard.RestrictionLevel.choices)
|
|
|
|
added_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
updated_at = models.DateTimeField(auto_now=True)
|
2022-02-02 17:16:35 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
constraints = [
|
2022-09-05 14:38:54 +02:00
|
|
|
models.UniqueConstraint(fields=["dashboard", "user"], name="unique_explicit_dashboard_privilege")
|
2022-02-02 17:16:35 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
__repr__ = sane_repr("dashboard", "user", "level")
|