mirror of https://github.com/jumpserver/jumpserver
feat: 克隆角色权限
parent
e096244e75
commit
dade0cadda
|
@ -39,6 +39,21 @@ class RoleViewSet(PaginatedResponseMixin, JMSModelViewSet):
|
||||||
raise PermissionDenied(error)
|
raise PermissionDenied(error)
|
||||||
return super().perform_destroy(instance)
|
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):
|
def perform_update(self, serializer):
|
||||||
instance = serializer.instance
|
instance = serializer.instance
|
||||||
if instance.builtin:
|
if instance.builtin:
|
||||||
|
|
Loading…
Reference in New Issue