Python rest_framework.permissions 模块,AllowAny() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用rest_framework.permissions.AllowAny()

项目:drf-schema-adapter    作者:drf-forms    | 项目源码 | 文件源码
def setUp(self):
        self.endpoint = Endpoint(model=Product)
        self.fields = tuple([field.name for field in Product._meta.get_fields()])

        self.permission_classes = (AllowAny, )
        self.filter_fields = ('name', 'category_id')
        self.search_fields = ('id', 'name')
        self.ordering_fields = ('name', )
        self.page_size = 2

        self.alternate_endpoint = Endpoint(model=Product, permission_classes=self.permission_classes,
                                           filter_fields=self.filter_fields,
                                           search_fields=self.search_fields,
                                           ordering_fields=self.ordering_fields,
                                           page_size=self.page_size)
项目:drf-swagger-customization    作者:androiz    | 项目源码 | 文件源码
def get_swagger_view(title=None, url=None, patterns=None, urlconf=None):
    """
    Returns schema view which renders Swagger/OpenAPI.
    """
    class SwaggerSchemaView(APIView):
        _ignore_model_permissions = True
        exclude_from_schema = True
        permission_classes = [AllowAny]
        renderer_classes = [
            CoreJSONRenderer,
            CustomOpenAPIRenderer,
            renderers.SwaggerUIRenderer
        ]

        def get(self, request):
            generator = SchemaGenerator(
                title=title,
                url=url,
                patterns=patterns,
                urlconf=urlconf
            )
            schema = generator.get_schema(request=request)
            if not schema:
                raise exceptions.ValidationError(
                    'The schema generator did not return a schema Document'
                )
            return Response(schema)
    return SwaggerSchemaView.as_view()
项目:snippod-starter-demo-app-server    作者:shalomeir    | 项目源码 | 文件源码
def get_permissions(self):
        if self.request.method in permissions.SAFE_METHODS:
            return (permissions.AllowAny(),)

        if self.request.method == 'POST':
            return (permissions.AllowAny(),)

        return (permissions.IsAuthenticated(),IsAccountOwner(),)
项目:snippod-starter-demo-app-server    作者:shalomeir    | 项目源码 | 文件源码
def get_permissions(self):
        if self.request.method in permissions.SAFE_METHODS:
            return (permissions.AllowAny(),)
        return (permissions.IsAuthenticated(), IsAuthor(),)
项目:snippod-starter-demo-app-server    作者:shalomeir    | 项目源码 | 文件源码
def get_permissions(self):
        if self.request.method in permissions.SAFE_METHODS:
            return (permissions.AllowAny(),)
        return (permissions.IsAuthenticated(), IsAuthor(),)
项目:snippod-starter-demo-app-server    作者:shalomeir    | 项目源码 | 文件源码
def get_queryset(self):
        user_id = self.kwargs['userid']
        sorting = self.request.query_params.get('sorting', None)
        if sorting == 'upvotes':
            return Comment.sorted_objects.upvotes().filter(author=user_id)
        elif sorting == 'newest':
            return Comment.sorted_objects.newest().filter(author=user_id)
        else:
            return Comment.sorted_objects.upvotes().filter(author=user_id)


# class PostUpvoteViewSet(viewsets.ModelViewSet):
#     queryset = PostUpvote.objects.all()
#     serializer_class = PostUpvoteSerializer
#
#     def get_permissions(self):
#         if self.request.method in permissions.SAFE_METHODS:
#             return (permissions.AllowAny(),)
#         return (permissions.IsAuthenticated(), IsOwner(),)
#
#     def perform_create(self, serializer):
#         instance = serializer.save(voter=self.request.user)
#         return super(PostUpvoteViewSet, self).perform_create(serializer)
#
#
# class CommentUpvoteViewSet(viewsets.ModelViewSet):
#     queryset = PostUpvote.objects.all()
#     serializer_class = CommentUpvoteSerializer
#
#     def get_permissions(self):
#         if self.request.method in permissions.SAFE_METHODS:
#             return (permissions.AllowAny(),)
#         return (permissions.IsAuthenticated(), IsOwner(),)
#
#     def perform_create(self, serializer):
#         instance = serializer.save(voter=self.request.user)
#         return super(PostUpvoteViewSet, self).perform_create(serializer)
项目:conductor    作者:mblayman    | 项目源码 | 文件源码
def test_allow_any(self):
        viewset = views.SupportTicketViewSet()
        self.assertIn(permissions.AllowAny, viewset.permission_classes)