mirror of https://github.com/jumpserver/jumpserver
parent
eae4f76e1f
commit
e84411588a
|
@ -5,6 +5,7 @@ from rest_framework import serializers
|
||||||
from common.serializers.fields import ReadableHiddenField
|
from common.serializers.fields import ReadableHiddenField
|
||||||
from ops.models import Playbook
|
from ops.models import Playbook
|
||||||
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
def parse_playbook_name(path):
|
def parse_playbook_name(path):
|
||||||
|
@ -15,13 +16,13 @@ def parse_playbook_name(path):
|
||||||
class PlaybookSerializer(BulkOrgResourceModelSerializer):
|
class PlaybookSerializer(BulkOrgResourceModelSerializer):
|
||||||
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
|
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
|
||||||
path = serializers.FileField(required=False)
|
path = serializers.FileField(required=False)
|
||||||
|
name = serializers.CharField(label=_('Name'), max_length=128, allow_blank=True, required=False)
|
||||||
|
|
||||||
def create(self, validated_data):
|
def to_internal_value(self, data):
|
||||||
name = validated_data.get('name')
|
name = data.get('name', False)
|
||||||
if not name:
|
if not name:
|
||||||
path = validated_data.get('path').name
|
data['name'] = parse_playbook_name(data['path'].name)
|
||||||
validated_data['name'] = parse_playbook_name(path)
|
return super().to_internal_value(data)
|
||||||
return super().create(validated_data)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Playbook
|
model = Playbook
|
||||||
|
|
Loading…
Reference in New Issue