Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add access control model #26076

Merged
merged 4 commits into from
Nov 8, 2024
Merged

feat: add access control model #26076

merged 4 commits into from
Nov 8, 2024

Conversation

zlwaterfield
Copy link
Contributor

@zlwaterfield zlwaterfield commented Nov 7, 2024

Changes

Adding the access control model for RBAC. Not changes to functionality and the model is not yet used anywhere

See #24512 for more information.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

It doesn't have an impact

How did you test this code?

Coming with next PR.

@zlwaterfield zlwaterfield changed the title feat:add access control model (with migration) feat: add access control model Nov 7, 2024
)

# Optional scope it to a specific role
role: models.ForeignKey = models.ForeignKey(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these python code quality checks are weird.... Not sure if something has changed in the way we do foreign key relations? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was from the :models. ForeignKey types. We don't use those. If we want to then we'd need to do something like

organization_member: Optional[models.ForeignKey["posthog.OrganizationMembership"]] = models.ForeignKey(
        "posthog.OrganizationMembership",
        on_delete=models.CASCADE,
        related_name="access_controls",
        related_query_name="access_controls",
        null=True,
    )

)

# Configuration of what we are accessing
access_level: models.CharField = models.CharField(max_length=32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we have the available access levels defined somewhere, so could we include choices in this field to have autovalidation, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to do db level validation to avoid migrations needed so it'll all be in the serializer. Coming soon :)

@@ -5,17 +5,17 @@


class Role(UUIDModel):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes to this file, just clean up.

@@ -138,7 +138,7 @@ def update_billing(self, organization: Organization, data: dict[str, Any]) -> No

def update_billing_organization_users(self, organization: Organization) -> None:
try:
distinct_ids = list(organization.members.values_list("distinct_id", flat=True))
distinct_ids = list(organization.members.values_list("distinct_id", flat=True)) # type: ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why these started throwing errors in this PR. I didn't make any changes related.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to ignore and update baseline

@zlwaterfield zlwaterfield merged commit 23db954 into master Nov 8, 2024
89 checks passed
@zlwaterfield zlwaterfield deleted the zach/rbac/2 branch November 8, 2024 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants