perf: 修改授权的账号

pull/13378/head
ibuler 2024-06-05 19:33:40 +08:00
parent 263bcbb566
commit 3468f8cd40
3 changed files with 25 additions and 4 deletions

View File

@ -226,7 +226,7 @@
"ChangeSecretParams": "Change secret parameters",
"ChangeViewHelpText": "Click to switch different views",
"Chat": "Chat",
"ChatHello": "Hello! Can i help you?",
"ChatHello": "Hello, can I help you?",
"ChatAI": "Chat AI",
"ChdirHelpText": "By default, the execution directory is the user's home directory",
"CheckAssetsAmount": "Check asset quantity",

View File

@ -105,6 +105,22 @@ class AssetPermission(LabeledMixin, JMSOrgBaseModel):
return True
return False
@property
def real_accounts(self):
return [a for a in self.accounts if not a.startswith('@') or a == '@ALL']
@real_accounts.setter
def real_accounts(self, value):
self.accounts += value
@property
def virtual_accounts(self):
return [a for a in self.accounts if a.startswith('@') and a != '@ALL']
@virtual_accounts.setter
def virtual_accounts(self, value):
self.accounts += value
@lazyproperty
def users_amount(self):
return self.users.count()

View File

@ -43,6 +43,8 @@ class AssetPermissionSerializer(ResourceLabelsMixin, BulkOrgResourceModelSeriali
is_valid = serializers.BooleanField(read_only=True, label=_("Is valid"))
is_expired = serializers.BooleanField(read_only=True, label=_("Is expired"))
accounts = serializers.ListField(label=_("Accounts"), required=False)
real_accounts = serializers.ListField(label=_("General accounts"), required=False)
virtual_accounts = serializers.ListField(label=_("Virtual accounts"), required=False)
protocols = serializers.ListField(label=_("Protocols"), required=False)
template_accounts = AccountTemplate.objects.none()
@ -52,9 +54,9 @@ class AssetPermissionSerializer(ResourceLabelsMixin, BulkOrgResourceModelSeriali
fields_mini = ["id", "name"]
amount_fields = ["users_amount", "user_groups_amount", "assets_amount", "nodes_amount"]
fields_generic = [
"accounts", "protocols", "actions", "created_by", "date_created",
"date_start", "date_expired", "is_active", "is_expired",
"is_valid", "comment", "from_ticket",
"accounts", "real_accounts", "virtual_accounts", "protocols", "actions",
"created_by", "date_created", "date_start", "date_expired", "is_active",
"is_expired", "is_valid", "comment", "from_ticket",
]
fields_small = fields_mini + fields_generic
fields_m2m = ["users", "user_groups", "assets", "nodes", "labels"] + amount_fields
@ -135,6 +137,9 @@ class AssetPermissionSerializer(ResourceLabelsMixin, BulkOrgResourceModelSeriali
template_usernames = list(self.template_accounts.values_list('username', flat=True))
return list(set(account_usernames + template_usernames))
def validate_real_accounts(self, usernames):
return self.validate_accounts(usernames)
@classmethod
def setup_eager_loading(cls, queryset):
"""Perform necessary eager loading of data."""