perf: ticket optimization (#9094)

Co-authored-by: feng <1304903146@qq.com>
pull/9098/head
fit2bot 2022-11-17 17:34:52 +08:00 committed by GitHub
parent 30f37d9ebf
commit 71122312cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 13 deletions

View File

@ -35,4 +35,4 @@ class ActionChoices(BitChoices):
@classmethod
def display(cls, value):
return ', '.join([c.label for c in cls if c.value & value == c.value])
return ', '.join([str(c.label) for c in cls if c.value & value == c.value])

View File

@ -97,6 +97,10 @@ class ApplyAssetTicketViewSet(TicketViewSet):
serializer_class = serializers.ApplyAssetSerializer
model = ApplyAssetTicket
filterset_class = filters.ApplyAssetTicketFilter
serializer_classes = {
'open': serializers.ApplyAssetSerializer,
'approve': serializers.ApproveAssetSerializer
}
class ApplyLoginTicketViewSet(TicketViewSet):

View File

@ -9,7 +9,7 @@ from tickets.models import ApplyAssetTicket
from .common import BaseApplyAssetSerializer
from .ticket import TicketApplySerializer
__all__ = ['ApplyAssetSerializer']
__all__ = ['ApplyAssetSerializer', 'ApproveAssetSerializer']
asset_or_node_help_text = _("Select at least one asset or node")
@ -57,3 +57,9 @@ class ApplyAssetSerializer(BaseApplyAssetSerializer, TicketApplySerializer):
def setup_eager_loading(cls, queryset):
queryset = queryset.prefetch_related('apply_nodes', 'apply_assets')
return queryset
class ApproveAssetSerializer(ApplyAssetSerializer):
class Meta(ApplyAssetSerializer.Meta):
read_only_fields = TicketApplySerializer.Meta.fields_small + \
ApplyAssetSerializer.Meta.read_only_fields

View File

@ -9,8 +9,8 @@ __all__ = [
class ApplyCommandConfirmSerializer(TicketApplySerializer):
class Meta:
model = ApplyCommandTicket
fields = TicketApplySerializer.Meta.fields + [
'apply_run_user', 'apply_run_asset', 'apply_run_account',
'apply_run_command', 'apply_from_session', 'apply_from_cmd_filter',
'apply_from_cmd_filter_rule'
writeable_fields = [
'apply_run_user', 'apply_run_asset', 'apply_run_account', 'apply_run_command',
'apply_from_session', 'apply_from_cmd_filter', 'apply_from_cmd_filter_rule'
]
fields = TicketApplySerializer.Meta.fields + writeable_fields

View File

@ -9,6 +9,5 @@ __all__ = [
class LoginAssetConfirmSerializer(TicketApplySerializer):
class Meta:
model = ApplyLoginAssetTicket
fields = TicketApplySerializer.Meta.fields + [
'apply_login_user', 'apply_login_asset', 'apply_login_account'
]
writeable_fields = ['apply_login_user', 'apply_login_asset', 'apply_login_account']
fields = TicketApplySerializer.Meta.fields + writeable_fields

View File

@ -7,8 +7,7 @@ __all__ = [
class LoginConfirmSerializer(TicketApplySerializer):
class Meta:
class Meta(TicketApplySerializer.Meta):
model = ApplyLoginTicket
fields = TicketApplySerializer.Meta.fields + [
'apply_login_ip', 'apply_login_city', 'apply_login_datetime'
]
writeable_fields = ['apply_login_ip', 'apply_login_city', 'apply_login_datetime']
fields = TicketApplySerializer.Meta.fields + writeable_fields