Browse Source

perf: 修改 org name

pull/13244/head
ibuler 6 months ago
parent
commit
9f103a88d6
  1. 30
      apps/common/signal_handlers.py
  2. 22
      apps/i18n/lina/en.json
  3. 2
      apps/i18n/lina/zh.json
  4. 6
      apps/orgs/migrations/0001_initial.py
  5. 21
      apps/users/serializers/user.py

30
apps/common/signal_handlers.py

@ -63,21 +63,21 @@ def digest_sql_query():
path = current_request.get_full_path()
print(">>>. [{}] {}".format(method, path))
for table_name, queries in table_queries.items():
if table_name.startswith('rbac_') or table_name.startswith('auth_permission'):
continue
for query in queries:
sql = query['sql']
print(" # {}: {}".format(query['time'], sql[:1000]))
if len(queries) < 3:
continue
print("- Table: {}".format(table_name))
for i, query in enumerate(queries, 1):
sql = query['sql']
if not sql or not sql.startswith('SELECT'):
continue
print('\t{}.[{}s] {}'.format(i, round(float(query['time']), 2), sql[:1000]))
# for table_name, queries in table_queries.items():
# if table_name.startswith('rbac_') or table_name.startswith('auth_permission'):
# continue
#
# for query in queries:
# sql = query['sql']
# print(" # {}: {}".format(query['time'], sql[:1000]))
# if len(queries) < 3:
# continue
# print("- Table: {}".format(table_name))
# for i, query in enumerate(queries, 1):
# sql = query['sql']
# if not sql or not sql.startswith('SELECT'):
# continue
# print('\t{}.[{}s] {}'.format(i, round(float(query['time']), 2), sql[:1000]))
# logger.debug(">>> [{}] {}".format(method, path))
for name, counter in counters:

22
apps/i18n/lina/en.json

@ -317,7 +317,7 @@
"CreateNode": "Create node",
"CreatePlaybook": "Create playbook",
"CreateReplayStorage": "Create object storage",
"CreateSuccessMsg": "Import successful, total: {count}",
"CreateSuccessMsg": "Successfully created !",
"CreateUserSetting": "User creation",
"Created": "Created",
"CreatedBy": "Creator",
@ -377,8 +377,9 @@
"DeleteOrgTitle": "Please ensure the following information within the organization has been deleted",
"DeleteReleasedAssets": "Delete released assets",
"DeleteSelected": "Delete selected",
"DeleteSuccess": "Delete successfully",
"DeleteSuccessMsg": "Delete successful",
"DeleteSuccess": "Successfully deleted",
"DeleteSuccessMsg": "Successfully deleted",
"ActivateSuccessMsg": "Successful activated",
"DeleteWarningMsg": "Are you sure you want to delete",
"Deploy": "Deployment",
"Description": "Description",
@ -412,7 +413,7 @@
"Empty": "Empty",
"Enable": "Enable",
"EnableKoKoSSHHelpText": "When switched on, connecting to the asset will display ssh client pull-up method",
"Endpoint": "Service endpoint",
"Endpoint": "Service endpoints",
"EndpointListHelpMessage": "The service endpoint is the address (port) for users to access the service. when users connect to assets, they choose service endpoints based on endpoint rules and asset labels, using them as access points to establish connections and achieve distributed connections to assets",
"EndpointRule": "Endpoint rules",
"EndpointRuleListHelpMessage": "For the server endpoint selection strategy, there are currently two options:<br>1、specify the endpoint according to the endpoint rule (current page);<br>2、choose the endpoint through asset labels, with the fixed label name being 'endpoint' and the value being the name of the endpoint.<br>the tag matching method is preferred for both methods, as the ip range may conflict, and the tag method exists as a supplement to the rules.",
@ -552,6 +553,11 @@
"InputEmailAddress": "Please enter the correct email address",
"InputMessage": "Enter message...",
"InputPhone": "Phone number",
"MIN_LENGTH_ERROR": "Passwords must be at least {0} characters.",
"UPPER_CASE_REQUIRED": "Must contain uppercase letters",
"LOWER_CASE_REQUIRED": "Must contain lowercase letters",
"NUMBER_REQUIRED": "Must contain numbers",
"SPECIAL_CHAR_REQUIRED": "Must contain special characters",
"InstanceAddress": "Instance address",
"InstanceName": "Instance name",
"InstancePlatformName": "Instance platform name",
@ -721,7 +727,7 @@
"ObjectNotFoundOrDeletedMsg": "No corresponding resources found or it has been deleted.",
"Offline": "Offline",
"OfflineSelected": "Offline selected",
"OfflineSuccessMsg": "Offline successfully",
"OfflineSuccessMsg": "Successfully offline",
"OfflineUpload": "Offline upload",
"OldPassword": "Old password",
"OldSSHKey": "Old ssh public key",
@ -957,7 +963,7 @@
"Saturday": "Sat",
"Save": "Save",
"SaveAdhoc": "Save command",
"SaveAndAddAnother": "Save & continue",
"SaveAndAddAnother": "Save & Continue",
"SaveCommand": "Save command",
"SaveCommandSuccess": "Command saved successfully",
"SaveSetting": "Synchronization settings",
@ -1199,7 +1205,7 @@
"UpdateSSHKey": "Change ssh public key",
"NewSSHKey": "New SSH Key",
"UpdateSelected": "Update selected",
"UpdateSuccessMsg": "Update successful",
"UpdateSuccessMsg": "Successfully updated !",
"Updated": "Updated",
"Upload": "Upload",
"UploadCsvLth10MHelpText": "Only csv/xlsx can be uploaded, and no more than 10m",
@ -1213,7 +1219,7 @@
"UseProtocol": "User agreement",
"UseSSL": "Use ssl/tls",
"User": "User",
"UserAclLists": "Login acls",
"UserAclLists": "Login ACLs",
"UserAssetActivity": "User/asset activity",
"UserCreate": "Create user",
"UserData": "User",

2
apps/i18n/lina/zh.json

@ -367,6 +367,7 @@
"Download": "下载",
"DownloadCenter": "下载中心",
"DownloadFTPFileTip": "当前动作不记录文件,或者文件大小超过阈值(默认100M),或者还未保存到对应存储中",
"MinLengthError": "密码最少有 {0} 位",
"DownloadImportTemplateMsg": "下载创建模板",
"DownloadReplay": "下载录像",
"DownloadUpdateTemplateMsg": "下载更新模板",
@ -1228,5 +1229,4 @@
"AccessKeys": "访问密钥",
"InformationModification": "信息更改",
"Phone": "手机"
}

6
apps/orgs/migrations/0001_initial.py

@ -9,7 +9,7 @@ default_id = '00000000-0000-0000-0000-000000000002'
def add_default_org(apps, schema_editor):
org_cls = apps.get_model('orgs', 'Organization')
defaults = {'name': 'Default', 'id': default_id}
defaults = {'name': 'DEFAULT', 'id': default_id, 'builtin': True}
org_cls.objects.get_or_create(defaults=defaults, id=default_id)
@ -20,10 +20,6 @@ def update_builtin_org(apps, schema_editor):
name='SYSTEM', builtin=True
)
# 更新 Default
org_model.objects.filter(name='DEFAULT').update(builtin=True)
class Migration(migrations.Migration):

21
apps/users/serializers/user.py

@ -3,7 +3,6 @@
from functools import partial
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
@ -42,12 +41,15 @@ def default_org_roles():
class RolesSerializerMixin(serializers.Serializer):
system_roles = ObjectRelatedField(
queryset=Role.system_roles, attrs=('id', 'display_name'),
label=_("System roles"), many=True, default=default_system_roles
label=_("System roles"), many=True, default=default_system_roles,
help_text=_("System roles are roles at the system level, and they will take effect across all organizations")
)
org_roles = ObjectRelatedField(
queryset=Role.org_roles, attrs=('id', 'display_name', 'name'),
label=_("Org roles"), many=True, required=False,
default=default_org_roles
default=default_org_roles,
help_text=_(
"Org roles are roles at the organization level, and they will only take effect within current organization")
)
orgs_roles = serializers.JSONField(read_only=True, label=_("Organizations and roles"))
@ -189,6 +191,10 @@ class UserSerializer(RolesSerializerMixin, ResourceLabelsMixin, CommonBulkModelS
'mfa_level': {'label': _("MFA level")},
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.update_source_choices()
def get_fields(self):
fields = super().get_fields()
self.pop_fields_if_need(fields)
@ -200,6 +206,15 @@ class UserSerializer(RolesSerializerMixin, ResourceLabelsMixin, CommonBulkModelS
for f in self.Meta.fields_only_root_org:
fields.pop(f, None)
def update_source_choices(self):
source = self.fields.get("source")
if not source:
return
open_source = ['local', 'ldap', 'cas']
# if not settings.XPACK_ENABLED:
choices = {k: v for k, v in source.choices.items() if k in open_source}
source.choices = list(choices.items())
def validate_password(self, password):
password_strategy = self.initial_data.get("password_strategy")
if self.instance is None and password_strategy != PasswordStrategy.custom:

Loading…
Cancel
Save