From 050ddc88f210d18d8f4ce1b0cc1c50c673167011 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 4 Jun 2024 19:08:16 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20labels=20=E6=94=AF=E6=8C=81=E9=A2=9C?= =?UTF-8?q?=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/serializers/fields.py | 5 +++- apps/i18n/lina/en.json | 15 ++++++----- apps/i18n/lina/zh.json | 2 +- apps/labels/migrations/0002_label_color.py | 31 ++++++++++++++++++++++ apps/labels/models.py | 3 +++ apps/labels/serializers.py | 4 +-- apps/users/migrations/0001_initial.py | 18 ++++++------- 7 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 apps/labels/migrations/0002_label_color.py diff --git a/apps/common/serializers/fields.py b/apps/common/serializers/fields.py index d8cf420c1..ecf97a0b3 100644 --- a/apps/common/serializers/fields.py +++ b/apps/common/serializers/fields.py @@ -113,7 +113,10 @@ class LabelRelatedField(serializers.RelatedField): def to_representation(self, value): if value is None: return value - return str(value.label) + label = value.label + if not label: + return None + return {'id': label.id, 'name': label.name, 'value': label.value, 'color': label.color} def to_internal_value(self, data): from labels.models import LabeledResource, Label diff --git a/apps/i18n/lina/en.json b/apps/i18n/lina/en.json index 61901588b..f7f9627d0 100644 --- a/apps/i18n/lina/en.json +++ b/apps/i18n/lina/en.json @@ -79,7 +79,7 @@ "Aliyun": "Alibaba cloud", "All": "All", "AllAccountTip": "All accounts already added on the asset", - "AllAccounts": "All", + "AllAccounts": "Existing accounts", "AllClickRead": "Mark all as read", "AllMembers": "All members", "AllowInvalidCert": "Ignore certificate check", @@ -379,6 +379,7 @@ "DefaultDatabase": "Default database", "DefaultPort": "Default port", "Delete": "Delete", + "WeekAdd": "Weekly add", "DeleteConfirmMessage": "Deletion is irreversible, do you wish to continue?", "DeleteErrorMsg": "Delete failed", "DeleteNode": "Delete node", @@ -656,7 +657,7 @@ "LoginSSHKeySetting": "Login SSH Key", "LoginSucceeded": "Login successful", "LoginTitleTip": "Note: it will be displayed on the enterprise edition user ssh login koko login page (e.g.: welcome to use jumpserver open source bastion)", - "LoginUserRanking": "Login account ranking", + "LoginUserRanking": "Login user ranking", "LoginUserToday": "Users logged today", "LoginUsers": "Active account", "LogoIndexTip": "Tip: it will be displayed in the upper left corner of the page (recommended image size: 185px*55px)", @@ -670,7 +671,7 @@ "MFAOfUserFirstLoginUserGuidePage": "In order to protect your and the company's security, please carefully safeguard important sensitive information such as your account, password, and key (for example, set a complex password, and enable multi-factor authentication)
personal information such as email, mobile number, and wechat are only used for user authentication and platform internal message notifications.", "MailRecipient": "Email recipient", "MailSend": "Sending", - "ManualAccount": "Manual accounts", + "ManualAccount": "Manual account", "ManualAccountTip": "Manual input of username/password upon login", "ManyChoose": "Select multiple", "MarkAsRead": "Mark as read", @@ -861,7 +862,7 @@ "QuickJob": "Adhoc", "QuickUpdate": "Quick update", "Radius": "Radius", - "Ranking": "Ranking", + "Ranking": "Rank", "RazorNotSupport": "Rdp client session, monitoring not supported", "ReLogin": "Login again", "ReLoginTitle": "Current third-party login user (cas/saml), not bound to mfa and does not support password verification, please login again.", @@ -971,8 +972,8 @@ "SSHPort": "SSH Port", "SSHSecretKey": "SSH Key", "SafeCommand": "Secure command", - "SameAccount": "Same", - "SameAccountTip": "Accounts with the same username as authorized users", + "SameAccount": "Same account", + "SameAccountTip": "Account with the same username as authorized users", "SameTypeAccountTip": "An account with the same username and key type already exists", "Saturday": "Sat", "Save": "Save", @@ -1059,7 +1060,7 @@ "SourceIP": "Source address", "SourcePort": "Source port", "Spec": "Specific", - "SpecAccount": "Specified", + "SpecAccount": "Specified accounts", "SpecAccountTip": "Specify username to choose authorized account", "SpecialSymbol": "Special char", "SpecificInfo": "Special information", diff --git a/apps/i18n/lina/zh.json b/apps/i18n/lina/zh.json index 451715a7d..0057baef3 100644 --- a/apps/i18n/lina/zh.json +++ b/apps/i18n/lina/zh.json @@ -674,7 +674,7 @@ "MenuAccounts": "账号管理", "MenuAcls": "访问控制", "MenuAssets": "资产管理", - "MenuMore": "更多...", + "MenuMore": "其它", "MenuPermissions": "授权管理", "MenuUsers": "用户管理", "Message": "消息", diff --git a/apps/labels/migrations/0002_label_color.py b/apps/labels/migrations/0002_label_color.py new file mode 100644 index 000000000..b01c7a608 --- /dev/null +++ b/apps/labels/migrations/0002_label_color.py @@ -0,0 +1,31 @@ +# Generated by Django 4.1.13 on 2024-06-04 03:50 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("labels", "0001_initial"), + ] + + operations = [ + migrations.AddField( + model_name="label", + name="color", + field=models.CharField( + blank=True, default="", max_length=32, verbose_name="Color" + ), + ), + migrations.AlterField( + model_name="labeledresource", + name="label", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="labeled_resources", + to="labels.label", + verbose_name="Tag", + ), + ), + ] diff --git a/apps/labels/models.py b/apps/labels/models.py index 3002fdb6d..284c96bab 100644 --- a/apps/labels/models.py +++ b/apps/labels/models.py @@ -11,6 +11,9 @@ class Label(JMSOrgBaseModel): name = models.CharField(max_length=64, verbose_name=_("Name"), db_index=True) value = models.CharField(max_length=64, unique=False, verbose_name=_("Value")) internal = models.BooleanField(default=False, verbose_name=_("Internal")) + color = models.CharField( + max_length=32, default="", blank=True, verbose_name=_("Color") + ) class Meta: unique_together = [("name", "value", "org_id")] diff --git a/apps/labels/serializers.py b/apps/labels/serializers.py index 62abc1bc8..e3cc6796f 100644 --- a/apps/labels/serializers.py +++ b/apps/labels/serializers.py @@ -14,8 +14,8 @@ class LabelSerializer(BulkOrgResourceModelSerializer): class Meta: model = Label fields = [ - 'id', 'name', 'value', 'res_count', 'comment', - 'date_created', 'date_updated' + 'id', 'name', 'value', 'color', 'res_count', + 'comment', 'date_created', 'date_updated' ] read_only_fields = ('date_created', 'date_updated', 'res_count') extra_kwargs = { diff --git a/apps/users/migrations/0001_initial.py b/apps/users/migrations/0001_initial.py index 8a4459b0a..a5ae13b84 100644 --- a/apps/users/migrations/0001_initial.py +++ b/apps/users/migrations/0001_initial.py @@ -1,17 +1,17 @@ # Generated by Django 4.1.13 on 2024-05-09 03:16 +import uuid + +import django.contrib.auth.models +import django.utils.timezone +from django.conf import settings +from django.contrib.auth.hashers import make_password +from django.db import migrations, models + import common.db.fields import common.db.models -from django.contrib.auth.hashers import make_password import common.utils.django -from django.conf import settings -import django.contrib.auth.models -from django.db import migrations, models -import django.db.models.deletion -import django.utils.timezone import users.models.user -import uuid - def add_default_group(apps, schema_editor): @@ -62,7 +62,7 @@ class Migration(migrations.Migration): ('avatar', models.ImageField(null=True, upload_to='avatar', verbose_name='Avatar')), ('wechat', common.db.fields.EncryptCharField(blank=True, max_length=128, verbose_name='Wechat')), ('phone', common.db.fields.EncryptCharField(blank=True, max_length=128, null=True, verbose_name='Phone')), - ('mfa_level', models.SmallIntegerField(choices=[(0, 'Disable'), (1, 'Enable'), (2, 'Force enable')], default=0, verbose_name='MFA')), + ('mfa_level', models.SmallIntegerField(choices=[(0, "Disabled"), (1, "Enabled"), (2, "Force enabled")], default=0, verbose_name='MFA')), ('otp_secret_key', common.db.fields.EncryptCharField(blank=True, max_length=128, null=True, verbose_name='OTP secret key')), ('private_key', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='Private key')), ('public_key', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='Public key')),