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

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

项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def get_permissions(self):
    request = self.get_serializer_context()['request']
    if self.action == 'create':
      self.permission_classes = (permissions.IsAuthenticated,)
    if self.action == 'partial_update':
      self.permission_classes = (permissions.IsAuthenticated, organization_permissions.OwnsOrIsOrganizationMember)
    if self.action == 'retrieve':
      self.permission_classes = ()
    if self.action in ['invite_user', 'revoke_invite']:
      self.permission_classes = (permissions.IsAuthenticated, organization_permissions.OwnsOrIsOrganizationMember)
    if self.action == 'join':
      self.permission_classes = (permissions.IsAuthenticated, organization_permissions.IsInvitedToOrganization)
    if self.action == 'leave':
      self.permission_classes = (permissions.IsAuthenticated, organization_permissions.IsOrganizationMember)
    if self.action == 'remove_member':
      self.permission_classes = (permissions.IsAuthenticated, organization_permissions.OwnsOrganization)
    if self.action in ['bookmark', 'unbookmark', 'bookmarked']:
      self.permission_classes = self.get_bookmark_permissions()

    return super(OrganizationResourceViewSet, self).get_permissions()
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def get_permissions(self):
    request = self.get_serializer_context()['request']

    if self.action in ['list', 'partial_update']:
      self.permission_classes = (permissions.IsAuthenticated, ProjectApplyPermission)

    if self.action == 'apply':
      if int(get_channel_setting(request.channel, "UNAUTHENTICATED_APPLY")[0]):
        self.permission_classes = ()
      else:
        self.permission_classes = (permissions.IsAuthenticated, )

    if self.action == 'unapply':
      self.permission_classes = (permissions.IsAuthenticated, )


    return super(ApplyResourceViewSet, self).get_permissions()
项目:thorn    作者:robinhood    | 项目源码 | 文件源码
def test_permission_classes(patching, View):
    view = mock_view(View)
    current_app = patching(
        'thorn.django.rest_framework.views.current_app')
    app = current_app()
    app.settings.THORN_DRF_PERMISSION_CLASSES = None
    assert view.permission_classes == (IsAuthenticated,)
    app.settings.THORN_DRF_PERMISSION_CLASSES = (303, 808)
    assert view.permission_classes == (303, 808)
项目:thorn    作者:robinhood    | 项目源码 | 文件源码
def _permission_classes(view):
    perms = current_app().settings.THORN_DRF_PERMISSION_CLASSES
    return perms if perms is not None else (IsAuthenticated,)
项目:django-shared-schema-tenants    作者:hugobessa    | 项目源码 | 文件源码
def get_permissions(self):
        if self.request.method == 'POST':
            self.permission_classes = [permissions.IsAuthenticated]
        return super(TenantListView, self).get_permissions()
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def get_bookmark_permissions(self):
    return (permissions.IsAuthenticated, )
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def get_permissions(self):
    request = self.get_serializer_context()['request']
    if self.action == 'create':
      if int(get_channel_setting(request.channel, "CAN_CREATE_PROJECTS_IN_ANY_ORGANIZATION")[0]):
        self.permission_classes = (permissions.IsAuthenticated, )
      else:
        self.permission_classes = (permissions.IsAuthenticated, ProjectCreateOwnsOrIsOrganizationMember)

    if self.action == 'partial_update':
      self.permission_classes = (permissions.IsAuthenticated, ProjectRetrieveOwnsOrIsOrganizationMember)

    if self.action == 'retrieve':
      self.permission_classes = ()

    if self.action == 'manageable':
      self.permission_classes = (permissions.IsAuthenticated, )

    if self.action == 'close':
      self.permission_classes = (permissions.IsAuthenticated, ProjectRetrieveOwnsOrIsOrganizationMember)

    if self.action in ['bookmark', 'unbookmark', 'bookmarked']:
      self.permission_classes = self.get_bookmark_permissions()

    if self.action == 'export_applied_users':
      self.permission_classes = (permissions.IsAuthenticated, ProjectRetrieveOwnsOrIsOrganizationMember)

    return super(ProjectResourceViewSet, self).get_permissions()
项目:django-open-volunteering-platform    作者:OpenVolunteeringPlatform    | 项目源码 | 文件源码
def get_permissions(self):
    request = self.get_serializer_context()['request']
    if self.action == 'create':
      self.permission_classes = []
    elif self.action in ['current_user']:
      self.permission_classes = [permissions.IsAuthenticated, ]

    return super(UserResourceViewSet, self).get_permissions()
项目:django-rest-framework-tutorial    作者:twtrubiks    | 项目源码 | 文件源码
def get_permissions(self):
        if self.action in ('create',):
            self.permission_classes = [IsAuthenticated]
        return [permission() for permission in self.permission_classes]

    # [GET] api/shares/
项目:djangocon2017viewsets    作者:buddylindsey    | 项目源码 | 文件源码
def test_attrs(self):
        self.assertIsInstance(self.view, mixins.CreateModelMixin)
        self.assertIsInstance(self.view, mixins.ListModelMixin)
        self.assertIsInstance(self.view, mixins.UpdateModelMixin)
        self.assertIsInstance(self.view, mixins.RetrieveModelMixin)
        self.assertIsInstance(self.view, mixins.DestroyModelMixin)
        self.assertIsInstance(self.view, viewsets.GenericViewSet)

        self.assertEqual(self.view.permission_classes, (IsAuthenticated,))
        self.assertEqual(self.view.serializer_class, CoinSerializer)
        self.assertSequenceEqual(
            self.view.filter_backends,
            (filters.DjangoFilterBackend, BitFilter))

        self.assertEqual(self.view.filter_class, CoinFilter)
项目:BrewCenterAPI    作者:BrewCenter    | 项目源码 | 文件源码
def get_permissions(self):
        """Define custom permissions for different methods"""

        # at minimum require users to be authenticated
        self.permission_classes = [IsAuthenticated]
        # for PUT requests require users to be admins
        if self.request.method == 'PUT':
            self.permission_classes.append(IsAdminUser)

        return super(viewsets.ViewSet, self).get_permissions()
项目:BrewCenterAPI    作者:BrewCenter    | 项目源码 | 文件源码
def get_permissions(self):
        """Define custom permissions for different methods"""

        # at minimum require users to be authenticated
        self.permission_classes = [IsAuthenticated]
        # for PUT requests require users to be admins
        if self.request.method == 'PUT':
            self.permission_classes.append(IsAdminUser)

        return super(viewsets.ViewSet, self).get_permissions()
项目: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)
项目:occasions-server    作者:travisbloom    | 项目源码 | 文件源码
def wrap_as_django_rest_framework_view(cls, *args, **kwargs):
        view = cls.as_view(*args, **kwargs)
        view = permission_classes((IsAuthenticated,))(view)
        view = authentication_classes(cls.get_view_authentication_classes())(view)
        view = api_view(['POST', 'GET'])(view)
        return view
项目:timestrap    作者:overshard    | 项目源码 | 文件源码
def get_permissions(self):
        # Prevent rest_framework from checking for the "view" perm.
        return (permissions.IsAuthenticated(),)
项目:timestrap    作者:overshard    | 项目源码 | 文件源码
def get_permissions(self):
        # Prevent rest_framework from checking for the "view" perm.
        return (permissions.IsAuthenticated(),)
项目:conductor    作者:mblayman    | 项目源码 | 文件源码
def get_permissions(self):
        if self.action == 'retrieve':
            self.permission_classes = (permissions.IsAuthenticated, IsUser)
        return super(UserViewSet, self).get_permissions()
项目:django-netbox-graphql    作者:ninech    | 项目源码 | 文件源码
def as_view(cls, *args, **kwargs):
        view = super(DRFAuthenticatedGraphQLView, cls).as_view(*args, **kwargs)
        view = permission_classes((IsAuthenticated,))(view)
        view = authentication_classes(api_settings.DEFAULT_AUTHENTICATION_CLASSES)(view)
        view = api_view(['GET', 'POST'])(view)
        return view
项目:atados-ovp    作者:atados    | 项目源码 | 文件源码
def get_permissions(self):
    request = self.get_serializer_context()["request"]

    if self.action == "list":
      self.permission_classes = ()

    if self.action in ["appoint", "unappoint", "appointments"]:
      self.permission_classes = (permissions.IsAuthenticated, )

    return super(MeetingViewSet, self).get_permissions()
项目:iguana    作者:iguana-project    | 项目源码 | 文件源码
def get_permissions(self):
        if self.action == 'list' or self.action == 'create':
            return [permissions.IsAuthenticated(), ]
        if self.action == 'retrieve':
            return [permissions.IsAuthenticated(), UserIsMemberInProject()]
        if self.action in ('update', 'partial_update', 'destroy'):
            return [permissions.IsAuthenticated(), UserIsManagerInProject()]
        return [permissions.IsAuthenticated(), UserIsManagerInProject()]
项目:iguana    作者:iguana-project    | 项目源码 | 文件源码
def get_permissions(self):
        if self.action in ('list', 'retrieve', 'create'):
            return [permissions.IsAuthenticated(), UserIsMemberInProject()]
        if self.action in ('update', 'partial_update', 'destroy'):
            return [permissions.IsAuthenticated(), UserIsOwnerOrManager()]
        return [permissions.IsAuthenticated(), UserIsOwnerOrManager()]
项目:iguana    作者:iguana-project    | 项目源码 | 文件源码
def get_permissions(self):
        if self.action in ('list', 'retrieve', 'create'):
            return [permissions.IsAuthenticated(), UserIsMemberInProject()]
        if self.action in ('update', 'partial_update', 'destroy'):
            return [permissions.IsAuthenticated(), UserIsOwnerOrManager()]
        return [permissions.IsAuthenticated(), UserIsOwnerOrManager()]
项目:tunga-api    作者:tunga-io    | 项目源码 | 文件源码
def has_permission(self, request, view):
        if request.method in SAFE_METHODS and get_session_visitor_email(request):
            return True
        return IsAuthenticated().has_permission(request, view)