This commit is contained in:
shijing 2023-09-21 17:13:39 +08:00
commit 9bd2887580
1 changed files with 22 additions and 1 deletions

View File

@ -7,7 +7,7 @@ from django.shortcuts import render
from django.utils import timezone
from rest_framework import status
from rest_framework.decorators import action, permission_classes
from rest_framework.exceptions import PermissionDenied
from rest_framework.exceptions import PermissionDenied, ParseError
from rest_framework.mixins import CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
@ -46,6 +46,27 @@ class PolicyViewSet(OptimizationMixin, PageOrNot, CreateUpdateModelAMixin, Model
filterset_fields = ['cate', 'name']
search_fields = ['cate', 'name', 'description']
ordering = ['-id']
def can_view_top(self, user):
if user.dept.type and user.dept.type.name == '部门':
return True
elif user.dept.name in ['福建分公司', '河南分公司']:
return True
return False
def get_queryset(self):
cate = self.request.query_params.get('cate', '')
if cate:
if cate == '总部文件':
user = self.request.user
if self.can_view_top(user):
return Policy.objects.filter(cate=cate)
else:
return Policy.objects.none()
else:
raise ParseError('请提供cate查询条件')
return super().get_queryset()
class ValidationViewSet(OptimizationMixin, PageOrNot, CreateUpdateModelAMixin, ModelViewSet):
perms_map = {'get': '*', 'post': 'validation_create',
'put': 'policy_update', 'delete': 'validation_delete'}