def test_user_permitted_objects_returns_permitted_requests( self, user_with_role_assignments, test_garden, test_request ): permitted_requests = user_permitted_objects( user_with_role_assignments, Request, "request:read" ) assert test_request in permitted_requests
def test_user_permitted_objects_returns_permitted_jobs( self, user_with_role_assignments, test_garden, test_job ): permitted_jobs = user_permitted_objects( user_with_role_assignments, Job, "job:read" ) assert test_job in permitted_jobs
def test_user_permitted_objects_does_not_return_nonpermitted_jobs( self, user_with_role_assignments, test_garden, test_job ): permitted_jobs = user_permitted_objects( user_with_role_assignments, Job, "unassigned_permission" ) assert test_job not in permitted_jobs
def test_user_permitted_objects_does_not_return_nonpermitted_gardens( self, user_with_role_assignments, test_garden ): permitted_gardens = user_permitted_objects( user_with_role_assignments, Garden, "unassigned_permission" ) assert test_garden not in permitted_gardens
def test_user_permitted_objects_returns_permitted_gardens_via_global( self, user_with_role_assignments, test_garden ): permitted_gardens = user_permitted_objects( user_with_role_assignments, Garden, "garden:create" ) assert test_garden in permitted_gardens
def test_user_permitted_objects_does_not_return_nonpermitted_systems( self, user_with_role_assignments, test_garden ): permitted_systems = user_permitted_objects( user_with_role_assignments, System, "unassigned_permission" ) assert test_system_1_0_0 not in permitted_systems assert test_system_2_0_0 not in permitted_systems
def test_user_permitted_objects_returns_permitted_systems( self, user_with_role_assignments, test_system_1_0_0, test_system_2_0_0 ): permitted_systems = user_permitted_objects( user_with_role_assignments, System, "request:read" ) assert test_system_1_0_0 in permitted_systems assert test_system_2_0_0 in permitted_systems
def permissioned_queryset(self, model: Type[Document], permission: str) -> QuerySet: """Returns a QuerySet for the provided Document model filtered down to only the objects for which the requesting user has the given permission Args: model: The Document model to be filtered permission: The required permission that will be used to filter objects Returns: QuerySet: A QuerySet for model filtered down to objects the requesting user has access to. """ return user_permitted_objects(self.current_user, model, permission)