0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 09:16:49 +01:00
posthog/ee/api/test/test_dashboard.py

50 lines
2.3 KiB
Python
Raw Normal View History

Project-based permissioning `TopNavigation` (#6027) * Refactor `AvailableFeature` from strings to an enum everywhere * Fix circular dependency and type * Add "Per-project access" feature flag, premium feature, and organization switch * Rename `OrganizationMembershipLevel` to `OrganizationAccessLevel` * Create `ExplicitTeamMembership` model * Show whether projects are restricted in the project switcher * Update organizations API code * Fix migrations * Move organization tests that require EE to `ee` * Revert `OrganizationMembershipLevel` rename * Fix organization tests * Update migration * Fix schema and add Members to Project Settings * Build out test memberships API with security tests * Update `TeamMembers` and `teamMembersLogic` * Move "Per-project access" description to tooltip * Add moar tests * Fix Project Members list logic * Add additional membership checks * Update migrations * Fix typing * Adjust explicit team memberships API similarly * Fix typo * Unify `ExplicitTeamMemberSerializer` * Remove old changes to `membersLogic` usage * Use `effective_membership_level` on `TeamBasicSerializer` * Clean up organization update tests * Explicitly disallow enabling per-project access for free * Fix circular import * Remove `id` from `UserSerializer` * Fix typing * Try to fix import * Fix fatal typing * Add more tests * Update permissioning.ts * Add clarifying comment to migration * Fix import * Revert `TopNavigation` changes * Restore `TopNavigation` changes This reverts commit 05fd9e4ed665c51ab6d4e45443570694f56b3324. * Try to add a story for `TopNavigation` * minor clarifications * Revert `TopNavigation` changes * Restore `TopNavigation` changes * Make new access control entirely project-based * Update migrations * Add `project_based_permissioning` to `TeamBasicSerializer` * Update test_team.py * Fix `isRestricted` in `ProjectRow` * Disable project creation for non-admins * Make project icon in top nav itself dynamic as well * Fix story * Delete 0169_project_based_permissioning.py * Apply suggestions from code review Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Update frontend/src/layout/navigation/TopNavigation.tsx Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Address feedback * Project-based permissioning full data access restrictions (#6068) * Fix Access Control restriction tooltip * Add `TeamMemberAccessPermission` and use it in viewsets * Add `ErrorProjectUnavailable` scene * Ignore mypy * Update MainNavigation.tsx * Update explicit_team_member.py * Fix frontend detection of unavailable project * Fix some tests and edge cases * Fix basic permissions * Add more tests * Simplify `ExplicitTeamMemberViewSet` permissions * Improve restrictions and add moar tests * Update frontend * Fix a couple of things * Fix import * Fix some edge cases * Fix typing errors * Use hedgehog instead of moth Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Address feedback * Add proper permissioning to dashboard views * Update ee/api/test/test_dashboard.py Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Run prettier * Remove debug code Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2021-09-30 00:43:40 +02:00
from rest_framework import status
from ee.api.test.base import APILicensedTest
from ee.models.explicit_team_membership import ExplicitTeamMembership
from posthog.models import OrganizationMembership
from posthog.models.dashboard import Dashboard
class TestDashboardEnterpriseAPI(APILicensedTest):
def setUp(self):
super().setUp()
self.team.access_control = True
self.team.save()
def test_retrieve_dashboard_forbidden_for_project_outsider(self):
self.organization_membership.level = OrganizationMembership.Level.MEMBER
self.organization_membership.save()
dashboard = Dashboard.objects.create(
team=self.team, name="private dashboard", created_by=self.user, tags=["deprecated"]
)
response = self.client.get(f"/api/projects/{self.team.id}/dashboards/{dashboard.id}")
Project-based permissioning `TopNavigation` (#6027) * Refactor `AvailableFeature` from strings to an enum everywhere * Fix circular dependency and type * Add "Per-project access" feature flag, premium feature, and organization switch * Rename `OrganizationMembershipLevel` to `OrganizationAccessLevel` * Create `ExplicitTeamMembership` model * Show whether projects are restricted in the project switcher * Update organizations API code * Fix migrations * Move organization tests that require EE to `ee` * Revert `OrganizationMembershipLevel` rename * Fix organization tests * Update migration * Fix schema and add Members to Project Settings * Build out test memberships API with security tests * Update `TeamMembers` and `teamMembersLogic` * Move "Per-project access" description to tooltip * Add moar tests * Fix Project Members list logic * Add additional membership checks * Update migrations * Fix typing * Adjust explicit team memberships API similarly * Fix typo * Unify `ExplicitTeamMemberSerializer` * Remove old changes to `membersLogic` usage * Use `effective_membership_level` on `TeamBasicSerializer` * Clean up organization update tests * Explicitly disallow enabling per-project access for free * Fix circular import * Remove `id` from `UserSerializer` * Fix typing * Try to fix import * Fix fatal typing * Add more tests * Update permissioning.ts * Add clarifying comment to migration * Fix import * Revert `TopNavigation` changes * Restore `TopNavigation` changes This reverts commit 05fd9e4ed665c51ab6d4e45443570694f56b3324. * Try to add a story for `TopNavigation` * minor clarifications * Revert `TopNavigation` changes * Restore `TopNavigation` changes * Make new access control entirely project-based * Update migrations * Add `project_based_permissioning` to `TeamBasicSerializer` * Update test_team.py * Fix `isRestricted` in `ProjectRow` * Disable project creation for non-admins * Make project icon in top nav itself dynamic as well * Fix story * Delete 0169_project_based_permissioning.py * Apply suggestions from code review Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Update frontend/src/layout/navigation/TopNavigation.tsx Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Address feedback * Project-based permissioning full data access restrictions (#6068) * Fix Access Control restriction tooltip * Add `TeamMemberAccessPermission` and use it in viewsets * Add `ErrorProjectUnavailable` scene * Ignore mypy * Update MainNavigation.tsx * Update explicit_team_member.py * Fix frontend detection of unavailable project * Fix some tests and edge cases * Fix basic permissions * Add more tests * Simplify `ExplicitTeamMemberViewSet` permissions * Improve restrictions and add moar tests * Update frontend * Fix a couple of things * Fix import * Fix some edge cases * Fix typing errors * Use hedgehog instead of moth Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Address feedback * Add proper permissioning to dashboard views * Update ee/api/test/test_dashboard.py Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Run prettier * Remove debug code Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2021-09-30 00:43:40 +02:00
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_retrieve_dashboard_forbidden_for_org_admin(self):
self.organization_membership.level = OrganizationMembership.Level.ADMIN
self.organization_membership.save()
dashboard = Dashboard.objects.create(
team=self.team, name="private dashboard", created_by=self.user, tags=["deprecated"]
)
response = self.client.get(f"/api/projects/{self.team.id}/dashboards/{dashboard.id}")
Project-based permissioning `TopNavigation` (#6027) * Refactor `AvailableFeature` from strings to an enum everywhere * Fix circular dependency and type * Add "Per-project access" feature flag, premium feature, and organization switch * Rename `OrganizationMembershipLevel` to `OrganizationAccessLevel` * Create `ExplicitTeamMembership` model * Show whether projects are restricted in the project switcher * Update organizations API code * Fix migrations * Move organization tests that require EE to `ee` * Revert `OrganizationMembershipLevel` rename * Fix organization tests * Update migration * Fix schema and add Members to Project Settings * Build out test memberships API with security tests * Update `TeamMembers` and `teamMembersLogic` * Move "Per-project access" description to tooltip * Add moar tests * Fix Project Members list logic * Add additional membership checks * Update migrations * Fix typing * Adjust explicit team memberships API similarly * Fix typo * Unify `ExplicitTeamMemberSerializer` * Remove old changes to `membersLogic` usage * Use `effective_membership_level` on `TeamBasicSerializer` * Clean up organization update tests * Explicitly disallow enabling per-project access for free * Fix circular import * Remove `id` from `UserSerializer` * Fix typing * Try to fix import * Fix fatal typing * Add more tests * Update permissioning.ts * Add clarifying comment to migration * Fix import * Revert `TopNavigation` changes * Restore `TopNavigation` changes This reverts commit 05fd9e4ed665c51ab6d4e45443570694f56b3324. * Try to add a story for `TopNavigation` * minor clarifications * Revert `TopNavigation` changes * Restore `TopNavigation` changes * Make new access control entirely project-based * Update migrations * Add `project_based_permissioning` to `TeamBasicSerializer` * Update test_team.py * Fix `isRestricted` in `ProjectRow` * Disable project creation for non-admins * Make project icon in top nav itself dynamic as well * Fix story * Delete 0169_project_based_permissioning.py * Apply suggestions from code review Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Update frontend/src/layout/navigation/TopNavigation.tsx Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Address feedback * Project-based permissioning full data access restrictions (#6068) * Fix Access Control restriction tooltip * Add `TeamMemberAccessPermission` and use it in viewsets * Add `ErrorProjectUnavailable` scene * Ignore mypy * Update MainNavigation.tsx * Update explicit_team_member.py * Fix frontend detection of unavailable project * Fix some tests and edge cases * Fix basic permissions * Add more tests * Simplify `ExplicitTeamMemberViewSet` permissions * Improve restrictions and add moar tests * Update frontend * Fix a couple of things * Fix import * Fix some edge cases * Fix typing errors * Use hedgehog instead of moth Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Address feedback * Add proper permissioning to dashboard views * Update ee/api/test/test_dashboard.py Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Run prettier * Remove debug code Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2021-09-30 00:43:40 +02:00
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_retrieve_dashboard_allowed_for_project_member(self):
self.organization_membership.level = OrganizationMembership.Level.MEMBER
self.organization_membership.save()
ExplicitTeamMembership.objects.create(team=self.team, parent_membership=self.organization_membership)
dashboard = Dashboard.objects.create(
team=self.team, name="private dashboard", created_by=self.user, tags=["deprecated"]
)
response = self.client.get(f"/api/projects/{self.team.id}/dashboards/{dashboard.id}")
Project-based permissioning `TopNavigation` (#6027) * Refactor `AvailableFeature` from strings to an enum everywhere * Fix circular dependency and type * Add "Per-project access" feature flag, premium feature, and organization switch * Rename `OrganizationMembershipLevel` to `OrganizationAccessLevel` * Create `ExplicitTeamMembership` model * Show whether projects are restricted in the project switcher * Update organizations API code * Fix migrations * Move organization tests that require EE to `ee` * Revert `OrganizationMembershipLevel` rename * Fix organization tests * Update migration * Fix schema and add Members to Project Settings * Build out test memberships API with security tests * Update `TeamMembers` and `teamMembersLogic` * Move "Per-project access" description to tooltip * Add moar tests * Fix Project Members list logic * Add additional membership checks * Update migrations * Fix typing * Adjust explicit team memberships API similarly * Fix typo * Unify `ExplicitTeamMemberSerializer` * Remove old changes to `membersLogic` usage * Use `effective_membership_level` on `TeamBasicSerializer` * Clean up organization update tests * Explicitly disallow enabling per-project access for free * Fix circular import * Remove `id` from `UserSerializer` * Fix typing * Try to fix import * Fix fatal typing * Add more tests * Update permissioning.ts * Add clarifying comment to migration * Fix import * Revert `TopNavigation` changes * Restore `TopNavigation` changes This reverts commit 05fd9e4ed665c51ab6d4e45443570694f56b3324. * Try to add a story for `TopNavigation` * minor clarifications * Revert `TopNavigation` changes * Restore `TopNavigation` changes * Make new access control entirely project-based * Update migrations * Add `project_based_permissioning` to `TeamBasicSerializer` * Update test_team.py * Fix `isRestricted` in `ProjectRow` * Disable project creation for non-admins * Make project icon in top nav itself dynamic as well * Fix story * Delete 0169_project_based_permissioning.py * Apply suggestions from code review Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Update frontend/src/layout/navigation/TopNavigation.tsx Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Address feedback * Project-based permissioning full data access restrictions (#6068) * Fix Access Control restriction tooltip * Add `TeamMemberAccessPermission` and use it in viewsets * Add `ErrorProjectUnavailable` scene * Ignore mypy * Update MainNavigation.tsx * Update explicit_team_member.py * Fix frontend detection of unavailable project * Fix some tests and edge cases * Fix basic permissions * Add more tests * Simplify `ExplicitTeamMemberViewSet` permissions * Improve restrictions and add moar tests * Update frontend * Fix a couple of things * Fix import * Fix some edge cases * Fix typing errors * Use hedgehog instead of moth Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Address feedback * Add proper permissioning to dashboard views * Update ee/api/test/test_dashboard.py Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com> * Run prettier * Remove debug code Co-authored-by: Paolo D'Amico <paolodamico@users.noreply.github.com>
2021-09-30 00:43:40 +02:00
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_shared_dashboard_in_private_project(self):
self.client.logout()
Dashboard.objects.create(
team=self.team, share_token="testtoken", name="public dashboard", is_shared=True,
)
response = self.client.get("/shared_dashboard/testtoken")
self.assertEqual(response.status_code, status.HTTP_200_OK)