2022-11-24 02:36:29 +01:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
from ee.models.organization_resource_access import OrganizationResourceAccess
|
|
|
|
from posthog.models.utils import UUIDModel
|
|
|
|
|
|
|
|
|
|
|
|
class Role(UUIDModel):
|
|
|
|
name: models.CharField = models.CharField(max_length=200)
|
|
|
|
organization: models.ForeignKey = models.ForeignKey(
|
|
|
|
"posthog.Organization",
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="roles",
|
|
|
|
related_query_name="role",
|
|
|
|
)
|
2023-10-31 14:41:57 +01:00
|
|
|
feature_flags_access_level: models.PositiveSmallIntegerField = models.PositiveSmallIntegerField(
|
2022-11-24 02:36:29 +01:00
|
|
|
default=OrganizationResourceAccess.AccessLevel.CAN_ALWAYS_EDIT,
|
|
|
|
choices=OrganizationResourceAccess.AccessLevel.choices,
|
|
|
|
)
|
|
|
|
created_at: models.DateTimeField = models.DateTimeField(auto_now_add=True)
|
|
|
|
created_by: models.ForeignKey = models.ForeignKey(
|
|
|
|
"posthog.User",
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
related_name="roles",
|
|
|
|
related_query_name="role",
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
constraints = [models.UniqueConstraint(fields=["organization", "name"], name="unique_role_name")]
|
|
|
|
|
|
|
|
|
|
|
|
class RoleMembership(UUIDModel):
|
|
|
|
role: models.ForeignKey = models.ForeignKey(
|
|
|
|
"Role",
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="roles",
|
|
|
|
related_query_name="role",
|
|
|
|
)
|
2024-03-18 10:09:35 +01:00
|
|
|
# TODO: Eventually remove this as we only need the organization membership
|
2022-11-24 02:36:29 +01:00
|
|
|
user: models.ForeignKey = models.ForeignKey(
|
|
|
|
"posthog.User",
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="role_memberships",
|
|
|
|
related_query_name="role_membership",
|
|
|
|
)
|
2024-03-18 10:09:35 +01:00
|
|
|
|
|
|
|
organization_member: models.ForeignKey = models.ForeignKey(
|
|
|
|
"posthog.OrganizationMembership",
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="role_memberships",
|
|
|
|
related_query_name="role_membership",
|
|
|
|
null=True,
|
|
|
|
)
|
2022-11-24 02:36:29 +01:00
|
|
|
joined_at: models.DateTimeField = models.DateTimeField(auto_now_add=True)
|
|
|
|
updated_at: models.DateTimeField = models.DateTimeField(auto_now=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
constraints = [models.UniqueConstraint(fields=["role", "user"], name="unique_user_and_role")]
|