mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-08-31 15:11:27 +00:00
perf: 优化 playbook 删除策略,正在被 job 使用时无法被删除
This commit is contained in:
@@ -32,6 +32,15 @@ class PlaybookViewSet(OrgBulkModelViewSet):
|
||||
model = Playbook
|
||||
search_fields = ('name', 'comment')
|
||||
|
||||
def perform_destroy(self, instance):
|
||||
instance = self.get_object()
|
||||
if instance.job_set.exists():
|
||||
raise JMSException(code='playbook_has_job', detail={"msg": _("Currently playbook is being used in a job")})
|
||||
instance_id = instance.id
|
||||
super().perform_destroy(instance)
|
||||
dest_path = os.path.join(settings.DATA_DIR, "ops", "playbook", instance_id.__str__())
|
||||
shutil.rmtree(dest_path)
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
queryset = queryset.filter(creator=self.request.user)
|
||||
|
Reference in New Issue
Block a user