def filter(self, user, operation, resource, iterable): query = shield.filter(*self.permissions[operation], bearer=user, target=resource.meta.model, query=iterable) return query.distinct()
def test_filter(self): self.register_membership() user = self.users[0] team_ids = {x.id for x in user.teams} query = shield.filter('member', bearer=user, target=models.Team) assert {x.id for x in query} == team_ids
def test_deferred_target_style(self): self.register_membership() shield.deferred_rule(attributes=('team', ), bearer=models.User, target=models.Box) result = shield.filter('member', bearer=self.users[0], target=models.Box) assert result.count() == 5
def filter(self, user, operation, resource, iterable): clause = shield.filter( *self.permissions[operation], bearer=user, target=resource.meta.model) return resource.filter(clause, iterable)