0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-22 08:40:03 +01:00
posthog/ee/models/organization_resource_access.py
Julian Bez 34d0da70d9
chore(deps): Upgrade mypy, stubs, and ruff (#24500)
Also remove type annotations for Django fields, due to updates to the 
stubs and possibly to mypy they are actively unhelpful now.
2024-08-22 09:42:25 +00:00

40 lines
1.5 KiB
Python

from django.db import models
from posthog.models.organization import Organization
class OrganizationResourceAccess(models.Model):
class AccessLevel(models.IntegerChoices):
"""Level for which a role or user can edit or view resources"""
CAN_ONLY_VIEW = 21, "Can only view"
CAN_ALWAYS_EDIT = 37, "Can always edit"
class Resources(models.TextChoices):
FEATURE_FLAGS = "feature flags", "feature flags"
EXPERIMENTS = "experiments", "experiments"
COHORTS = "cohorts", "cohorts"
DATA_MANAGEMENT = "data management", "data management"
SESSION_RECORDINGS = "session recordings", "session recordings"
INSIGHTS = "insights", "insights"
DASHBOARDS = "dashboards", "dashboards"
resource = models.CharField(max_length=32, choices=Resources.choices)
access_level = models.PositiveSmallIntegerField(default=AccessLevel.CAN_ALWAYS_EDIT, choices=AccessLevel.choices)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE, related_name="resource_access")
created_by = models.ForeignKey(
"posthog.User",
on_delete=models.SET_NULL,
null=True,
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
constraints = [
models.UniqueConstraint(
fields=["organization", "resource"],
name="unique resource per organization",
)
]