:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(projects): unblock project creation for members and stop a 500 (#86048)
posthog[bot]8526978123b6
diff --git a/frontend/src/scenes/project/CreateProjectModal.tsx b/frontend/src/scenes/project/CreateProjectModal.tsxindex 393248863d19..3bad97327c10 100644--- a/frontend/src/scenes/project/CreateProjectModal.tsx+++ b/frontend/src/scenes/project/CreateProjectModal.tsx@@ -31,7 +31,7 @@ export function CreateProjectModal({}): JSX.Element {const { currentProject, currentProjectLoading } = useValues(projectLogic)const { createProject } = useActions(projectLogic)- const { currentOrganization } = useValues(organizationLogic)+ const { currentOrganization, projectCreationForbiddenReason } = useValues(organizationLogic)const { reportProjectCreationSubmitted } = useActions(eventUsageLogic)const [name, setName] = useState<string>('')@@ -49,7 +49,7 @@ export function CreateProjectModal({}const handleSubmit = (): void => {// Also guards Enter-key submission, which bypasses the button's disabledReason- if (!name || isNameTaken || currentProjectLoading) {+ if (!name || isNameTaken || currentProjectLoading || projectCreationForbiddenReason) {return}createProject({ name })@@ -112,11 +112,13 @@ export function CreateProjectModal({onClick={handleSubmit}loading={currentProjectLoading}disabledReason={- !name- ? 'Think of a name!'- : isNameTaken- ? 'There is already a project with this name in this organization. Choose a different name.'- : null+ projectCreationForbiddenReason+ ? projectCreationForbiddenReason+ : !name+ ? 'Think of a name!'+ : isNameTaken+ ? 'There is already a project with this name in this organization. Choose a different name.'+ : null}>Create projectdiff --git a/posthog/api/project.py b/posthog/api/project.pyindex 2c85ea691697..1a96252e72ce 100644--- a/posthog/api/project.py+++ b/posthog/api/project.py@@ -1419,7 +1419,9 @@ class ProjectViewSet(if self.action:if self.action == "create":if "is_demo" not in self.request.data or not self.request.data["is_demo"]:- permissions.append(UserCanCreateProjectPermission)+ # Evaluate the create-access check before the premium check so a member who lacks+ # permission gets the permission message, not the plan-upgrade one.+ permissions.insert(permissions.index(PremiumMultiProjectPermission), UserCanCreateProjectPermission)else:permissions.append(OrganizationMemberPermissions)elif self.action != "list":diff --git a/posthog/api/test/test_project.py b/posthog/api/test/test_project.pyindex 137b9cebb965..d8b457c7c7c3 100644--- a/posthog/api/test/test_project.py+++ b/posthog/api/test/test_project.py@@ -275,6 +275,21 @@ class TestProjectAPI(team_api_test_factory()): # type: ignoreresponse.json()["detail"], "You need to be an organization admin or above to create new projects.")+ def test_member_over_plan_limit_gets_permission_message_not_billing(self):+ # A non-admin member in an org that is also at its plan limit must be told they lack+ # permission, not pointed at billing - upgrading the plan cannot unblock them.+ self.organization.available_product_features = [] # no projects feature: capped at the 1 existing project+ self.organization.save()+ self.organization_membership.level = OrganizationMembership.Level.MEMBER+ self.organization_membership.save()++ response = self.client.post("/api/projects/", {"name": "Member Project"})++ self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)+ self.assertEqual(+ response.json()["detail"], "You need to be an organization admin or above to create new projects."+ )+def test_member_cannot_create_project_without_entitlement_even_when_toggle_on(self):# No invite-settings entitlement: the toggle is ignored and the gate behaves as admin-only.self._set_unlimited_projects(with_member_create_entitlement=False)diff --git a/posthog/rbac/test/test_user_access_control.py b/posthog/rbac/test/test_user_access_control.pyindex 4e0b015cc78e..6ee7fdeeadca 100644--- a/posthog/rbac/test/test_user_access_control.py+++ b/posthog/rbac/test/test_user_access_control.py@@ -974,6 +974,18 @@ class TestUserAccessControlGetUserAccessLevel(BaseUserAccessControlTest):access_level = uac.get_user_access_level(self.dashboard)assert access_level is None+ def test_object_access_resolves_when_access_control_has_no_team(self):+ # A create request builds the access control with team=None (no team exists yet). Serializing+ # the create response must resolve the object's level from the organization scope instead of+ # raising AttributeError on the missing team.+ uac = UserAccessControl(user=self.user_with_no_role, team=None, organization_id=self.organization.id)++ # user_with_no_role is a plain member and did not create self.team, so resolution falls through+ # to the object-level lookup that would otherwise read the absent team. With no restricting+ # access control it resolves to the project default rather than raising.+ access_level = uac.get_user_access_level(self.team)+ assert access_level == "admin"+def test_unsupported_model_returns_none(self):"""Test that unsupported models return None"""diff --git a/posthog/rbac/user_access_control.py b/posthog/rbac/user_access_control.pyindex 7d6fe6f5493f..49a29afc256e 100644--- a/posthog/rbac/user_access_control.py+++ b/posthog/rbac/user_access_control.py@@ -622,7 +622,14 @@ class UserAccessControl:"""Used when checking an individual object - gets all access controls for the object and its type"""- return {"team_id": self._team.id, "resource": resource, "resource_id": resource_id} # type: ignore+ filters: dict[str, Any] = {"resource": resource, "resource_id": resource_id}+ # A create request has no team yet, so fall back to the organization scope like the queryset+ # variant does - otherwise serializing the create response raises AttributeError on team.id.+ if self._team:+ filters["team_id"] = self._team.id+ elif self._organization_id:+ filters["team__organization_id"] = str(self._organization_id)+ return filtersdef _access_controls_filters_for_resource(self, resource: APIScopeObject) -> dict:"""