From 3a62abf381cc512694913d63153c4f89ccac00a4 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 17 Nov 2022 15:07:23 +0800 Subject: [PATCH] perf: ticket action (#9090) Co-authored-by: feng <1304903146@qq.com> --- apps/perms/const.py | 4 ++++ apps/tickets/models/ticket/apply_asset.py | 3 +++ apps/tickets/models/ticket/general.py | 2 ++ apps/tickets/serializers/ticket/apply_asset.py | 3 +-- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/perms/const.py b/apps/perms/const.py index cecaa5e3a..8c1cdc908 100644 --- a/apps/perms/const.py +++ b/apps/perms/const.py @@ -32,3 +32,7 @@ class ActionChoices(BitChoices): def has_perm(cls, action_name, total): action_value = getattr(cls, action_name) return action_value & total == action_value + + @classmethod + def display(cls, value): + return ', '.join([c.label for c in cls if c.value & value == c.value]) diff --git a/apps/tickets/models/ticket/apply_asset.py b/apps/tickets/models/ticket/apply_asset.py index 1e46cc130..2fde56125 100644 --- a/apps/tickets/models/ticket/apply_asset.py +++ b/apps/tickets/models/ticket/apply_asset.py @@ -18,3 +18,6 @@ class ApplyAssetTicket(Ticket): apply_actions = models.IntegerField(verbose_name=_('Actions'), default=ActionChoices.all()) apply_date_start = models.DateTimeField(verbose_name=_('Date start'), null=True) apply_date_expired = models.DateTimeField(verbose_name=_('Date expired'), null=True) + + def get_apply_actions_display(self): + return ActionChoices.display(self.apply_actions) diff --git a/apps/tickets/models/ticket/general.py b/apps/tickets/models/ticket/general.py index e58ffa04a..9a2f5424d 100644 --- a/apps/tickets/models/ticket/general.py +++ b/apps/tickets/models/ticket/general.py @@ -398,6 +398,8 @@ class Ticket(StatusMixin, CommonModelMixin): value = self.rel_snapshot[name] elif isinstance(field, related.ManyToManyField): value = ', '.join(self.rel_snapshot[name]) + elif isinstance(value, list): + value = ', '.join(value) return value def get_local_snapshot(self): diff --git a/apps/tickets/serializers/ticket/apply_asset.py b/apps/tickets/serializers/ticket/apply_asset.py index 0593da3c6..9eeb43998 100644 --- a/apps/tickets/serializers/ticket/apply_asset.py +++ b/apps/tickets/serializers/ticket/apply_asset.py @@ -44,8 +44,7 @@ class ApplyAssetSerializer(BaseApplyAssetSerializer, TicketApplySerializer): attrs['type'] = 'apply_asset' attrs = super().validate(attrs) if self.is_final_approval and ( - not attrs.get('apply_nodes') - and not attrs.get('apply_assets') + not attrs.get('apply_nodes') and not attrs.get('apply_assets') ): raise serializers.ValidationError({ 'apply_nodes': asset_or_node_help_text,