权限标识设置

This commit is contained in:
曹前明 2022-08-25 11:38:14 +08:00
parent c57c426daa
commit 2f06d9931a
5 changed files with 12 additions and 6 deletions

View File

@ -25,6 +25,7 @@ class OplCateViewSet(CustomModelViewSet):
class OperationViewSet(CustomModelViewSet):
perms_map = {'get': 'operation.view', 'post': 'operation.create', 'put': 'operation.update', 'delete': 'operation.delete'}
queryset = Operation.objects.all()
create_serializer_class = OperationCreateUpdateSerializer
update_serializer_class = OperationCreateUpdateSerializer

View File

@ -24,7 +24,7 @@ class Rparty(CommonBModel):
admin = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
class Rfile(BaseModel):
class Rfile(CommonBDModel):
"""
相关方文件库
"""
@ -81,7 +81,7 @@ class Rpjfile(BaseModel):
rpj = models.ForeignKey(Rpj, verbose_name='关联相关方项目', on_delete=models.CASCADE)
class Remployee(CommonAModel):
class Remployee(CommonBModel):
"""
相关方成员
"""
@ -96,7 +96,7 @@ class Remployee(CommonAModel):
null=True, blank=True)
class Rcertificate(CommonAModel):
class Rcertificate(CommonBModel):
"""
相关方证书
"""

View File

@ -113,6 +113,7 @@ def rpj_audit_end(ticket):
rf = Rfile()
rf.rparty = i.rpj.rparty
rf.file_cate = i.file_cate
rf.belong_dept = i.rpj.rparty.dept
rf.save()
for m in i.files.all():
rf.files.add(m)

View File

@ -20,6 +20,7 @@ from rest_framework.exceptions import ParseError
# Create your views here.
class RpartyViewSet(CustomModelViewSet):
perms_map = {'get': 'rparty.view', 'post': 'rparty.create', 'put': 'rparty.update', 'delete': 'rparty.delete'}
queryset = Rparty.objects.all()
create_serializer_class = RpartyCreateUpdateSerializer
update_serializer_class = RpartyCreateUpdateSerializer
@ -68,7 +69,7 @@ class RpartyViewSet(CustomModelViewSet):
class RfileViewSet(ListModelMixin, CustomGenericViewSet):
perms_map = {'get': '*'}
perms_map = {'get': 'rfile.view'}
queryset = Rfile.objects.all()
list_serializer_class = RfileListSerializer
filterset_fields = ['file_cate']
@ -83,6 +84,7 @@ class RfileViewSet(ListModelMixin, CustomGenericViewSet):
class RemployeeViewSet(CustomModelViewSet):
perms_map = {'get': 'remployee.view', 'post': 'remployee.create', 'put': 'remployee.update', 'delete': 'remployee.update'}
queryset = Remployee.objects.all()
create_serializer_class = RemployeeCreateSerializer
update_serializer_class = RemployeeUpdateSerializer
@ -118,6 +120,7 @@ class RemployeeViewSet(CustomModelViewSet):
class RcertificateViewSet(CustomModelViewSet):
perms_map = {'get': 'rcetificate.view', 'post': 'rcetificate.create', 'put': 'rcetificate.update', 'delete': 'rcetificate.update'}
queryset = Rcertificate.objects.all()
create_serializer_class = RcertificateCreateUpdateSerializer
update_serializer_class = RcertificateCreateUpdateSerializer
@ -132,6 +135,7 @@ class RcertificateViewSet(CustomModelViewSet):
class RpjViewSet(CustomModelViewSet):
perms_map = {'get': 'rpj.view', 'post': 'rpj.create', 'put': 'rpj.update', 'delete': 'rpj.update'}
queryset = Rpj.objects.all()
create_serializer_class = RpjCreateUpdateSerializer
update_serializer_class = RpjCreateUpdateSerializer

View File

@ -30,13 +30,13 @@ class VisitViewSet(CustomModelViewSet):
def get_queryset(self):
user = self.request.user
queryset = super().get_queryset()
if user.type == 'visitor':
if hasattr(user, 'type') and user.type == 'visitor':
queryset = queryset.filter(create_by=user)
return queryset
def create(self, request, *args, **kwargs):
user = self.request.user
if user.type == 'visitor' and user.employee.photo is None:
if hasattr(user, 'type') and user.type == 'visitor' and user.employee.photo is None:
raise ParseError('请先完善个人信息')
return super().create(request, *args, **kwargs)