Filter queries to only those owned by current user if
        can_only_access_owned_queries permission is set.

        :returns: query
431504
def apply(
            self,
            query: BaseQuery,
            func: Callable) -> BaseQuery:
        
        if security_manager.can_only_access_owned_queries():
            query = (
                query
                .filter(Query.user_id == g.user.get_user_id())
            )
        return query
926398
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_access_moderation_queue(user)
239173
def filter(self, *args, **kwargs) -> "QuerySet":
        
        return self._filter_or_exclude(negate=False, *args, **kwargs)
424279
def superuser_only(view_func):
    
    def _inner(request, *args, **kwargs):
        if not request.user.is_superuser:
            raise PermissionDenied
        return view_func(request, *args, **kwargs)
    return _inner
963663
def get_queryset(self, request):
        ''' '''
        qs = super(SubmissionAdmin, self).get_queryset(request)
        if request.user.is_superuser:
            return qs
        else:
            return qs.filter(Q(assignment__course__tutors__pk=request.user.pk) | Q(assignment__course__owner=request.user)).distinct()
601104
def filter_by_device_owner(query, device_owners=None):
    
    port_model = models_v2.Port
    if not device_owners:
        device_owners = utils.SUPPORTED_DEVICE_OWNERS
    supported_device_owner_filter = [
        port_model.device_owner.ilike('%s%%' % owner)
        for owner in device_owners]
    unsupported_device_owner_filter = [
        port_model.device_owner.notilike('%s%%' % owner)
        for owner in utils.UNSUPPORTED_DEVICE_OWNERS]
    query = (query
             .filter(
                 and_(*unsupported_device_owner_filter),
                 or_(*supported_device_owner_filter)))
    return query
124618
def filter_queryset(self, request, queryset, view):
        """"""
        user = request.user

        app_label = queryset.model._meta.app_label  # pylint: disable=protected-access
        model_name = queryset.model._meta.model_name  # pylint: disable=protected-access

        kwargs = {}
        if model_name == 'storage':
            model_name = 'data'
            kwargs['perms_filter'] = 'data__pk__in'

        if model_name == 'relation':
            model_name = 'collection'
            kwargs['perms_filter'] = 'collection__pk__in'

        permission = '{}.view_{}'.format(app_label, model_name)

        return get_objects_for_user(user, permission, queryset, **kwargs)
843328
def filter_by_user(self, user):
        """"""

        return self.filter(Q(users=user) | Q(groups__in=user.groups.all()))
1127734
def list(self, **filters):
        
        LOG.debug(u'Querying %s by filters=%s', self.model_class.__name__, filters)
        query = self.__queryset__()
        perm = build_permission_name(self.model_class, 'view')
        LOG.debug(u"Checking if user %s has_perm %s" % (self.user, perm))
        query_with_permission = filter(lambda o: self.user.has_perm(perm, obj=o), query)
        ids = map(lambda o: o.pk, query_with_permission)

        # FIXME: Return to query again without use database
        queryset = self.__queryset__().filter(pk__in=ids)
        related = getattr(self, 'select_related', None)
        if related:
            queryset = queryset.select_related(*related)

        return queryset
858500
def has_permissions(self):
        
        perms = self.request('/me/permissions')['data'][0].keys()
        return all(k in perms for k in app.config[
            'CANVAS_SCOPE'].split(','))
779698
def filter_out(queryset, setting_name):
  
  kwargs = helpers.get_settings().get(setting_name, {}).get('FILTER_OUT', {})
  queryset = queryset.exclude(**kwargs)
  return queryset
257491
def get_queryset_filters(self, query):
        
        conditions = Q()
        for field_name in self.fields:
            conditions |= Q(**{
                self._construct_qs_filter(field_name): query
            })
        return conditions
972146
def _get_query(self, order=None, filters=None):
        
        order = self._get_order(order)
        return self.posts.all().order_by(order)
331250
def index_queryset(self, using=None):
        """"""

        kwargs = {"active": True}

        # if permissions are enabled then we want only public pages
        # https://github.com/leonardo-modules/leonardo-module-pagepermissions
        if hasattr(Page(), 'permissions'):
            kwargs['permissions__isnull'] = True

        # https://github.com/leonardo-modules/leonardo-page-search
        if hasattr(Page(), 'search_exclude'):
            kwargs['search_exclude'] = False

        return self.get_model().objects.filter(**kwargs)
1121525
def queryset(self, request, queryset):
        
        if self.value() is not None:
            return queryset.filter(user__pk=self.value())
        else:
            return queryset
607958
def get_queryset(self, request):
        """"""
        qs = super(TenantGroupAdmin, self).get_queryset(request)
        if not request.user.is_superuser:
            qs = qs.filter(tenantrole__user=request.user,
                           tenantrole__role=TenantRole.ROLE_GROUP_MANAGER)
        return qs
721120
def queries(self):
        
        if self._queries is None:
            self._queries = QueryList(self._version, assistant_sid=self._solution['sid'], )
        return self._queries