mirror of https://github.com/jumpserver/jumpserver
feat: 增加作业审计api
parent
bc47afb329
commit
009669febe
|
@ -13,19 +13,25 @@ from common.drf.api import JMSReadOnlyModelViewSet
|
|||
from common.plugins.es import QuerySet as ESQuerySet
|
||||
from common.drf.filters import DatetimeRangeFilter
|
||||
from common.api import CommonGenericViewSet
|
||||
from orgs.mixins.api import OrgGenericViewSet, OrgBulkModelViewSet, OrgRelationMixin
|
||||
from ops.models.job import JobAuditLog
|
||||
from orgs.mixins.api import OrgGenericViewSet, OrgBulkModelViewSet
|
||||
from orgs.utils import current_org
|
||||
# from ops.models import CommandExecution
|
||||
from . import filters
|
||||
from .backends import TYPE_ENGINE_MAPPING
|
||||
from .models import FTPLog, UserLoginLog, OperateLog, PasswordChangeLog
|
||||
from .serializers import FTPLogSerializer, UserLoginLogSerializer
|
||||
from .serializers import FTPLogSerializer, UserLoginLogSerializer, JobAuditLogSerializer
|
||||
from .serializers import (
|
||||
OperateLogSerializer, OperateLogActionDetailSerializer,
|
||||
PasswordChangeLogSerializer
|
||||
)
|
||||
|
||||
|
||||
class JobAuditViewSet(OrgBulkModelViewSet):
|
||||
serializer_class = JobAuditLogSerializer
|
||||
http_method_names = ('get', 'head', 'options',)
|
||||
permission_classes = ()
|
||||
model = JobAuditLog
|
||||
|
||||
|
||||
class FTPLogViewSet(CreateModelMixin, ListModelMixin, OrgGenericViewSet):
|
||||
model = FTPLog
|
||||
serializer_class = FTPLogSerializer
|
||||
|
|
|
@ -4,6 +4,8 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from rest_framework import serializers
|
||||
|
||||
from common.drf.fields import LabeledChoiceField
|
||||
from ops.models.job import JobAuditLog
|
||||
from ops.serializers.job import JobExecutionSerializer
|
||||
from terminal.models import Session
|
||||
from . import models
|
||||
from .const import (
|
||||
|
@ -15,6 +17,17 @@ from .const import (
|
|||
)
|
||||
|
||||
|
||||
class JobAuditLogSerializer(JobExecutionSerializer):
|
||||
class Meta:
|
||||
model = JobAuditLog
|
||||
read_only_fields = ["timedelta", "time_cost", 'is_finished', 'date_start',
|
||||
'date_finished',
|
||||
'date_created',
|
||||
'is_success',
|
||||
'creator_name']
|
||||
fields = read_only_fields + []
|
||||
|
||||
|
||||
class FTPLogSerializer(serializers.ModelSerializer):
|
||||
operate = LabeledChoiceField(choices=OperateChoices.choices, label=_("Operate"))
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ from rest_framework.routers import DefaultRouter
|
|||
from common import api as capi
|
||||
from .. import api
|
||||
|
||||
|
||||
app_name = "audits"
|
||||
|
||||
router = DefaultRouter()
|
||||
|
@ -15,9 +14,7 @@ router.register(r'ftp-logs', api.FTPLogViewSet, 'ftp-log')
|
|||
router.register(r'login-logs', api.UserLoginLogViewSet, 'login-log')
|
||||
router.register(r'operate-logs', api.OperateLogViewSet, 'operate-log')
|
||||
router.register(r'password-change-logs', api.PasswordChangeLogViewSet, 'password-change-log')
|
||||
# router.register(r'command-execution-logs', api.CommandExecutionViewSet, 'command-execution-log')
|
||||
# router.register(r'command-executions-hosts-relations', api.CommandExecutionHostRelationViewSet, 'command-executions-hosts-relation')
|
||||
|
||||
router.register(r'job-logs', api.JobAuditViewSet, 'job-log')
|
||||
|
||||
urlpatterns = [
|
||||
path('my-login-logs/', api.MyLoginLogAPIView.as_view(), name='my-login-log'),
|
||||
|
|
|
@ -3,9 +3,10 @@ from django.shortcuts import get_object_or_404
|
|||
from rest_framework.response import Response
|
||||
|
||||
from ops.models import Job, JobExecution
|
||||
from ops.models.job import JobAuditLog
|
||||
from ops.serializers.job import JobSerializer, JobExecutionSerializer
|
||||
|
||||
__all__ = ['JobViewSet', 'JobExecutionViewSet', 'JobRunVariableHelpAPIView', 'JobAssetDetail']
|
||||
__all__ = ['JobViewSet', 'JobExecutionViewSet', 'JobRunVariableHelpAPIView', 'JobAssetDetail', ]
|
||||
|
||||
from ops.tasks import run_ops_job_execution
|
||||
from ops.variables import JMS_JOB_VARIABLE_HELP
|
||||
|
|
|
@ -9,7 +9,7 @@ from django.utils.translation import gettext_lazy as _
|
|||
from django.utils import timezone
|
||||
from celery import current_task
|
||||
|
||||
__all__ = ["Job", "JobExecution"]
|
||||
__all__ = ["Job", "JobExecution", "JobAuditLog"]
|
||||
|
||||
from ops.ansible import JMSInventory, AdHocRunner, PlaybookRunner
|
||||
from ops.mixin import PeriodTaskModelMixin
|
||||
|
@ -286,3 +286,12 @@ class JobExecution(JMSOrgBaseModel):
|
|||
|
||||
class Meta:
|
||||
ordering = ['-date_created']
|
||||
|
||||
|
||||
class JobAuditLog(JobExecution):
|
||||
@property
|
||||
def creator_name(self):
|
||||
return self.creator.name
|
||||
|
||||
class Meta:
|
||||
proxy = True
|
||||
|
|
|
@ -3,6 +3,7 @@ from rest_framework import serializers
|
|||
from common.drf.fields import ReadableHiddenField
|
||||
from ops.mixin import PeriodTaskSerializerMixin
|
||||
from ops.models import Job, JobExecution
|
||||
from ops.models.job import JobAuditLog
|
||||
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
||||
|
||||
|
||||
|
@ -40,3 +41,6 @@ class JobExecutionSerializer(BulkOrgResourceModelSerializer):
|
|||
fields = read_only_fields + [
|
||||
"job", "parameters"
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue