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

Method get_user_organisation

api/users/models.py:290–311  ·  view source on GitHub ↗
(  # type: ignore[return]
        self, organisation: typing.Union["Organisation", int]
    )

Source from the content-addressed store, hash-verified

288 return user_organisation.date_joined
289
290 def get_user_organisation( # type: ignore[return]
291 self, organisation: typing.Union["Organisation", int]
292 ) -> UserOrganisation:
293 organisation_id = getattr(organisation, "id", organisation)
294
295 try:
296 # Since the user list view relies on this data, we prefetch it in
297 # the queryset, hence we can't use `userorganisation_set.get()`
298 # and instead use this next(filter()) approach. Since most users
299 # won't have more than ~1 organisation, we can accept the performance
300 # hit in the case that we are only getting the organisation for a
301 # single user.
302 return next(
303 filter(
304 lambda uo: uo.organisation_id == organisation_id,
305 self.userorganisation_set.all(),
306 )
307 )
308 except StopIteration:
309 logger.warning(
310 "User %d is not part of organisation %d" % (self.id, organisation_id)
311 )
312
313 def get_permitted_projects(
314 self,

Callers 4

get_organisation_roleMethod · 0.95
update_roleMethod · 0.80

Calls 1

allMethod · 0.45

Tested by

no test coverage detected