check filter permissions
171799
def has_object_permission(self, request, view, obj):
        

        user = request.user

        if not user.is_superuser and not user.is_anonymous():
            valid = False
            try:
                ct = ContentType.objects.get_for_model(obj)
                fpm = FilterPermissionModel.objects.get(user=user,
                                                        content_type=ct)
                myq = QSerializer(base64=True).loads(fpm.filter)
                try:
                    myobj = obj.__class__.objects.filter(myq).distinct().get(pk=obj.pk)
                    if myobj:
                        valid = True
                except ObjectDoesNotExist:
                    valid = False
            except ObjectDoesNotExist:
                valid = True
            finally:
                return valid
        else:
            return True
5479
def has_permission(self, request, view):
        """"""
        if view.suffix == 'Instance':
            return True

        filter_and_actions = self._get_filter_and_actions(
            request.query_params.get('sign'),
            view.action,
            '{}.{}'.format(
                view.queryset.model._meta.app_label,
                view.queryset.model._meta.model_name
            )
        )
        if not filter_and_actions:
            return False
        if request.method == 'POST':
            for key, value in request.data.iteritems():
                # Do unicode conversion because value will always be a
                # string
                if (key in filter_and_actions['filters'] and not
                        unicode(filter_and_actions['filters'][key]) == unicode(value)):
                    return False
        return True
575552
def filter(self, table, security_groups, filter_string):
        """"""
        query = filter_string.lower()
        return [security_group for security_group in security_groups
                if query in security_group.name.lower()]
817474
protected function checkFilters()
    {
        $current = $this->prepareForReturn($this->current);

        foreach ($this->filters as $tuple) {
            $result = call_user_func(
                $tuple[0],
                $current->copy(),
                $this->key,
                $this
            );

            if ($result === static::END_ITERATION) {
                return static::END_ITERATION;
            }

            if (!$result) {
                return false;
            }
        }

        return true;
    }
1043804
def validate_file_permissions(config):
    """"""
    files = config.get('files', {})
    for file_name, options in files.items():
        for key in options.keys():
            if key not in ["owner", "group", "mode"]:
                raise RuntimeError(
                    "Invalid ownership configuration: {}".format(key))
        mode = options.get('mode', config.get('permissions', '600'))
        optional = options.get('optional', config.get('optional', 'False'))
        if '*' in file_name:
            for file in glob.glob(file_name):
                if file not in files.keys():
                    if os.path.isfile(file):
                        _validate_file_mode(mode, file, optional)
        else:
            if os.path.isfile(file_name):
                _validate_file_mode(mode, file_name, optional)
960096
def _get_all_permissions(opts, tools):
    """"""
    perms = []
    for tool in tools:
        perms.append((_get_permission_codename(tool, opts), 'Can %s %s' % \
                (tool.name, opts.verbose_name_plural)))
    return perms
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(','))
648254
def list_user_permissions(self, name):
        
        return self._api_get('/api/users/{0}/permissions'.format(
            urllib.parse.quote_plus(name)
        ))
1313119
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_download_files(obj, user)
1228084
def setup_filter(self, root_path, path_list):
        """"""
        self.root_path = osp.normpath(to_text_string(root_path))
        self.path_list = [osp.normpath(to_text_string(p)) for p in path_list]
        self.invalidateFilter()
298497
def check_public_permissions(payload):
    """"""
    allowed_public_permissions = ['view', 'add', 'download']
    for perm_type in ['add', 'remove']:
        for perm in payload.get('public', {}).get(perm_type, []):
            if perm not in allowed_public_permissions:
                raise exceptions.PermissionDenied("Permissions for public users are too open")
999551
def _check_view_permission(self, view):
        
        security = get_service("security")
        return security.has_permission(current_user, view.permission, self.obj)
901386
def has_permission(self, perm):
        
        return self.user.superuser or self.auth.has_permission(perm)
221845
def filter_(*permissions, **kwargs):
    
    bearer = kwargs['bearer']
    target = kwargs.get('target')
    bearer_cls = type_for(bearer)

    # We need a query object.  There are many ways to get one,  Either we can
    # be passed one, or we can make one from the session.  We can either be
    # passed the session, or we can grab the session from the bearer passed.

    if 'query' in kwargs:
        query = kwargs['query']
    elif 'session' in kwargs:
        query = kwargs['session'].query(target)
    else:
        query = object_session(bearer).query(target)

    getter = functools.partial(
        registry.retrieve,
        bearer=bearer_cls,
        target=target)

    try:
        # Generate a hash of {rulefn: permission} that we can use later
        # to collect all of the rules.
        if len(permissions):
            rules = {getter(permission=x): x for x in permissions}
        else:
            rules = {getter(): None}
    except KeyError:
        # No rules defined.  Default to no permission.
        return query.filter(sql.false())

    # Invoke all the rules and collect the results

    # Abusing reduce here to invoke each rule and send the return value (query)
    # from one rule to the next one.  In this way the query becomes
    # increasingly decorated as it marches through the system.

    # q == query
    # r = (rulefn, permission)
    reducer = lambda q, r: r[0](permission=r[1], query=q, bearer=bearer)

    return reduce(reducer, six.iteritems(rules), query)
1060502
private boolean checkPermission(String permission) {
        int res = ctx.checkCallingOrSelfPermission(permission);
        return (res == PackageManager.PERMISSION_GRANTED);
    }
246678
def has_perm(self, user, perm, obj=None):
        """"""
        if not user.is_active:
            return False
        return perm in self.get_all_permissions(user, obj)
927508
protected function getFilteredPermissions()
    {
        $permissions = BackendAuth::listTabbedPermissions();

        if ($this->user->isSuperUser()) {
            return $permissions;
        }

        foreach ($permissions as $tab => $permissionsArray) {
            foreach ($permissionsArray as $index => $permission) {
                if (!$this->user->hasAccess($permission->code)) {
                    unset($permissionsArray[$index]);
                }
            }

            if (empty($permissionsArray)) {
                unset($permissions[$tab]);
            }
            else {
                $permissions[$tab] = $permissionsArray;
            }
        }

        return $permissions;
    }