当前位置: 首页>>代码示例>>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;未经允许,请勿转载。