mirror of
https://github.com/PostHog/posthog.git
synced 2024-12-01 04:12:23 +01:00
0257b2bcb9
* Use ruff formatter Ruff is now also a formatter! And it runs in a fraction of a second across our whole codebase vs "I waited more than 30s and cancelled it because I got bored". * Config and command -> ruff * Run 'ruff format .' * Update query snapshots * Run 'ruff format .' * Fix format after commit hook * Update query snapshots * Fix type error - ignore comment moved * Exclude hogql grammar from formatting and reverted grammar * Run format --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Tom Owers <tom@paace.co>
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
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",
|
|
)
|
|
feature_flags_access_level: models.PositiveSmallIntegerField = models.PositiveSmallIntegerField(
|
|
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",
|
|
)
|
|
user: models.ForeignKey = models.ForeignKey(
|
|
"posthog.User",
|
|
on_delete=models.CASCADE,
|
|
related_name="role_memberships",
|
|
related_query_name="role_membership",
|
|
)
|
|
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")]
|