mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.6 KiB
50 lines
1.6 KiB
3 years ago
|
# -*- coding: utf-8 -*-
|
||
|
#
|
||
3 years ago
|
from rest_framework import status, viewsets
|
||
3 years ago
|
from rest_framework.response import Response
|
||
|
|
||
|
from orgs.mixins.api import OrgBulkModelViewSet
|
||
|
from .. import serializers
|
||
|
from ..tasks import execute_account_backup_plan
|
||
|
from ..models import (
|
||
|
AccountBackupPlan, AccountBackupPlanExecution
|
||
|
)
|
||
|
|
||
|
__all__ = [
|
||
|
'AccountBackupPlanViewSet', 'AccountBackupPlanExecutionViewSet'
|
||
|
]
|
||
|
|
||
|
|
||
|
class AccountBackupPlanViewSet(OrgBulkModelViewSet):
|
||
|
model = AccountBackupPlan
|
||
|
filter_fields = ('name',)
|
||
|
search_fields = filter_fields
|
||
|
ordering_fields = ('name',)
|
||
|
ordering = ('name',)
|
||
|
serializer_class = serializers.AccountBackupPlanSerializer
|
||
|
|
||
|
|
||
3 years ago
|
class AccountBackupPlanExecutionViewSet(viewsets.ModelViewSet):
|
||
3 years ago
|
serializer_class = serializers.AccountBackupPlanExecutionSerializer
|
||
3 years ago
|
search_fields = ('trigger',)
|
||
|
filterset_fields = ('trigger', 'plan_id')
|
||
3 years ago
|
http_method_names = ['get', 'post', 'options']
|
||
3 years ago
|
|
||
|
def get_queryset(self):
|
||
|
queryset = AccountBackupPlanExecution.objects.all()
|
||
|
return queryset
|
||
|
|
||
|
def create(self, request, *args, **kwargs):
|
||
|
serializer = self.get_serializer(data=request.data)
|
||
|
serializer.is_valid(raise_exception=True)
|
||
|
pid = serializer.data.get('plan')
|
||
|
task = execute_account_backup_plan.delay(
|
||
|
pid=pid, trigger=AccountBackupPlanExecution.Trigger.manual
|
||
|
)
|
||
|
return Response({'task': task.id}, status=status.HTTP_201_CREATED)
|
||
|
|
||
|
def filter_queryset(self, queryset):
|
||
|
queryset = super().filter_queryset(queryset)
|
||
|
queryset = queryset.order_by('-date_start')
|
||
|
return queryset
|