MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / has_permission

Method has_permission

api/projects/permissions.py:14–49  ·  view source on GitHub ↗

Check if user has permission to list / create project

(self, request, view)

Source from the content-addressed store, hash-verified

12
13class ProjectPermissions(IsAuthenticated):
14 def has_permission(self, request, view): # type: ignore[no-untyped-def]
15 """Check if user has permission to list / create project"""
16 if not super().has_permission(request, view):
17 return False
18
19 if view.action == "create" and request.user.belongs_to(
20 int(request.data.get("organisation"))
21 ):
22 organisation = Organisation.objects.select_related("subscription").get(
23 id=int(request.data.get("organisation"))
24 )
25
26 # Allow project creation based on the active subscription
27 subscription_metadata = (
28 organisation.subscription.get_subscription_metadata()
29 )
30
31 total_projects_created = Project.objects.filter(
32 organisation=organisation
33 ).count()
34 if (
35 subscription_metadata.projects
36 and total_projects_created >= subscription_metadata.projects
37 and getattr(request, "is_e2e", False) is not True
38 ):
39 return False
40 if organisation.restrict_project_create_to_admin:
41 return request.user.is_organisation_admin(organisation.pk)
42 return request.user.has_organisation_permission(
43 organisation, CREATE_PROJECT
44 )
45 if view.action in ("list", "permissions", "get_by_uuid"):
46 return True
47
48 # move on to object specific permissions
49 return view.detail
50
51 def has_object_permission(self, request, view, obj): # type: ignore[no-untyped-def]
52 """Check if user has permission to view / edit / delete project"""

Calls 6

has_permissionMethod · 0.45
belongs_toMethod · 0.45
getMethod · 0.45
is_organisation_adminMethod · 0.45