mirror of https://github.com/jumpserver/jumpserver
perf: update action choice field default
parent
bc9782bd55
commit
4db15d9af7
|
@ -335,7 +335,6 @@ class DefaultValueFieldsMixin:
|
||||||
default = default()
|
default = default()
|
||||||
if default == "":
|
if default == "":
|
||||||
continue
|
continue
|
||||||
# print(f"Set default value: {name}: {default}")
|
|
||||||
serializer_field.default = default
|
serializer_field.default = default
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
from django.db.models import Q, Count
|
from django.db.models import Q, Count
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from rest_framework.fields import empty
|
||||||
|
|
||||||
from accounts.const import Source
|
from accounts.const import Source
|
||||||
from accounts.models import AccountTemplate, Account
|
from accounts.models import AccountTemplate, Account
|
||||||
|
@ -26,6 +27,16 @@ class ActionChoicesField(BitChoicesField):
|
||||||
def to_file_internal_value(self, data):
|
def to_file_internal_value(self, data):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@property
|
||||||
|
def default(self):
|
||||||
|
if self._default is empty:
|
||||||
|
return self._default
|
||||||
|
return self.to_representation(self._default)
|
||||||
|
|
||||||
|
@default.setter
|
||||||
|
def default(self, value):
|
||||||
|
self._default = value
|
||||||
|
|
||||||
|
|
||||||
class PermAccountsSerializer(serializers.ListField):
|
class PermAccountsSerializer(serializers.ListField):
|
||||||
def get_render_help_text(self):
|
def get_render_help_text(self):
|
||||||
|
@ -71,7 +82,7 @@ class AssetPermissionSerializer(ResourceLabelsMixin, BulkOrgResourceModelSeriali
|
||||||
fields = fields_mini + fields_m2m + fields_generic
|
fields = fields_mini + fields_m2m + fields_generic
|
||||||
read_only_fields = ["created_by", "date_created", "from_ticket"]
|
read_only_fields = ["created_by", "date_created", "from_ticket"]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
"actions": {"label": _("Action")},
|
"actions": {"label": _("Action"), },
|
||||||
"is_expired": {"label": _("Is expired")},
|
"is_expired": {"label": _("Is expired")},
|
||||||
"is_valid": {"label": _("Is valid")},
|
"is_valid": {"label": _("Is valid")},
|
||||||
}
|
}
|
||||||
|
@ -84,7 +95,7 @@ class AssetPermissionSerializer(ResourceLabelsMixin, BulkOrgResourceModelSeriali
|
||||||
actions = self.fields.get("actions")
|
actions = self.fields.get("actions")
|
||||||
if not actions:
|
if not actions:
|
||||||
return
|
return
|
||||||
actions.default = list(actions.choices.keys())
|
actions.default = ActionChoices.all()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all_assets(nodes, assets):
|
def get_all_assets(nodes, assets):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
class MenuPermission(models.Model):
|
class MenuPermission(models.Model):
|
||||||
|
|
|
@ -31,9 +31,9 @@ class ApplyAssetSerializer(BaseApplyAssetSerializer, TicketApplySerializer):
|
||||||
class Meta(TicketApplySerializer.Meta):
|
class Meta(TicketApplySerializer.Meta):
|
||||||
model = ApplyAssetTicket
|
model = ApplyAssetTicket
|
||||||
writeable_fields = [
|
writeable_fields = [
|
||||||
'id', 'title', 'type', 'apply_nodes', 'apply_assets', 'apply_accounts',
|
'id', 'title', 'type', 'apply_nodes', 'apply_assets',
|
||||||
'apply_actions', 'apply_date_start', 'apply_date_expired',
|
'apply_accounts', 'apply_actions', 'apply_date_start',
|
||||||
'comment', 'org_id'
|
'apply_date_expired', 'comment', 'org_id'
|
||||||
]
|
]
|
||||||
read_only_fields = TicketApplySerializer.Meta.read_only_fields + ['apply_permission_name', ]
|
read_only_fields = TicketApplySerializer.Meta.read_only_fields + ['apply_permission_name', ]
|
||||||
fields = TicketApplySerializer.Meta.fields_small + writeable_fields + read_only_fields
|
fields = TicketApplySerializer.Meta.fields_small + writeable_fields + read_only_fields
|
||||||
|
@ -45,12 +45,22 @@ class ApplyAssetSerializer(BaseApplyAssetSerializer, TicketApplySerializer):
|
||||||
}
|
}
|
||||||
extra_kwargs.update(ticket_extra_kwargs)
|
extra_kwargs.update(ticket_extra_kwargs)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
# self.set_actions_field()
|
||||||
|
|
||||||
def validate_apply_nodes(self, nodes):
|
def validate_apply_nodes(self, nodes):
|
||||||
return self.filter_many_to_many_field(Node, nodes)
|
return self.filter_many_to_many_field(Node, nodes)
|
||||||
|
|
||||||
def validate_apply_assets(self, assets):
|
def validate_apply_assets(self, assets):
|
||||||
return self.filter_many_to_many_field(Asset, assets)
|
return self.filter_many_to_many_field(Asset, assets)
|
||||||
|
|
||||||
|
def set_actions_field(self):
|
||||||
|
actions = self.fields.get("apply_actions")
|
||||||
|
if not actions:
|
||||||
|
return
|
||||||
|
actions.default = ['connect']
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
attrs['type'] = 'apply_asset'
|
attrs['type'] = 'apply_asset'
|
||||||
attrs = super().validate(attrs)
|
attrs = super().validate(attrs)
|
||||||
|
|
Loading…
Reference in New Issue