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.
43 lines
1.4 KiB
43 lines
1.4 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
|
||
|
|
||
2 years ago
|
from accounts import serializers
|
||
|
from accounts.models import (
|
||
|
AccountBackupAutomation, AccountBackupExecution
|
||
3 years ago
|
)
|
||
2 years ago
|
from accounts.tasks import execute_account_backup_task
|
||
2 years ago
|
from common.const.choices import Trigger
|
||
|
from orgs.mixins.api import OrgBulkModelViewSet
|
||
3 years ago
|
|
||
|
__all__ = [
|
||
|
'AccountBackupPlanViewSet', 'AccountBackupPlanExecutionViewSet'
|
||
|
]
|
||
|
|
||
|
|
||
|
class AccountBackupPlanViewSet(OrgBulkModelViewSet):
|
||
2 years ago
|
model = AccountBackupAutomation
|
||
3 years ago
|
filter_fields = ('name',)
|
||
|
search_fields = filter_fields
|
||
|
ordering = ('name',)
|
||
2 years ago
|
serializer_class = serializers.AccountBackupSerializer
|
||
3 years ago
|
|
||
|
|
||
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):
|
||
2 years ago
|
queryset = AccountBackupExecution.objects.all()
|
||
3 years ago
|
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')
|
||
2 years ago
|
task = execute_account_backup_task.delay(pid=str(pid), trigger=Trigger.manual)
|
||
3 years ago
|
return Response({'task': task.id}, status=status.HTTP_201_CREATED)
|