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: Personal API key scopes #20151

Merged
merged 230 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 211 commits
Commits
Show all changes
230 commits
Select commit Hold shift + click to select a range
80d8c8d
Started adding scopes
benjackwhite Feb 6, 2024
38fdfcc
Remove duplicate permission model
benjackwhite Feb 6, 2024
6ea7094
Removed unused clas
benjackwhite Feb 6, 2024
f7f4f13
Update query snapshots
github-actions[bot] Feb 6, 2024
b666cf0
Update query snapshots
github-actions[bot] Feb 6, 2024
4069bd3
Fix up scopes detection
benjackwhite Feb 6, 2024
6ff269f
fix
benjackwhite Feb 6, 2024
ec27026
Fix
benjackwhite Feb 6, 2024
d383f94
Fixes
benjackwhite Feb 6, 2024
9dd4d6b
Fixes
benjackwhite Feb 6, 2024
f3870ac
Fixed up scopes form
benjackwhite Feb 6, 2024
5832a75
Fixes
benjackwhite Feb 6, 2024
37892d4
Fix
benjackwhite Feb 6, 2024
8173fef
Fix
benjackwhite Feb 6, 2024
616f323
Fix
benjackwhite Feb 6, 2024
5239975
Fixed tests
benjackwhite Feb 6, 2024
e186c61
Fix
benjackwhite Feb 6, 2024
eae56c0
Removed duplicate permissions
benjackwhite Feb 7, 2024
4559d4a
merge
benjackwhite Feb 7, 2024
3d5614d
Merge branch 'chore/cleanup-api' into feat/simplify-permissions
benjackwhite Feb 7, 2024
963e342
Update query snapshots
github-actions[bot] Feb 7, 2024
c186629
Update query snapshots
github-actions[bot] Feb 7, 2024
f05009a
Fixes
benjackwhite Feb 7, 2024
6dd8475
Merge branch 'feat/simplify-permissions' of github.com:PostHog/postho…
benjackwhite Feb 7, 2024
a11a5de
Fixes
benjackwhite Feb 7, 2024
e763d06
Merge branch 'chore/cleanup-api' into feat/simplify-permissions
benjackwhite Feb 7, 2024
d15cde4
Update query snapshots
github-actions[bot] Feb 7, 2024
c4dd215
Fix comments
benjackwhite Feb 7, 2024
414a31d
Merge branch 'feat/simplify-permissions' of github.com:PostHog/postho…
benjackwhite Feb 7, 2024
6699f9c
Remove other code
benjackwhite Feb 7, 2024
a5e94f0
Update query snapshots
github-actions[bot] Feb 7, 2024
fbb2972
Update query snapshots
github-actions[bot] Feb 7, 2024
0b0d469
Fix naming
benjackwhite Feb 7, 2024
0a46045
Fixes
benjackwhite Feb 7, 2024
32fb5c1
Merge branch 'master' into chore/cleanup-api
Twixes Feb 7, 2024
3e09997
fix
benjackwhite Feb 7, 2024
5a4d3f0
Update query snapshots
github-actions[bot] Feb 7, 2024
61cadc6
Fix
benjackwhite Feb 7, 2024
5996c9d
Fix
benjackwhite Feb 7, 2024
d82571b
Fix
benjackwhite Feb 7, 2024
759cfc9
Fix
benjackwhite Feb 7, 2024
39d2670
Fix
benjackwhite Feb 7, 2024
dccc946
Merge branch 'chore/cleanup-api' into feat/simplify-permissions
benjackwhite Feb 7, 2024
c1189f3
Fixes
benjackwhite Feb 7, 2024
260a05c
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 7, 2024
126cf84
Added new routes
benjackwhite Feb 7, 2024
5a99cf8
Merge branch 'feat/simplify-permissions' into feat/api-scopes-with-re…
benjackwhite Feb 7, 2024
38baecf
Update query snapshots
github-actions[bot] Feb 7, 2024
8b4b882
Update query snapshots
github-actions[bot] Feb 7, 2024
580a648
Fixes
benjackwhite Feb 7, 2024
a1f41b4
Update query snapshots
github-actions[bot] Feb 7, 2024
58435d7
Fix
benjackwhite Feb 8, 2024
b0706c6
Fix typings
benjackwhite Feb 8, 2024
f7443f9
Fix up logic
benjackwhite Feb 8, 2024
c6fc093
Merge branch 'master' into feat/simplify-permissions
benjackwhite Feb 8, 2024
147ebdb
Merge branch 'personal-api-key-scopes' of github.com:PostHog/posthog …
benjackwhite Feb 8, 2024
17941ad
Merge branch 'personal-api-key-scopes' into feat/api-scopes-with-refa…
benjackwhite Feb 8, 2024
5b13a57
Merge branch 'feat/simplify-permissions' into feat/api-scopes-with-re…
benjackwhite Feb 8, 2024
8005fbd
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 8, 2024
1db2f25
Fixes
benjackwhite Feb 8, 2024
75fba44
Fixes
benjackwhite Feb 8, 2024
7ca8b52
Fixes
benjackwhite Feb 8, 2024
17c6374
Update query snapshots
github-actions[bot] Feb 8, 2024
e490a3c
Update query snapshots
github-actions[bot] Feb 8, 2024
9150c65
Fix routing
benjackwhite Feb 8, 2024
68eb183
Fixes
benjackwhite Feb 8, 2024
4095398
Merge branch 'feat/simplify-permissions' into personal-api-key-scopes
benjackwhite Feb 8, 2024
f7ff542
Adde perms
benjackwhite Feb 8, 2024
dd9701a
Update UI snapshots for `chromium` (2)
github-actions[bot] Feb 8, 2024
370f99b
Fixed up codes
benjackwhite Feb 8, 2024
6cb9c0d
Merge branch 'feat/simplify-permissions' into personal-api-key-scopes
benjackwhite Feb 8, 2024
cae0791
Fixes
benjackwhite Feb 8, 2024
90e3ba4
Fix up permission checking
benjackwhite Feb 8, 2024
7a0b583
Fix accessor
benjackwhite Feb 9, 2024
7c199ab
Merge branch 'feat/simplify-permissions' into personal-api-key-scopes
benjackwhite Feb 9, 2024
a3600d5
Update query snapshots
github-actions[bot] Feb 9, 2024
84f29dc
Added base scopes everywhere
benjackwhite Feb 9, 2024
d3328d0
Sync scopes
benjackwhite Feb 9, 2024
f86e808
Remove prompts
benjackwhite Feb 9, 2024
408bbbe
Remove todos
benjackwhite Feb 9, 2024
9b17a10
Fix up all access and swap to segmented button
benjackwhite Feb 9, 2024
86d6f2f
Added todo
benjackwhite Feb 9, 2024
7a785c5
fixes
benjackwhite Feb 9, 2024
8e632cf
Update query snapshots
github-actions[bot] Feb 9, 2024
76dda2d
Update query snapshots
github-actions[bot] Feb 9, 2024
7e16abd
Fixed up docs
benjackwhite Feb 9, 2024
378ecc2
Fixes to docs
benjackwhite Feb 9, 2024
cb20b6c
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 9, 2024
f0822ca
Fixes
benjackwhite Feb 9, 2024
3e5a726
Update query snapshots
github-actions[bot] Feb 9, 2024
8b2b4a8
Fixed post creation display
benjackwhite Feb 9, 2024
9420bb9
Merge branch 'personal-api-key-scopes' of github.com:PostHog/posthog …
benjackwhite Feb 9, 2024
60b097b
Fix
benjackwhite Feb 9, 2024
171e597
Update query snapshots
github-actions[bot] Feb 9, 2024
69813ac
Fix up query permissions
benjackwhite Feb 9, 2024
c32f92e
Type fixes
benjackwhite Feb 9, 2024
540b8ee
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 9, 2024
b39c781
Fix
benjackwhite Feb 9, 2024
97791f4
Fix linting
benjackwhite Feb 9, 2024
25fd011
Fixes
benjackwhite Feb 9, 2024
1d1e544
Fix
benjackwhite Feb 9, 2024
5ab438b
Fixes
benjackwhite Feb 9, 2024
96da14f
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 9, 2024
47bb44f
Update query snapshots
github-actions[bot] Feb 9, 2024
483749f
Fixes
benjackwhite Feb 9, 2024
34d73c2
Revert
benjackwhite Feb 9, 2024
990c6fc
Fix
benjackwhite Feb 9, 2024
5b6cdc4
Update query snapshots
github-actions[bot] Feb 9, 2024
ee8d2b4
More fixes
benjackwhite Feb 9, 2024
daccd32
Merge branch 'personal-api-key-scopes' of github.com:PostHog/posthog …
benjackwhite Feb 9, 2024
dd100b3
Merge branch 'feat/simplify-permissions' into personal-api-key-scopes
benjackwhite Feb 9, 2024
cb5eecc
Added a command back
benjackwhite Feb 9, 2024
7946f9f
Added stuff
benjackwhite Feb 9, 2024
edbb939
Update query snapshots
github-actions[bot] Feb 9, 2024
93b1507
Fixes
benjackwhite Feb 9, 2024
bdeb65a
Fix baseline
benjackwhite Feb 9, 2024
92acd9c
Update UI snapshots for `chromium` (2)
github-actions[bot] Feb 9, 2024
b01010c
Update UI snapshots for `chromium` (2)
github-actions[bot] Feb 9, 2024
b67c67c
Merge branch 'master' into feat/simplify-permissions
benjackwhite Feb 12, 2024
f59806a
Merge branch 'feat/simplify-permissions' into personal-api-key-scopes
benjackwhite Feb 12, 2024
65d1af4
Update query snapshots
github-actions[bot] Feb 12, 2024
b63f36f
Fixes
benjackwhite Feb 12, 2024
c1fbaf8
Removed a bunch of docs related things
benjackwhite Feb 12, 2024
9614945
Remove not supported endpoints from docs
benjackwhite Feb 12, 2024
af52287
Swap out include in docs for scopes
benjackwhite Feb 12, 2024
0c4d1cd
Fix
benjackwhite Feb 12, 2024
201f177
Started adding other tests
benjackwhite Feb 12, 2024
bd81afb
Fixed up org based access
benjackwhite Feb 12, 2024
d0aed90
Fixes
benjackwhite Feb 12, 2024
9dd30c1
Fixes
benjackwhite Feb 12, 2024
774a59b
Removed todo
benjackwhite Feb 12, 2024
eca8d39
Remove old code
benjackwhite Feb 12, 2024
3fd6c7d
Fixes scopes
benjackwhite Feb 12, 2024
cbec311
Fixes
benjackwhite Feb 12, 2024
8763171
Fix
benjackwhite Feb 12, 2024
8cab0fd
Fix
benjackwhite Feb 12, 2024
9217743
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 12, 2024
d08f84c
fix
benjackwhite Feb 12, 2024
9453656
Update query snapshots
github-actions[bot] Feb 12, 2024
8daa155
Update query snapshots
github-actions[bot] Feb 12, 2024
1857920
Fixed bad merge
benjackwhite Feb 12, 2024
1d59c25
Fix up types
benjackwhite Feb 12, 2024
b4bedad
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 12, 2024
198b839
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 12, 2024
903f824
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 13, 2024
e87d230
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 13, 2024
fbf79c8
Merge
benjackwhite Feb 13, 2024
c0d2b0c
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 13, 2024
0c731b8
Update query snapshots
github-actions[bot] Feb 13, 2024
0f6d504
Fixes
benjackwhite Feb 13, 2024
0b410d7
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 13, 2024
1d35454
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 13, 2024
bb21011
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 13, 2024
b94be8f
feat: API key team and org scoping (#20293)
benjackwhite Feb 14, 2024
5755961
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 14, 2024
b65d191
Update query snapshots
github-actions[bot] Feb 14, 2024
eee86a9
Squash migrations
benjackwhite Feb 14, 2024
d0b92e1
Merge branch 'master' into personal-api-key-scopes
Twixes Feb 14, 2024
cb14499
Fix 0389_personalapikey_scopes.py formatting
Twixes Feb 14, 2024
4a91610
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 14, 2024
cd35d06
Fixes
benjackwhite Feb 14, 2024
3b7eaa9
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 14, 2024
c5c8974
PR review changes
benjackwhite Feb 14, 2024
9e7d078
Fix
benjackwhite Feb 14, 2024
89990d3
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 14, 2024
363e095
Update query snapshots
github-actions[bot] Feb 14, 2024
cc0f068
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 14, 2024
3250975
Update query snapshots
github-actions[bot] Feb 14, 2024
2db7b8e
Update query snapshots
github-actions[bot] Feb 14, 2024
cd4b132
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 14, 2024
509af94
Fix
benjackwhite Feb 14, 2024
cbe1676
Fixed up all round
benjackwhite Feb 14, 2024
fc52402
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 14, 2024
654e6e0
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 14, 2024
0f76bcc
Fix
benjackwhite Feb 14, 2024
9cfce3c
Fixes
benjackwhite Feb 15, 2024
d040c10
Fixes
benjackwhite Feb 15, 2024
f51a748
Fixes
benjackwhite Feb 15, 2024
47f0aea
Update query snapshots
github-actions[bot] Feb 15, 2024
9dca302
More styling
benjackwhite Feb 15, 2024
64b4c36
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 15, 2024
a2fe8c2
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 15, 2024
372dc1f
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 15, 2024
8edee6b
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 15, 2024
28e3928
Tweak copy and make access mode choice mandatory
Twixes Feb 15, 2024
4417ad3
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 15, 2024
f2c1ed7
Fixes
benjackwhite Feb 16, 2024
9d4e928
Remove default API key authentication
benjackwhite Feb 16, 2024
ed7aacc
Fix user endpoint
benjackwhite Feb 16, 2024
6e48fd2
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 16, 2024
8be193f
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
ed6af66
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 16, 2024
0031846
Update UI snapshots for `chromium` (2)
github-actions[bot] Feb 16, 2024
9053dbc
Added scope for webhooks
benjackwhite Feb 16, 2024
b63b255
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
5d2d1c5
Automatically set zapier preset
benjackwhite Feb 16, 2024
b9b13be
Fix up permissions
benjackwhite Feb 16, 2024
2082f40
Fix scopes
benjackwhite Feb 16, 2024
b42f0f8
Update UI snapshots for `chromium` (2)
github-actions[bot] Feb 16, 2024
81d5796
Fixed up scopes for query access
benjackwhite Feb 16, 2024
1f94bf9
Fixes
benjackwhite Feb 16, 2024
f9eb17f
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
5c93462
Add `test_cannot_edit_self`
Twixes Feb 16, 2024
c16dca4
Make warnings a bit nicer
Twixes Feb 16, 2024
0ec64fe
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
c249170
Add some type annotations
Twixes Feb 16, 2024
2d8c792
Update test_authentication.py
Twixes Feb 16, 2024
bed30b7
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
20e495a
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
1b3cbff
Remove `using_personal_api_key`
Twixes Feb 16, 2024
06a3107
Update test_user.py
Twixes Feb 16, 2024
1e83cf0
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
6104e74
Fix session auth
benjackwhite Feb 16, 2024
0fb1bb4
Fix code
benjackwhite Feb 16, 2024
0a49e0a
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
d6d5af2
Update UI snapshots for `chromium` (2)
github-actions[bot] Feb 16, 2024
abf7d85
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
f2463ab
Fixes
benjackwhite Feb 16, 2024
73a5960
Update query snapshots
github-actions[bot] Feb 16, 2024
5940c8d
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
a6a0cd7
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 16, 2024
42b0243
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
eb12f9f
Update UI snapshots for `chromium` (1)
github-actions[bot] Feb 16, 2024
3aa6832
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
30ed217
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
8ef2f86
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 16, 2024
9e77030
Merge branch 'master' into personal-api-key-scopes
benjackwhite Feb 20, 2024
0bfe9e7
Update query snapshots
github-actions[bot] Feb 20, 2024
6438db7
Update query snapshots
github-actions[bot] Feb 20, 2024
d6bb306
Update UI snapshots for `webkit` (2)
github-actions[bot] Feb 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"SKIP_SERVICE_VERSION_REQUIREMENTS": "1",
"PRINT_SQL": "1",
"REPLAY_EVENTS_NEW_CONSUMER_RATIO": "1.0",
"AUTO_LOGIN": "True",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a solution from Bianca that we agreed to revert. Did it here as I needed to test the logged out situation a lot

"BILLING_SERVICE_URL": "https://billing.dev.posthog.dev"
},
"console": "integratedTerminal",
Expand Down
2 changes: 2 additions & 0 deletions ee/api/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class BillingViewset(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
serializer_class = BillingSerializer
derive_current_team_from_user_only = True

scope_object = "INTERNAL"

def list(self, request: Request, *args: Any, **kwargs: Any) -> Response:
license = get_cached_instance_license()
if license and not license.is_v2_license:
Expand Down
2 changes: 1 addition & 1 deletion ee/api/dashboard_collaborator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ class DashboardCollaboratorViewSet(
mixins.DestroyModelMixin,
viewsets.GenericViewSet,
):
scope_object = "INTERNAL"
permission_classes = [CanEditDashboardCollaborator]
pagination_class = None
queryset = DashboardPrivilege.objects.select_related("dashboard").filter(user__is_active=True)
lookup_field = "user__uuid"
serializer_class = DashboardCollaboratorSerializer
filter_rewrite_rules = {"team_id": "dashboard__team_id"}
include_in_docs = False

def get_serializer_context(self) -> Dict[str, Any]:
context = super().get_serializer_context()
Expand Down
2 changes: 1 addition & 1 deletion ee/api/explicit_team_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ def validate(self, attrs):


class ExplicitTeamMemberViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
scope_object = "project"
pagination_class = None
queryset = ExplicitTeamMembership.objects.filter(parent_membership__user__is_active=True).select_related(
"team", "parent_membership", "parent_membership__user"
)
lookup_field = "parent_membership__user__uuid"
ordering = ["level", "-joined_at"]
serializer_class = ExplicitTeamMemberSerializer
include_in_docs = True

permission_classes = [IsAuthenticated, TeamMemberStrictManagementPermission]

Expand Down
1 change: 1 addition & 0 deletions ee/api/feature_flag_role_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class FeatureFlagRoleAccessViewSet(
mixins.RetrieveModelMixin,
viewsets.GenericViewSet,
):
scope_object = "feature_flag"
permission_classes = [FeatureFlagRoleAccessPermissions]
serializer_class = FeatureFlagRoleAccessSerializer
queryset = FeatureFlagRoleAccess.objects.select_related("feature_flag")
Expand Down
4 changes: 4 additions & 0 deletions ee/api/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class HookViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
Retrieve, create, update or destroy REST hooks.
"""

scope_object = "webhook"
# NOTE: This permissions is needed for Zapier calls but we don't want to expose it in the API docs until
# it is able to support more than Zapier
hide_api_docs = True
queryset = Hook.objects.all()
ordering = "-created_at"
serializer_class = HookSerializer
Expand Down
1 change: 1 addition & 0 deletions ee/api/organization_resource_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class OrganizationResourceAccessViewSet(
mixins.DestroyModelMixin,
viewsets.GenericViewSet,
):
scope_object = "INTERNAL"
permission_classes = [RolePermissions]
serializer_class = OrganizationResourceAccessSerializer
queryset = OrganizationResourceAccess.objects.all()
2 changes: 2 additions & 0 deletions ee/api/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class RoleViewSet(
mixins.DestroyModelMixin,
viewsets.GenericViewSet,
):
scope_object = "organization"
permission_classes = [RolePermissions]
serializer_class = RoleSerializer
queryset = Role.objects.all()
Expand Down Expand Up @@ -133,6 +134,7 @@ class RoleMembershipViewSet(
mixins.DestroyModelMixin,
viewsets.GenericViewSet,
):
scope_object = "organization"
permission_classes = [RolePermissions]
serializer_class = RoleMembershipSerializer
queryset = RoleMembership.objects.select_related("role")
Expand Down
1 change: 1 addition & 0 deletions ee/api/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def update(self, instance: Subscription, validated_data: dict, *args: Any, **kwa


class SubscriptionViewSet(TeamAndOrgViewSetMixin, ForbidDestroyModel, viewsets.ModelViewSet):
scope_object = "subscription"
queryset = Subscription.objects.all()
serializer_class = SubscriptionSerializer
permission_classes = [PremiumFeaturePermission]
Expand Down
8 changes: 4 additions & 4 deletions ee/api/test/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_can_get_saml_metadata(self):

def test_need_to_be_authenticated_to_get_saml_metadata(self):
response = self.client.get("/api/saml/metadata/")
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(response.json(), self.unauthenticated_response())

def test_only_admins_can_get_saml_metadata(self):
Expand Down Expand Up @@ -498,7 +498,7 @@ def test_cannot_login_with_improperly_signed_payload(self):

# Test logged in request fails
response = self.client.get("/api/users/@me/")
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

@freeze_time("2021-08-25T22:09:14.252Z")
def test_cannot_signup_with_saml_if_jit_provisioning_is_disabled(self):
Expand Down Expand Up @@ -539,7 +539,7 @@ def test_cannot_signup_with_saml_if_jit_provisioning_is_disabled(self):

# Test logged in request fails
response = self.client.get("/api/users/@me/")
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

@freeze_time("2021-08-25T23:53:51.000Z")
def test_cannot_create_account_without_first_name_in_payload(self):
Expand Down Expand Up @@ -617,7 +617,7 @@ def test_cannot_login_with_saml_on_unverified_domain(self):

# Assert user is not logged in
response = self.client.get("/api/users/@me/")
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

def test_saml_can_be_enforced(self):
User.objects.create_and_join(
Expand Down
34 changes: 30 additions & 4 deletions ee/api/test/test_team.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from rest_framework.status import (
HTTP_200_OK,
HTTP_204_NO_CONTENT,
HTTP_400_BAD_REQUEST,
HTTP_403_FORBIDDEN,
HTTP_404_NOT_FOUND,
)
Expand Down Expand Up @@ -98,17 +97,44 @@ def test_user_that_does_not_belong_to_an_org_cannot_create_a_project(self):
self.client.force_login(user)

response = self.client.post("/api/projects/", {"name": "Test"})
self.assertEqual(response.status_code, HTTP_400_BAD_REQUEST, response.content)
self.assertEqual(response.status_code, HTTP_404_NOT_FOUND, response.content)
self.assertEqual(
response.json(),
{
"type": "validation_error",
"code": "invalid_input",
"type": "invalid_request",
"code": "not_found",
"detail": "You need to belong to an organization.",
"attr": None,
},
)

def test_user_create_project_for_org_via_url(self):
# Set both current and new org to high enough membership level
self.organization_membership.level = OrganizationMembership.Level.ADMIN
self.organization_membership.save()

current_org, _, _ = Organization.objects.bootstrap(self.user, name="other_org")
other_org = self.organization # Bootstrapping above sets it to the current org

assert current_org.id == self.user.current_organization_id
response = self.client.post(f"/api/organizations/{current_org.id}/projects/", {"name": "Via current org"})
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a test for the POST /api/projects/ case too?

self.assertEqual(response.status_code, 201)
assert response.json()["organization"] == str(current_org.id)

assert other_org.id != self.user.current_organization_id
response = self.client.post(f"/api/organizations/{other_org.id}/projects/", {"name": "Via path org"})
self.assertEqual(response.status_code, 201, msg=response.json())
assert response.json()["organization"] == str(other_org.id)

def test_user_cannot_create_project_in_org_without_access(self):
_, _, _ = Organization.objects.bootstrap(self.user, name="other_org")
other_org = self.organization # Bootstrapping above sets it to the current org

assert other_org.id != self.user.current_organization_id
response = self.client.post(f"/api/organizations/{other_org.id}/projects/", {"name": "Via path org"})
self.assertEqual(response.status_code, 403, msg=response.json())
assert response.json() == self.permission_denied_response("Your organization access level is insufficient.")

# Deleting projects

def test_delete_team_as_org_admin_allowed(self):
Expand Down
1 change: 1 addition & 0 deletions ee/clickhouse/views/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def update(self, instance: Experiment, validated_data: dict, *args: Any, **kwarg


class ClickhouseExperimentsViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
scope_object = "experiment"
serializer_class = ExperimentSerializer
queryset = Experiment.objects.all()
permission_classes = [PremiumFeaturePermission]
Expand Down
2 changes: 2 additions & 0 deletions ee/clickhouse/views/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Meta:


class ClickhouseGroupsTypesView(TeamAndOrgViewSetMixin, mixins.ListModelMixin, viewsets.GenericViewSet):
scope_object = "group"
serializer_class = GroupTypeSerializer
queryset = GroupTypeMapping.objects.all().order_by("group_type_index")
pagination_class = None
Expand Down Expand Up @@ -54,6 +55,7 @@ class Meta:


class ClickhouseGroupsView(TeamAndOrgViewSetMixin, mixins.ListModelMixin, viewsets.GenericViewSet):
scope_object = "group"
serializer_class = GroupSerializer
queryset = Group.objects.all()
pagination_class = GroupCursorPagination
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# serializer version: 1
# name: ClickhouseTestExperimentSecondaryResults.test_basic_secondary_metric_results
'''
/* user_id:124 celery:posthog.tasks.tasks.sync_insight_caching_state */
/* user_id:123 celery:posthog.tasks.tasks.sync_insight_caching_state */
SELECT team_id,
date_diff('second', max(timestamp), now()) AS age
FROM events
Expand Down
2 changes: 1 addition & 1 deletion ee/session_recordings/session_recording_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ def _check_can_create_playlist(self, team: Team) -> bool:


class SessionRecordingPlaylistViewSet(TeamAndOrgViewSetMixin, ForbidDestroyModel, viewsets.ModelViewSet):
scope_object = "session_recording_playlist"
queryset = SessionRecordingPlaylist.objects.all()
serializer_class = SessionRecordingPlaylistSerializer
throttle_classes = [ClickHouseBurstRateThrottle, ClickHouseSustainedRateThrottle]
filter_backends = [DjangoFilterBackend]
filterset_fields = ["short_id", "created_by"]
include_in_docs = True
lookup_field = "short_id"

def get_queryset(self) -> QuerySet:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-notebooks--headings--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Member

Choose a reason for hiding this comment

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

This seems off but I don't know why it'd occur on this branch 🤔

25 changes: 25 additions & 0 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
OrganizationFeatureFlagsCopyBody,
OrganizationResourcePermissionType,
OrganizationType,
PersonalAPIKeyType,
PersonListParams,
PersonType,
PluginConfigTypeNew,
Expand Down Expand Up @@ -717,6 +718,15 @@ class ApiRequest {
return this.projectsDetail(teamId).addPathComponent('activity_log')
}

// Personal API keys
public personalApiKeys(): ApiRequest {
return this.addPathComponent('personal_api_keys')
}

public personalApiKey(id: PersonalAPIKeyType['id']): ApiRequest {
return this.personalApiKeys().addPathComponent(id)
}

// Request finalization
public async get(options?: ApiMethodOptions): Promise<any> {
return await api.get(this.assembleFullUrl(), options)
Expand Down Expand Up @@ -1966,6 +1976,21 @@ const api = {
},
},

personalApiKeys: {
async list(): Promise<PersonalAPIKeyType[]> {
return await new ApiRequest().personalApiKeys().get()
},
async create(data: Partial<PersonalAPIKeyType>): Promise<PersonalAPIKeyType> {
return await new ApiRequest().personalApiKeys().create({ data })
},
async update(id: PersonalAPIKeyType['id'], data: Partial<PersonalAPIKeyType>): Promise<PersonalAPIKeyType> {
benjackwhite marked this conversation as resolved.
Show resolved Hide resolved
return await new ApiRequest().personalApiKey(id).update({ data })
},
async delete(id: PersonalAPIKeyType['id']): Promise<void> {
await new ApiRequest().personalApiKey(id).delete()
},
},

queryURL: (): string => {
return new ApiRequest().query().assembleFullUrl(true)
},
Expand Down
38 changes: 7 additions & 31 deletions frontend/src/lib/components/CommandPalette/commandPaletteLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import { sidePanelLogic } from '~/layout/navigation-3000/sidepanel/sidePanelLogi
import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
import { InsightType } from '~/types'

import { personalAPIKeysLogic } from '../../../scenes/settings/user/personalAPIKeysLogic'
import { commandBarLogic } from '../CommandBar/commandBarLogic'
import { BarStatus } from '../CommandBar/types'
import { hedgehogBuddyLogic } from '../HedgehogBuddy/hedgehogBuddyLogic'
Expand Down Expand Up @@ -139,8 +138,6 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>([
path(['lib', 'components', 'CommandPalette', 'commandPaletteLogic']),
connect({
actions: [
personalAPIKeysLogic,
['createKey'],
router,
['push'],
userLogic,
Expand Down Expand Up @@ -662,6 +659,13 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>([
userLogic.actions.logout()
},
},
{
icon: IconUnlock,
display: 'Go to Personal API Keys',
executor: () => {
push(urls.settings('user-api-keys'))
},
},
],
}

Expand Down Expand Up @@ -757,33 +761,6 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>([
},
}

const createPersonalApiKey: Command = {
key: 'create-personal-api-key',
scope: GLOBAL_COMMAND_SCOPE,
resolver: {
icon: IconUnlock,
display: 'Create Personal API Key',
executor: () => ({
instruction: 'Give your key a label',
icon: IconKeyboard,
scope: 'Creating Personal API Key',
resolver: (argument) => {
if (argument?.length) {
return {
icon: IconUnlock,
display: `Create Key "${argument}"`,
executor: () => {
personalAPIKeysLogic.actions.createKey(argument)
push(urls.settings('user'), {}, 'personal-api-keys')
},
}
}
return null
},
}),
},
}

const createDashboard: Command = {
key: 'create-dashboard',
scope: GLOBAL_COMMAND_SCOPE,
Expand Down Expand Up @@ -961,7 +938,6 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>([
actions.registerCommand(openUrls)
actions.registerCommand(debugClickhouseQueries)
actions.registerCommand(calculator)
actions.registerCommand(createPersonalApiKey)
actions.registerCommand(createDashboard)
actions.registerCommand(shareFeedback)
actions.registerCommand(debugCopySessionRecordingURL)
Expand Down
Loading
Loading