fix: 修复 Playbook 脚本文件问题

pull/12805/head
Bai 2024-03-14 10:22:09 +08:00 committed by Bryan
parent e2d14f5e4b
commit 80035e7cb6
1 changed files with 8 additions and 4 deletions

View File

@ -79,9 +79,13 @@ class PlaybookFileBrowserAPIView(APIView):
}
protected_files = ['root', 'main.yml']
def get_playbook(self, playbook_id):
playbook = get_object_or_404(Playbook, id=playbook_id, creator=self.request.user)
return playbook
def get(self, request, **kwargs):
playbook_id = kwargs.get('pk')
playbook = get_object_or_404(Playbook, id=playbook_id)
playbook = self.get_playbook(playbook_id)
work_path = playbook.work_dir
file_key = request.query_params.get('key', '')
if file_key:
@ -101,7 +105,7 @@ class PlaybookFileBrowserAPIView(APIView):
def post(self, request, **kwargs):
playbook_id = kwargs.get('pk')
playbook = get_object_or_404(Playbook, id=playbook_id)
playbook = self.get_playbook(playbook_id)
work_path = playbook.work_dir
parent_key = request.data.get('key', '')
@ -157,7 +161,7 @@ class PlaybookFileBrowserAPIView(APIView):
def patch(self, request, **kwargs):
playbook_id = kwargs.get('pk')
playbook = get_object_or_404(Playbook, id=playbook_id)
playbook = self.get_playbook(playbook_id)
work_path = playbook.work_dir
file_key = request.data.get('key', '')
@ -197,7 +201,7 @@ class PlaybookFileBrowserAPIView(APIView):
def delete(self, request, **kwargs):
playbook_id = kwargs.get('pk')
playbook = get_object_or_404(Playbook, id=playbook_id)
playbook = self.get_playbook(playbook_id)
work_path = playbook.work_dir
file_key = request.query_params.get('key', '')
if not file_key: