Files
jumpserver/apps/tickets/serializers/ticket/meta/apply_application.py
Jiangjie.Bai 3b056ff953 reactor&feat: 重构工单模块 & 支持申请应用工单 (#5352)
* reactor: 修改工单Model,添加工单迁移文件

* reactor: 修改工单Model,添加工单迁移文件

* reactor: 重构工单模块

* reactor: 重构工单模块2

* reactor: 重构工单模块3

* reactor: 重构工单模块4

* reactor: 重构工单模块5

* reactor: 重构工单模块6

* reactor: 重构工单模块7

* reactor: 重构工单模块8

* reactor: 重构工单模块9

* reactor: 重构工单模块10

* reactor: 重构工单模块11

* reactor: 重构工单模块12

* reactor: 重构工单模块13

* reactor: 重构工单模块14

* reactor: 重构工单模块15

* reactor: 重构工单模块16

* reactor: 重构工单模块17

* reactor: 重构工单模块18

* reactor: 重构工单模块19

* reactor: 重构工单模块20

* reactor: 重构工单模块21

* reactor: 重构工单模块22

* reactor: 重构工单模块23

* reactor: 重构工单模块24

* reactor: 重构工单模块25

* reactor: 重构工单模块26

* reactor: 重构工单模块27

* reactor: 重构工单模块28

* reactor: 重构工单模块29

* reactor: 重构工单模块30

* reactor: 重构工单模块31

* reactor: 重构工单模块32

* reactor: 重构工单模块33

* reactor: 重构工单模块34

* reactor: 重构工单模块35

* reactor: 重构工单模块36

* reactor: 重构工单模块37

* reactor: 重构工单模块38

* reactor: 重构工单模块39
2020-12-30 00:19:59 +08:00

94 lines
3.5 KiB
Python

from rest_framework import serializers
from django.utils.translation import ugettext_lazy as _
from applications.models import Category, Application
from assets.models import SystemUser
from .base import BaseTicketMetaSerializer, BaseTicketMetaApproveSerializerMixin
__all__ = [
'TicketMetaApplyApplicationApplySerializer',
'TicketMetaApplyApplicationApproveSerializer',
]
class TicketMetaApplyApplicationSerializer(BaseTicketMetaSerializer):
# 申请信息
apply_category = serializers.ChoiceField(
choices=Category.choices, required=True, label=_('Category')
)
apply_type = serializers.ChoiceField(
choices=Category.get_all_type_choices(), required=True, label=_('Type')
)
apply_application_group = serializers.ListField(
child=serializers.CharField(), default=list, label=_('Application group')
)
apply_system_user_group = serializers.ListField(
child=serializers.CharField(), default=list, label=_('System user group')
)
apply_date_start = serializers.DateTimeField(
required=True, label=_('Date start')
)
apply_date_expired = serializers.DateTimeField(
required=True, label=_('Date expired')
)
# 审批信息
approve_applications = serializers.ListField(
child=serializers.UUIDField(), required=True,
label=_('Approve applications')
)
approve_system_users = serializers.ListField(
child=serializers.UUIDField(), required=True,
label=_('Approve system users')
)
approve_date_start = serializers.DateTimeField(
required=True, label=_('Date start')
)
approve_date_expired = serializers.DateTimeField(
required=True, label=_('Date expired')
)
class TicketMetaApplyApplicationApplySerializer(TicketMetaApplyApplicationSerializer):
class Meta:
fields = [
'apply_category', 'apply_type',
'apply_application_group', 'apply_system_user_group',
'apply_date_start', 'apply_date_expired'
]
def validate_apply_type(self, tp):
category = self.root.initial_data['meta'].get('apply_category')
if not category:
return tp
valid_type_types = list((dict(Category.get_type_choices(category)).keys()))
if tp in valid_type_types:
return tp
error = _('Type `{}` is not a valid choice `({}){}`'.format(tp, category, valid_type_types))
raise serializers.ValidationError(error)
class TicketMetaApplyApplicationApproveSerializer(BaseTicketMetaApproveSerializerMixin,
TicketMetaApplyApplicationSerializer):
class Meta:
fields = {
'approve_applications', 'approve_system_users',
'approve_date_start', 'approve_date_expired'
}
def validate_approve_applications(self, approve_applications):
application_type = self.root.instance.meta['apply_type']
queries = {'type': application_type}
applications_id = self.filter_approve_resources(
resource_model=Application, resources_id=approve_applications, queries=queries
)
return applications_id
def validate_approve_system_users(self, approve_system_users):
application_type = self.root.instance.meta['apply_type']
protocol = SystemUser.get_protocol_by_application_type(application_type)
queries = {'protocol': protocol}
system_users_id = self.filter_approve_system_users(approve_system_users, queries)
return system_users_id