當前位置: 首頁>>代碼示例>>Python>>正文


Python permissions.SAFE_METHODS屬性代碼示例

本文整理匯總了Python中rest_framework.permissions.SAFE_METHODS屬性的典型用法代碼示例。如果您正苦於以下問題:Python permissions.SAFE_METHODS屬性的具體用法?Python permissions.SAFE_METHODS怎麽用?Python permissions.SAFE_METHODS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在rest_framework.permissions的用法示例。


在下文中一共展示了permissions.SAFE_METHODS屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: configure

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def configure(self, request, pk=None):
        router = self.get_object()

        # Check if the router runs on a supported platform
        if not router.platform:
            raise ServiceUnavailable("Unsupported router platform.")

        # Check user permission first
        if not request.user.has_perm("peering.deploy_configuration_router"):
            return HttpResponseForbidden()

        # Commit changes only if not using a GET request
        error, changes = router.set_napalm_configuration(
            router.generate_configuration(), commit=(request.method not in SAFE_METHODS)
        )
        return Response({"changed": not error, "changes": changes, "error": error}) 
開發者ID:respawner,項目名稱:peering-manager,代碼行數:18,代碼來源:views.py

示例2: has_permission

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def has_permission(self, request, view):
        """Check permission based on the defined access."""
        if request.user.admin:
            return True

        if not request.user.access:
            return False

        if request.method in permissions.SAFE_METHODS:
            rates_read = request.user.access.get("rate", {}).get("read", [])
            if rates_read:
                return True
        else:
            rates_write = request.user.access.get("rate", {}).get("write", [])
            if "*" in rates_write:
                return True
            if self.get_uuid_from_url(request) in rates_write:
                return True
        return False 
開發者ID:project-koku,項目名稱:koku,代碼行數:21,代碼來源:cost_models_access.py

示例3: has_permission

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def has_permission(self, request, view):
        """Check permission to view Azure data."""
        if request.user.admin:
            return True

        resource_access = request.user.access
        if resource_access is None or not isinstance(resource_access, dict):
            return False

        res_type_access = resource_access.get(AzureAccessPermission.resource_type, {})
        if request.method in permissions.SAFE_METHODS:
            # Check permissions for read-only request
            read_access = res_type_access.get("read", [])
            return len(read_access) > 0

        return False 
開發者ID:project-koku,項目名稱:koku,代碼行數:18,代碼來源:azure_access.py

示例4: has_permission

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def has_permission(self, request, view):
        """Check permission to view AWS data."""
        if request.user.admin:
            return True

        resource_access = request.user.access
        if resource_access is None or not isinstance(resource_access, dict):
            return False

        res_type_access = resource_access.get(AwsAccessPermission.resource_type, {})
        if request.method in permissions.SAFE_METHODS:
            # Check permissions for read-only request
            read_access = res_type_access.get("read", [])
            return len(read_access) > 0

        return False 
開發者ID:project-koku,項目名稱:koku,代碼行數:18,代碼來源:aws_access.py

示例5: has_permission

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def has_permission(self, request, view):
        """Check permission to view OCP-on-ALL data."""
        if request.user.admin:
            return True

        resource_access = request.user.access
        if resource_access is None or not isinstance(resource_access, dict):
            return False

        read_access = []
        if request.method in permissions.SAFE_METHODS:
            # Check permissions for read-only request
            for resource_type in RESOURCE_TYPES:
                res_type_access = resource_access.get(resource_type, {})
                read_access.extend(res_type_access.get("read", []))
            return len(read_access) > 0

        return False 
開發者ID:project-koku,項目名稱:koku,代碼行數:20,代碼來源:openshift_all_access.py

示例6: has_object_permission

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def has_object_permission(self, request, view, obj):
        """Check permissions When an object does exist (PUT, GET)"""
        if request.user.has_perm('EDIT_FUEL_SUPPLIERS'):
            return True

        # Users can always see themselves
        if obj.id == request.user.id and \
                request.method in permissions.SAFE_METHODS:
            return True

        if request.method == 'GET' and \
                request.user.has_perm('VIEW_FUEL_SUPPLIERS'):
            return True

        if obj.id == request.user.organization.id and \
                request.user.has_perm('EDIT_FUEL_SUPPLIER'):
            return True

        # not authorized
        return False 
開發者ID:bcgov,項目名稱:tfrs,代碼行數:22,代碼來源:OrganizationPermissions.py

示例7: get_queryset

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def get_queryset(self):
        queryset = models.Activity.objects.all()
        if self.request.method not in permissions.SAFE_METHODS:
            # To check for permission
            queryset = queryset.select_related('account', 'account__owner')
        if 'expand_account' in self.request.query_params:
            queryset = queryset.select_related('account')
        if 'expand_liked_by' in self.request.query_params:
            queryset = queryset.prefetch_related(Prefetch('likes', to_attr='liked_by'))
            queryset = queryset.select_related('account', 'account__owner')
        ordering = self.request.query_params.get('ordering', '')
        if ('expand_total_likes' in self.request.query_params and 'expand_liked_by' not in self.request.query_params) or 'total_likes' in ordering:
            queryset = queryset.annotate(total_likes=Count('likes'))
        if ('expand_liked' in self.request.query_params and self.request.user.is_authenticated()
            and 'expand_liked_by' not in self.request.query_params):
            queryset = queryset.extra(select={'liked': 'SELECT COUNT(*) FROM api_activity_likes WHERE activity_id=api_activity.id AND user_id={}'.format(self.request.user.id) })
        return queryset 
開發者ID:MagiCircles,項目名稱:SchoolIdolAPI,代碼行數:19,代碼來源:views.py

示例8: has_permission

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def has_permission(self, request, view):
        """
        Return `True` if permission is granted, `False` otherwise.
        """
        return request.method in permissions.SAFE_METHODS or request.user.is_superuser 
開發者ID:deis,項目名稱:controller,代碼行數:7,代碼來源:permissions.py

示例9: has_object_permission

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def has_object_permission(self, request, view, obj):
        # Read-only permissions are allowed for any request
        if request.method in permissions.SAFE_METHODS:
            return True

        # Write permissions are only allowed to the author of a post
        return obj.author == request.user 
開發者ID:wsvincent,項目名稱:restapiswithdjango,代碼行數:9,代碼來源:permissions.py

示例10: throttle_scope

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def throttle_scope(self):
        return 'dns_api_read' if self.request.method in SAFE_METHODS else 'dns_api_write' 
開發者ID:desec-io,項目名稱:desec-stack,代碼行數:4,代碼來源:views.py

示例11: has_permission

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def has_permission(self, request, view):
        """Check permission to view and update settings data."""
        if request.user.admin:
            return True

        if request.method in permissions.SAFE_METHODS:
            return True

        return False 
開發者ID:project-koku,項目名稱:koku,代碼行數:11,代碼來源:settings_access.py

示例12: get_serializer_class

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def get_serializer_class(self):
        """Return the appropriate serializer depending on the method."""
        if self.request.method in (permissions.SAFE_METHODS, "PATCH"):
            return SourcesSerializer
        else:
            return AdminSourcesSerializer 
開發者ID:project-koku,項目名稱:koku,代碼行數:8,代碼來源:view.py

示例13: configure_router

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def configure_router(self, request, pk=None):
        internet_exchange = self.get_object()
        if not internet_exchange.router:
            raise ServiceUnavailable("No router available.")

        # Check user permission first
        if not request.user.has_perm("peering.deploy_configuration_internetexchange"):
            return HttpResponseForbidden()

        # Commit changes only if not using a GET request
        error, changes = internet_exchange.router.set_napalm_configuration(
            internet_exchange.generate_configuration(),
            commit=(request.method not in SAFE_METHODS),
        )
        return Response({"changed": not error, "changes": changes, "error": error}) 
開發者ID:respawner,項目名稱:peering-manager,代碼行數:17,代碼來源:views.py

示例14: has_permission

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def has_permission(self, request, view):
        # If token authentication is in use, verify that the token allows write
        # operations (for unsafe methods).
        if request.method not in SAFE_METHODS and isinstance(request.auth, Token):
            if not request.auth.write_enabled:
                return False
        return super().has_permission(request, view) 
開發者ID:respawner,項目名稱:peering-manager,代碼行數:9,代碼來源:api.py

示例15: has_permission

# 需要導入模塊: from rest_framework import permissions [as 別名]
# 或者: from rest_framework.permissions import SAFE_METHODS [as 別名]
def has_permission(self, request, view):
        if request.method not in SAFE_METHODS:
            return request.user.reviews.exists()
        return True 
開發者ID:adfinis-sygroup,項目名稱:timed-backend,代碼行數:6,代碼來源:permissions.py


注:本文中的rest_framework.permissions.SAFE_METHODS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。