-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bad7548
commit dbe6f63
Showing
5 changed files
with
177 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from rest_framework import status | ||
|
||
from ee.api.test.base import APILicensedTest | ||
from posthog.constants import AvailableFeature | ||
from posthog.models.organization import OrganizationMembership | ||
|
||
|
||
class TestAccessControlAPI(APILicensedTest): | ||
# def _create_access_control( | ||
# self, resource="project", resource_id=None, access_level="admin", organization_member=None, team=None, role=None | ||
# ): | ||
# return AccessControl.objects.create( | ||
# organization=self.organization, | ||
# resource=resource, | ||
# resource_id=resource_id or self.team.id, | ||
# access_level=access_level, | ||
# # Targets | ||
# organization_member=organization_member, | ||
# team=team, | ||
# role=role, | ||
# ) | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.organization.available_features = [ | ||
AvailableFeature.PROJECT_BASED_PERMISSIONING, | ||
AvailableFeature.ROLE_BASED_ACCESS, | ||
] | ||
self.organization.save() | ||
|
||
def _put_access_control(self, data): | ||
payload = { | ||
"resource": "project", | ||
"resource_id": self.team.id, | ||
"access_level": "admin", | ||
} | ||
|
||
payload.update(data) | ||
return self.client.put( | ||
"/api/organizations/@current/access_controls", | ||
payload, | ||
) | ||
|
||
def _org_membership(self, level: OrganizationMembership.Level = OrganizationMembership.Level.ADMIN): | ||
self.organization_membership.level = level | ||
self.organization_membership.save() | ||
|
||
def test_project_change_rejected_if_not_org_admin(self): | ||
self._org_membership(OrganizationMembership.Level.MEMBER) | ||
res = self._put_access_control({"team": self.team.id}) | ||
assert res.status_code == status.HTTP_403_FORBIDDEN, res.json() | ||
|
||
def test_project_change_accepted_if_org_admin(self): | ||
self._org_membership(OrganizationMembership.Level.ADMIN) | ||
res = self._put_access_control({"team": self.team.id}) | ||
assert res.status_code == status.HTTP_200_OK, res.json() | ||
|
||
def test_project_change_if_in_access_control(self): | ||
self._org_membership(OrganizationMembership.Level.ADMIN) | ||
# Add ourselves to access | ||
res = self._put_access_control({"team": self.team.id}) | ||
assert res.status_code == status.HTTP_200_OK, res.json() | ||
|
||
# TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
ee/rbac/test/test_user_access_control.py → ...hog/rbac/test/test_user_access_control.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters