feat: 克隆角色权限

pull/8342/head
Jiangjie.Bai 2022-06-06 15:51:17 +08:00 committed by Jiangjie.Bai
parent e096244e75
commit dade0cadda
1 changed files with 15 additions and 0 deletions

View File

@ -39,6 +39,21 @@ class RoleViewSet(PaginatedResponseMixin, JMSModelViewSet):
raise PermissionDenied(error)
return super().perform_destroy(instance)
def perform_create(self, serializer):
super(RoleViewSet, self).perform_create(serializer)
self.set_permissions_if_need(serializer.instance)
def set_permissions_if_need(self, instance):
if not isinstance(instance, Role):
return
clone_from = self.request.query_params.get('clone_from')
if not clone_from:
return
clone = Role.objects.filter(id=clone_from).first()
if not clone:
return
instance.permissions.set(clone.permissions.all())
def perform_update(self, serializer):
instance = serializer.instance
if instance.builtin: