mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-08-31 15:11:27 +00:00
feat: 完成剩余流程, 修改部分模型
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#
|
||||
|
||||
from rest_framework import viewsets
|
||||
|
||||
from orgs.mixins.api import OrgBulkModelViewSet
|
||||
from ..models import AdHoc
|
||||
from ..serializers import (
|
||||
AdHocSerializer
|
||||
@@ -12,6 +14,7 @@ __all__ = [
|
||||
]
|
||||
|
||||
|
||||
class AdHocViewSet(viewsets.ModelViewSet):
|
||||
queryset = AdHoc.objects.all()
|
||||
class AdHocViewSet(OrgBulkModelViewSet):
|
||||
serializer_class = AdHocSerializer
|
||||
permission_classes = ()
|
||||
model = AdHoc
|
||||
|
@@ -5,10 +5,16 @@ from ops.serializers.job import JobSerializer, JobExecutionSerializer
|
||||
|
||||
__all__ = ['JobViewSet', 'JobExecutionViewSet']
|
||||
|
||||
from ops.tasks import run_ops_job, run_ops_job_executions
|
||||
from ops.tasks import run_ops_job_execution
|
||||
from orgs.mixins.api import OrgBulkModelViewSet
|
||||
|
||||
|
||||
def set_task_to_serializer_data(serializer, task):
|
||||
data = getattr(serializer, "_data", {})
|
||||
data["task_id"] = task.id
|
||||
setattr(serializer, "_data", data)
|
||||
|
||||
|
||||
class JobViewSet(OrgBulkModelViewSet):
|
||||
serializer_class = JobSerializer
|
||||
model = Job
|
||||
@@ -23,23 +29,25 @@ class JobViewSet(OrgBulkModelViewSet):
|
||||
def perform_create(self, serializer):
|
||||
instance = serializer.save()
|
||||
if instance.instant:
|
||||
run_ops_job.delay(instance.id)
|
||||
execution = instance.create_execution()
|
||||
task = run_ops_job_execution.delay(execution.id)
|
||||
set_task_to_serializer_data(serializer, task)
|
||||
|
||||
|
||||
class JobExecutionViewSet(OrgBulkModelViewSet):
|
||||
serializer_class = JobExecutionSerializer
|
||||
http_method_names = ('get', 'post', 'head', 'options',)
|
||||
# filter_fields = ('type',)
|
||||
permission_classes = ()
|
||||
model = JobExecution
|
||||
|
||||
def perform_create(self, serializer):
|
||||
instance = serializer.save()
|
||||
run_ops_job_executions.delay(instance.id)
|
||||
task = run_ops_job_execution.delay(instance.id)
|
||||
set_task_to_serializer_data(serializer, task)
|
||||
|
||||
def get_queryset(self):
|
||||
query_set = super().get_queryset()
|
||||
job_id = self.request.query_params.get('job_id')
|
||||
if job_id:
|
||||
self.queryset = query_set.filter(job_id=job_id)
|
||||
query_set = query_set.filter(job_id=job_id)
|
||||
return query_set
|
||||
|
@@ -2,7 +2,8 @@ import os
|
||||
import zipfile
|
||||
|
||||
from django.conf import settings
|
||||
from rest_framework import viewsets
|
||||
|
||||
from orgs.mixins.api import OrgBulkModelViewSet
|
||||
from ..models import Playbook
|
||||
from ..serializers.playbook import PlaybookSerializer
|
||||
|
||||
@@ -15,9 +16,10 @@ def unzip_playbook(src, dist):
|
||||
fz.extract(file, dist)
|
||||
|
||||
|
||||
class PlaybookViewSet(viewsets.ModelViewSet):
|
||||
queryset = Playbook.objects.all()
|
||||
class PlaybookViewSet(OrgBulkModelViewSet):
|
||||
serializer_class = PlaybookSerializer
|
||||
permission_classes = ()
|
||||
model = Playbook
|
||||
|
||||
def perform_create(self, serializer):
|
||||
instance = serializer.save()
|
||||
|
Reference in New Issue
Block a user