This will return a boolean indicating if the considered permission is granted for the passed
        user.

    Usage::

        {% get_permission 'can_access_moderation_panel' request.user as var %}
480647
def get_permission(context, method, *args, **kwargs):
    
    request = context.get('request', None)
    perm_handler = request.forum_permission_handler if request else PermissionHandler()

    allowed_methods = inspect.getmembers(perm_handler, predicate=inspect.ismethod)
    allowed_method_names = [a[0] for a in allowed_methods if not a[0].startswith('_')]

    if method not in allowed_method_names:
        raise template.TemplateSyntaxError(
            'Only the following methods are allowed through '
            'this templatetag: {}'.format(allowed_method_names))

    perm_method = getattr(perm_handler, method)
    return perm_method(*args, **kwargs)
665717
def check_permissions(self):
        
        # Variable to supply some feedback
        changed_permissions = []
        changed_users = []
        warnings = []

        # Check that all the permissions are available.
        for model, perms in ASSIGNED_PERMISSIONS.items():
            if model == 'profile':
                model_obj = get_profile_model()
            else: model_obj = get_user_model()

            model_content_type = ContentType.objects.get_for_model(model_obj)

            for perm in perms:
                try:
                    Permission.objects.get(codename=perm[0],
                                           content_type=model_content_type)
                except Permission.DoesNotExist:
                    changed_permissions.append(perm[1])
                    Permission.objects.create(name=perm[1],
                                              codename=perm[0],
                                              content_type=model_content_type)

        # it is safe to rely on settings.ANONYMOUS_USER_NAME since it is a
        # requirement of django-guardian
        for user in get_user_model().objects.exclude(username=settings.ANONYMOUS_USER_NAME):
            try:
                user_profile = get_user_profile(user=user)
            except ObjectDoesNotExist:
                warnings.append(_("No profile found for %(username)s") \
                                    % {'username': user.username})
            else:
                all_permissions = get_perms(user, user_profile) + get_perms(user, user)

                for model, perms in ASSIGNED_PERMISSIONS.items():
                    if model == 'profile':
                        perm_object = get_user_profile(user=user)
                    else: perm_object = user

                    for perm in perms:
                        if perm[0] not in all_permissions:
                            assign_perm(perm[0], user, perm_object)
                            changed_users.append(user)

        return (changed_permissions, changed_users, warnings)
1309234
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_subscribe_to_topic(obj, user)
944968
def object_permission_set(self):
        ''''''
        return Or(
            AllowOnlySafeHttpMethod,
            AllowAdmin,
            And(
                AllowPermission('org:admin'),
                ObjAttrTrue(lambda _, u: not u.is_superuser),
                ObjAttrTrue(
                    lambda r, _: r.data.get('admin') is not True)
            ),
            And(
                AllowModify,
                ObjAttrTrue(
                    lambda req, user: user == req.user),
                ObjAttrTrue(
                    lambda r, _: r.data.get('admin') is not 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
1313028
def check_permissions(self, request):
        

        for permission in self.get_permissions():
            if not permission.has_permission(request, self):
                self.permission_denied(request, message=getattr(permission, 'message', None))
447738
def check_permissions(self, request):
        
        obj = (
            hasattr(self, 'get_controlled_object') and self.get_controlled_object() or
            hasattr(self, 'get_object') and self.get_object() or getattr(self, 'object', None)
        )
        user = request.user

        # Get the permissions to check
        perms = self.get_required_permissions(self)

        # Check permissions
        has_permissions = self.perform_permissions_check(user, obj, perms)

        if not has_permissions and not user.is_authenticated:
            return HttpResponseRedirect('{}?{}={}'.format(
                resolve_url(self.login_url),
                self.redirect_field_name,
                urlquote(request.get_full_path())
            ))
        elif not has_permissions:
            raise PermissionDenied
1026327
def has_permission(self, request):
        
        if not super(AdminSiteOTPRequiredMixin, self).has_permission(request):
            return False
        return request.user.is_verified()
9238
def check_permission(self, obj_id, permissions):
        
        response = self._client.session.post(
            '{url}/{id}/permissioncheck'.format(
                url=self.endpoint_url, id=obj_id
            ),
            data={'permissions': permissions}
        )
        return self.process_response(response)
422698
def check_permission(self, request):
        
        return all((permission.has_permission(request) for permission in self.permission_classes))
280904
def local_manager_consider_for_user(self):
        
        if not self.local_management_enabled:
            return False
        request = get_current_request()
        if authenticated_userid(request) == security.ADMIN_USER:
            return False
        roles = security.authenticated_user(request).roles
        if 'admin' in roles or 'manager' in roles:
            return False
        return True
1203607
def client_has_user_consent(self):
        
        value = False
        try:
            uc = UserConsent.objects.get(user=self.request.user, client=self.client)
            if (set(self.params['scope']).issubset(uc.scope)) and not (uc.has_expired()):
                value = True
        except UserConsent.DoesNotExist:
            pass

        return value
35187
def has_permission(self, user):
        
        return user.has_perm(
            self.model._meta.app_label + '.' + self.get_permission()
        )
1255305
def _has_perm(self, user, permission):
        

        if user.is_superuser:
            return True
        if user.is_active:
            perms = [perm.split('.')[1] for perm in user.get_all_permissions()]
            return permission in perms
        return False
699821
def has_object_permission(self, request, view, obj):
        
        user = request.user
        if not user.is_authenticated:
            return False
        elif user.is_staff or user.is_superuser:
            return True
        return user == obj.user
1024033
def has_add_permission(self, request):
        
        opts = self.opts
        return request.user.has_perm(opts.app_label + '.' + opts.get_add_permission())
540980
def has_permission(self, request, view):
        
        user_filter = self._get_user_filter(request)
        if not user_filter:
            # no user filters are present in the token to limit access
            return True

        username_param = get_username_param(request)
        allowed = user_filter == username_param
        if not allowed:
            log.warning(
                u"Permission JwtHasUserFilterForRequestedUser: user_filter %s doesn't match username %s.",
                user_filter,
                username_param,
            )
        return allowed