mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-08-31 23:20:37 +00:00
feat: 修改作业权限
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from .base import SelfBulkModelViewSet
|
||||
from orgs.mixins.api import OrgBulkModelViewSet
|
||||
from ..models import AdHoc
|
||||
from ..serializers import (
|
||||
AdHocSerializer
|
||||
@@ -10,7 +10,11 @@ __all__ = [
|
||||
]
|
||||
|
||||
|
||||
class AdHocViewSet(SelfBulkModelViewSet):
|
||||
class AdHocViewSet(OrgBulkModelViewSet):
|
||||
serializer_class = AdHocSerializer
|
||||
permission_classes = ()
|
||||
model = AdHoc
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
return queryset.filter(creator=self.request.user)
|
||||
|
@@ -1,17 +0,0 @@
|
||||
from rest_framework_bulk import BulkModelViewSet
|
||||
|
||||
from common.mixins import CommonApiMixin
|
||||
|
||||
__all__ = ['SelfBulkModelViewSet']
|
||||
|
||||
|
||||
class SelfBulkModelViewSet(CommonApiMixin, BulkModelViewSet):
|
||||
|
||||
def get_queryset(self):
|
||||
if hasattr(self, 'model'):
|
||||
return self.model.objects.filter(creator=self.request.user)
|
||||
else:
|
||||
assert self.queryset is None, (
|
||||
"'%s' should not include a `queryset` attribute"
|
||||
% self.__class__.__name__
|
||||
)
|
@@ -2,7 +2,6 @@ from rest_framework.views import APIView
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework.response import Response
|
||||
|
||||
from ops.api.base import SelfBulkModelViewSet
|
||||
from ops.models import Job, JobExecution
|
||||
from ops.serializers.job import JobSerializer, JobExecutionSerializer
|
||||
|
||||
@@ -10,6 +9,7 @@ __all__ = ['JobViewSet', 'JobExecutionViewSet', 'JobRunVariableHelpAPIView', 'Jo
|
||||
|
||||
from ops.tasks import run_ops_job_execution
|
||||
from ops.variables import JMS_JOB_VARIABLE_HELP
|
||||
from orgs.mixins.api import OrgBulkModelViewSet
|
||||
|
||||
|
||||
def set_task_to_serializer_data(serializer, task):
|
||||
@@ -18,16 +18,17 @@ def set_task_to_serializer_data(serializer, task):
|
||||
setattr(serializer, "_data", data)
|
||||
|
||||
|
||||
class JobViewSet(SelfBulkModelViewSet):
|
||||
class JobViewSet(OrgBulkModelViewSet):
|
||||
serializer_class = JobSerializer
|
||||
permission_classes = ()
|
||||
model = Job
|
||||
|
||||
def get_queryset(self):
|
||||
query_set = super().get_queryset()
|
||||
queryset = super().get_queryset()
|
||||
queryset = queryset.filter(creator=self.request.user)
|
||||
if self.action != 'retrieve':
|
||||
return query_set.filter(instant=False)
|
||||
return query_set
|
||||
return queryset.filter(instant=False)
|
||||
return queryset
|
||||
|
||||
def perform_create(self, serializer):
|
||||
instance = serializer.save()
|
||||
@@ -48,7 +49,7 @@ class JobViewSet(SelfBulkModelViewSet):
|
||||
set_task_to_serializer_data(serializer, task)
|
||||
|
||||
|
||||
class JobExecutionViewSet(SelfBulkModelViewSet):
|
||||
class JobExecutionViewSet(OrgBulkModelViewSet):
|
||||
serializer_class = JobExecutionSerializer
|
||||
http_method_names = ('get', 'post', 'head', 'options',)
|
||||
permission_classes = ()
|
||||
@@ -60,11 +61,12 @@ class JobExecutionViewSet(SelfBulkModelViewSet):
|
||||
set_task_to_serializer_data(serializer, task)
|
||||
|
||||
def get_queryset(self):
|
||||
query_set = super().get_queryset()
|
||||
queryset = super().get_queryset()
|
||||
queryset = queryset.filter(creator=self.request.user)
|
||||
job_id = self.request.query_params.get('job_id')
|
||||
if job_id:
|
||||
query_set = query_set.filter(job_id=job_id)
|
||||
return query_set
|
||||
queryset = queryset.filter(job_id=job_id)
|
||||
return queryset
|
||||
|
||||
|
||||
class JobRunVariableHelpAPIView(APIView):
|
||||
|
@@ -2,11 +2,7 @@ import os
|
||||
import zipfile
|
||||
|
||||
from django.conf import settings
|
||||
from rest_framework_bulk import BulkModelViewSet
|
||||
|
||||
from common.mixins import CommonApiMixin
|
||||
from orgs.mixins.api import OrgBulkModelViewSet
|
||||
from .base import SelfBulkModelViewSet
|
||||
from ..exception import PlaybookNoValidEntry
|
||||
from ..models import Playbook
|
||||
from ..serializers.playbook import PlaybookSerializer
|
||||
@@ -20,11 +16,16 @@ def unzip_playbook(src, dist):
|
||||
fz.extract(file, dist)
|
||||
|
||||
|
||||
class PlaybookViewSet(SelfBulkModelViewSet):
|
||||
class PlaybookViewSet(OrgBulkModelViewSet):
|
||||
serializer_class = PlaybookSerializer
|
||||
permission_classes = ()
|
||||
model = Playbook
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
queryset = queryset.filter(creator=self.request.user)
|
||||
return queryset
|
||||
|
||||
def perform_create(self, serializer):
|
||||
instance = serializer.save()
|
||||
src_path = os.path.join(settings.MEDIA_ROOT, instance.path.name)
|
||||
|
Reference in New Issue
Block a user