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

Method get_queryset

api/users/views.py:173–204  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

171 permission_classes = [IsAuthenticated, UserPermissionGroupPermission]
172
173 def get_queryset(self): # type: ignore[no-untyped-def]
174 if getattr(self, "swagger_fake_view", False):
175 return UserPermissionGroup.objects.none()
176
177 organisation_pk = self.kwargs.get("organisation_pk")
178 organisation = Organisation.objects.get(id=organisation_pk)
179
180 qs = UserPermissionGroup.objects.filter(organisation=organisation)
181 if (
182 self.action != "summaries"
183 and not self.request.user.has_organisation_permission( # type: ignore[union-attr]
184 organisation, MANAGE_USER_GROUPS
185 )
186 ):
187 # my_groups and summaries return a very cut down set of data, we can safely allow all users
188 # of the groups / organisation to retrieve them in this case, otherwise they must be a group admin.
189 q = Q(userpermissiongroupmembership__ffadminuser=self.request.user)
190 if self.action != "my_groups":
191 q = q & Q(userpermissiongroupmembership__group_admin=True)
192 qs = qs.filter(q)
193
194 if self.action == "list":
195 qs = qs.prefetch_related(
196 Prefetch(
197 "userpermissiongroupmembership_set",
198 queryset=UserPermissionGroupMembership.objects.select_related(
199 "ffadminuser"
200 ),
201 )
202 )
203
204 return qs
205
206 def paginate_queryset(self, queryset: QuerySet) -> list[UserPermissionGroup] | None: # type: ignore[override,type-arg] # noqa: E501
207 if self.action == "summaries":

Callers

nothing calls this directly

Calls 2

getMethod · 0.45

Tested by

no test coverage detected