0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 09:14:46 +01:00
posthog/ee/api/test/test_feature_flag.py
Zach Waterfield 8d01d5ef54
feat: rbac initial set up (#25745)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
2024-10-29 17:17:27 -04:00

26 lines
1.3 KiB
Python

from ee.api.test.base import APILicensedTest
from ee.models.rbac.organization_resource_access import OrganizationResourceAccess
from ee.models.rbac.role import Role, RoleMembership
from posthog.models.feature_flag import FeatureFlag
from posthog.models.organization import OrganizationMembership
class TestFeatureFlagEnterpriseAPI(APILicensedTest):
def test_adding_role_edit_access_is_not_restrictive(self):
FeatureFlag.objects.create(created_by=self.user, key="flag_a", name="Flag A", team=self.team)
self.assertEqual(self.organization_membership.level, OrganizationMembership.Level.MEMBER)
OrganizationResourceAccess.objects.create(
resource=OrganizationResourceAccess.Resources.FEATURE_FLAGS,
access_level=OrganizationResourceAccess.AccessLevel.CAN_ALWAYS_EDIT,
organization=self.organization,
)
role = Role.objects.create(
name="Marketing",
organization=self.organization,
feature_flags_access_level=OrganizationResourceAccess.AccessLevel.CAN_ONLY_VIEW,
)
RoleMembership.objects.create(role=role, user=self.user)
flag_res = self.client.get(f"/api/projects/{self.team.id}/feature_flags/")
self.assertEqual(flag_res.json()["count"], 1)
self.assertEqual(flag_res.json()["results"][0]["can_edit"], True)