Determines if the user has permissions to publish.

        :param request: Django request object.
        :param obj: The object to determine if the user has
        permissions to publish.
        :return: Boolean.
428607
def has_publish_permission(self, request, obj=None):
        
        # If auto-publishing is enabled, no user has "permission" to publish
        # because it happens automatically
        if is_automatic_publishing_enabled(self.model):
            return False
        user_obj = request.user
        if not user_obj.is_active:
            return False
        if user_obj.is_superuser:
            return True
        # Normal user with `can_publish` permission can always publish
        if user_obj.has_perm('%s.can_publish' % self.opts.app_label):
            return True
        # Normal user with `can_republish` permission can only publish if the
        # item is already published.
        if user_obj.has_perm('%s.can_republish' % self.opts.app_label) and \
                obj and getattr(obj, 'has_been_published', False):
            return True
        # User does not meet any publishing permisison requirements; reject!
        return False
479913
def has_permission(self, permission, obj=None):
        
        if not permission:
            logger.warn("None permission is not allowed")
            return False
        if obj is None:
            return check_permission(permission, self.context)
        return check_permission(permission, api.get_object(obj))
1289418
def show_form_for_method(self, view, method, request, obj):
        
        if method not in view.allowed_methods:
            return  # Not a valid method

        try:
            view.check_permissions(request)
            if obj is not None:
                view.check_object_permissions(request, obj)
        except exceptions.APIException:
            return False  # Doesn't have permissions
        return True
58153
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_unsubscribe_from_topic(obj, user)
1139035
def check_model_permission(self, app, model):
        
        if self.apps_dict.get(app, False) and model in self.apps_dict[app]['models']:
            return True

        return False
969415
def detail_permissions(self, request, pk=None):
        """"""
        obj = self.get_object()

        if request.method == 'POST':
            content_type = ContentType.objects.get_for_model(obj)
            payload = request.data
            share_content = strtobool(payload.pop('share_content', 'false'))
            user = request.user
            is_owner = user.has_perm('owner_{}'.format(content_type), obj=obj)

            allow_owner = is_owner or user.is_superuser
            check_owner_permission(payload, allow_owner)
            check_public_permissions(payload)
            check_user_permissions(payload, request.user.pk)

            with transaction.atomic():
                update_permission(obj, payload)

                owner_count = UserObjectPermission.objects.filter(
                    object_pk=obj.id,
                    content_type=content_type,
                    permission__codename__startswith='owner_'
                ).count()

                if not owner_count:
                    raise exceptions.ParseError('Object must have at least one owner.')

            if share_content:
                self.set_content_permissions(user, obj, payload)

        return Response(get_object_perms(obj))
1250289
def get_permissions(self, user, obj=_nothing):
        
        rule = self._get_rule(obj)

        all_permissions = (
            attr[len('can_'):] for attr in dir(rule)
            if attr.startswith('can_')
        )

        return set(
            permission for permission in all_permissions
            if self.allows(user, permission, obj)
        )
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
1166927
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_add_post(obj, user)
380689
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_move_topics(obj, user)
753229
def has_object_permission(self, request, view, obj):
        
        # Give permission if we're not protecting this method
        if self.protected_methods and request.method not in self.protected_methods:
            return True

        user = getattr(request, "user", None)

        if not user or user.is_anonymous():
            return False

        if self.require_staff and not user.is_staff:
            return False

        # if they have higher-level privileges we can return true right now
        if user.has_perms(self.permissions):
            return True

        # no? ok maybe they're the author and have appropriate author permissions.
        authors_field = getattr(obj, self.authors_field, None)

        if not authors_field:
            return False

        if self.author_permissions and not user.has_perms(self.author_permissions):
            return False

        return user in authors_field.all()
909870
def is_editable(self, request):
        
        return request.user.is_superuser or request.user.id == self.user_id
683091
def check(self, user, permission, obj=_nothing):
        
        if not self.allows(user, permission, obj):
            raise AuthorizationError(
                'Can\'t {} object of class {}'.format(
                    permission, type(obj)))
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)
1209190
def check_permissions(self, request):
        """"""

        if not self.predicates:
            return True

        # All registered authentication predicates must return True
        return all(
            predicate(request, *self.predicates_params[i])
            for i, predicate in enumerate(self.predicates)
        )
30437
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_delete_topics(obj, user)
994524
def has_permission(
    permission,
    context=None,
):
    
    def wrapper(fn):
        @wraps(fn)
        async def wrapped(*args, **kwargs):
            request = args[-1]
            if not isinstance(request, web.BaseRequest):
                msg = ("Incorrect decorator usage. "
                       "Expecting `def handler(request)` "
                       "or `def handler(self, request)`.")
                raise RuntimeError(msg)

            await check_permission(request, permission, context)
            return await fn(*args, **kwargs)

        return wrapped

    warnings.warn("has_permission decorator is deprecated, "
                  "use check_permission instead",
                  DeprecationWarning)
    return wrapper