diff --git a/apps/assets/models/base.py b/apps/assets/models/base.py index d3ac5f493..38b7218c4 100644 --- a/apps/assets/models/base.py +++ b/apps/assets/models/base.py @@ -185,10 +185,18 @@ class BaseUser(OrgModelMixin, AuthMixin): ASSETS_AMOUNT_CACHE_KEY = "ASSET_USER_{}_ASSETS_AMOUNT" ASSET_USER_CACHE_TIME = 600 + APPS_AMOUNT_CACHE_KEY = "APP_USER_{}_APPS_AMOUNT" + APP_USER_CACHE_TIME = 600 + def get_related_assets(self): assets = self.assets.filter(org_id=self.org_id) return assets + def get_related_apps(self): + from applications.models import Account + apps = Account.objects.filter(systemuser=self) + return apps + def get_username(self): return self.username @@ -201,6 +209,15 @@ class BaseUser(OrgModelMixin, AuthMixin): cache.set(cache_key, cached, self.ASSET_USER_CACHE_TIME) return cached + @property + def apps_amount(self): + cache_key = self.APPS_AMOUNT_CACHE_KEY.format(self.id) + cached = cache.get(cache_key) + if not cached: + cached = self.get_related_apps().count() + cache.set(cache_key, cached, self.APP_USER_CACHE_TIME) + return cached + def expire_assets_amount(self): cache_key = self.ASSETS_AMOUNT_CACHE_KEY.format(self.id) cache.delete(cache_key) diff --git a/apps/assets/serializers/system_user.py b/apps/assets/serializers/system_user.py index a380c3831..85968ca25 100644 --- a/apps/assets/serializers/system_user.py +++ b/apps/assets/serializers/system_user.py @@ -26,6 +26,7 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): auto_generate_key = serializers.BooleanField(initial=True, required=False, write_only=True) type_display = serializers.ReadOnlyField(source='get_type_display', label=_('Type display')) ssh_key_fingerprint = serializers.ReadOnlyField(label=_('SSH key fingerprint')) + applications_amount = serializers.IntegerField(source='apps_amount', label=_('Apps amount')) class Meta: model = SystemUser @@ -39,7 +40,7 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): 'username_same_with_user', 'auto_push', 'auto_generate_key', 'date_created', 'date_updated', 'comment', 'created_by', ] - fields_m2m = ['cmd_filters', 'assets_amount', 'nodes'] + fields_m2m = ['cmd_filters', 'assets_amount', 'applications_amount', 'nodes'] fields = fields_small + fields_m2m extra_kwargs = { 'password': { @@ -203,7 +204,7 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): def setup_eager_loading(cls, queryset): """ Perform necessary eager loading of data. """ queryset = queryset\ - .annotate(assets_amount=Count("assets"))\ + .annotate(assets_amount=Count("assets")) \ .prefetch_related('nodes', 'cmd_filters') return queryset diff --git a/apps/locale/zh/LC_MESSAGES/django.mo b/apps/locale/zh/LC_MESSAGES/django.mo index 555ebb9f5..dac4a4b09 100644 --- a/apps/locale/zh/LC_MESSAGES/django.mo +++ b/apps/locale/zh/LC_MESSAGES/django.mo @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b2663d90ceadd419c40abd472a3b5030b007b1e1db1fcaeda9893ff90cd7cdd6 -size 89955 +oid sha256:55a2062981ea7eef4ca28142f325f52e15cb7679ad0a2600234a5bdb6d005c87 +size 89996 diff --git a/apps/locale/zh/LC_MESSAGES/django.po b/apps/locale/zh/LC_MESSAGES/django.po index c2945ae51..5dcdd8488 100644 --- a/apps/locale/zh/LC_MESSAGES/django.po +++ b/apps/locale/zh/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: JumpServer 0.3.3\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-22 19:15+0800\n" +"POT-Creation-Date: 2021-10-25 14:56+0800\n" "PO-Revision-Date: 2021-05-20 10:54+0800\n" "Last-Translator: ibuler \n" "Language-Team: JumpServer team\n" @@ -35,12 +35,12 @@ msgid "Name" msgstr "名称" #: acls/models/base.py:27 assets/models/cmd_filter.py:54 -#: assets/models/user.py:207 +#: assets/models/user.py:199 msgid "Priority" msgstr "优先级" #: acls/models/base.py:28 assets/models/cmd_filter.py:54 -#: assets/models/user.py:207 +#: assets/models/user.py:199 msgid "1-100, the lower the value will be match first" msgstr "优先级可选范围为 1-100 (数值越小越优先)" @@ -85,7 +85,7 @@ msgstr "登录复核" #: orgs/models.py:19 orgs/models.py:433 perms/models/base.py:45 #: templates/index.html:78 terminal/backends/command/models.py:18 #: terminal/backends/command/serializers.py:12 terminal/models/session.py:38 -#: terminal/notifications.py:91 terminal/notifications.py:136 +#: terminal/notifications.py:90 terminal/notifications.py:138 #: tickets/models/comment.py:17 users/const.py:14 users/models/user.py:173 #: users/models/user.py:801 users/models/user.py:827 #: users/serializers/group.py:19 @@ -123,11 +123,11 @@ msgstr "系统用户" #: acls/models/login_asset_acl.py:22 #: applications/serializers/attrs/application_category/remote_app.py:37 #: assets/models/asset.py:357 assets/models/authbook.py:18 -#: assets/models/gathered_user.py:14 assets/serializers/system_user.py:215 +#: assets/models/gathered_user.py:14 assets/serializers/system_user.py:231 #: audits/models.py:38 perms/models/asset_permission.py:99 #: templates/index.html:82 terminal/backends/command/models.py:19 #: terminal/backends/command/serializers.py:13 terminal/models/session.py:40 -#: terminal/notifications.py:90 +#: terminal/notifications.py:89 #: users/templates/users/user_asset_permission.html:40 #: users/templates/users/user_asset_permission.html:70 #: xpack/plugins/change_auth_plan/models/asset.py:195 @@ -196,7 +196,7 @@ msgid "" msgstr "格式为逗号分隔的字符串, * 表示匹配所有. 可选的协议有: {}" #: acls/serializers/login_asset_acl.py:55 assets/models/asset.py:184 -#: assets/models/domain.py:63 assets/models/user.py:208 +#: assets/models/domain.py:63 assets/models/user.py:200 #: terminal/serializers/session.py:30 terminal/serializers/storage.py:69 msgid "Protocol" msgstr "协议" @@ -252,7 +252,7 @@ msgid "Custom" msgstr "自定义" #: applications/models/account.py:11 assets/models/authbook.py:19 -#: assets/models/user.py:281 audits/models.py:39 +#: assets/models/user.py:273 audits/models.py:39 #: perms/models/application_permission.py:32 #: perms/models/asset_permission.py:101 templates/_nav.html:45 #: terminal/backends/command/models.py:20 @@ -293,7 +293,7 @@ msgstr "类别" #: applications/models/application.py:171 #: applications/serializers/application.py:90 assets/models/cmd_filter.py:53 -#: assets/models/user.py:206 perms/models/application_permission.py:23 +#: assets/models/user.py:198 perms/models/application_permission.py:23 #: perms/serializers/application/user_permission.py:34 #: terminal/models/storage.py:55 terminal/models/storage.py:116 #: tickets/models/flow.py:51 tickets/models/ticket.py:48 @@ -403,7 +403,7 @@ msgstr "运行参数" msgid "Target url" msgstr "目标URL" -#: assets/api/domain.py:50 +#: assets/api/domain.py:52 msgid "Number required" msgstr "需要为数字" @@ -447,7 +447,7 @@ msgstr "系统平台" msgid "Protocols" msgstr "协议组" -#: assets/models/asset.py:189 assets/models/user.py:198 +#: assets/models/asset.py:189 assets/models/user.py:190 #: perms/models/asset_permission.py:100 #: xpack/plugins/change_auth_plan/models/asset.py:44 #: xpack/plugins/gathered_user/models.py:24 @@ -460,7 +460,7 @@ msgid "Is active" msgstr "激活" #: assets/models/asset.py:193 assets/models/cluster.py:19 -#: assets/models/user.py:195 assets/models/user.py:330 templates/_nav.html:44 +#: assets/models/user.py:187 assets/models/user.py:322 templates/_nav.html:44 msgid "Admin user" msgstr "特权用户" @@ -638,7 +638,7 @@ msgstr "系统" msgid "Default Cluster" msgstr "默认Cluster" -#: assets/models/cmd_filter.py:33 assets/models/user.py:213 +#: assets/models/cmd_filter.py:33 assets/models/user.py:205 msgid "Command filter" msgstr "命令过滤器" @@ -747,7 +747,7 @@ msgstr "全称" msgid "Parent key" msgstr "ssh私钥" -#: assets/models/node.py:559 assets/serializers/system_user.py:214 +#: assets/models/node.py:559 assets/serializers/system_user.py:230 #: users/templates/users/user_asset_permission.html:41 #: users/templates/users/user_asset_permission.html:73 #: users/templates/users/user_asset_permission.html:158 @@ -755,67 +755,67 @@ msgstr "ssh私钥" msgid "Node" msgstr "节点" -#: assets/models/user.py:189 +#: assets/models/user.py:181 msgid "Automatic managed" msgstr "托管密码" -#: assets/models/user.py:190 +#: assets/models/user.py:182 msgid "Manually input" msgstr "手动输入" -#: assets/models/user.py:194 +#: assets/models/user.py:186 msgid "Common user" msgstr "普通用户" -#: assets/models/user.py:197 +#: assets/models/user.py:189 msgid "Username same with user" msgstr "用户名与用户相同" -#: assets/models/user.py:200 assets/serializers/domain.py:29 +#: assets/models/user.py:192 assets/serializers/domain.py:29 #: templates/_nav.html:39 #: terminal/templates/terminal/_msg_command_execute_alert.html:16 #: xpack/plugins/change_auth_plan/models/asset.py:40 msgid "Assets" msgstr "资产" -#: assets/models/user.py:204 templates/_nav.html:17 +#: assets/models/user.py:196 templates/_nav.html:17 #: users/views/profile/pubkey.py:37 msgid "Users" msgstr "用户管理" -#: assets/models/user.py:205 +#: assets/models/user.py:197 msgid "User groups" msgstr "用户组" -#: assets/models/user.py:209 +#: assets/models/user.py:201 msgid "Auto push" msgstr "自动推送" -#: assets/models/user.py:210 +#: assets/models/user.py:202 msgid "Sudo" msgstr "Sudo" -#: assets/models/user.py:211 +#: assets/models/user.py:203 msgid "Shell" msgstr "Shell" -#: assets/models/user.py:212 +#: assets/models/user.py:204 msgid "Login mode" msgstr "认证方式" -#: assets/models/user.py:214 +#: assets/models/user.py:206 msgid "SFTP Root" msgstr "SFTP根路径" -#: assets/models/user.py:215 authentication/models.py:45 +#: assets/models/user.py:207 authentication/models.py:45 msgid "Token" msgstr "" -#: assets/models/user.py:216 +#: assets/models/user.py:208 msgid "Home" msgstr "家目录" -#: assets/models/user.py:217 +#: assets/models/user.py:209 msgid "System groups" msgstr "用户组" @@ -848,7 +848,7 @@ msgstr "节点名称" msgid "Hardware info" msgstr "硬件信息" -#: assets/serializers/asset.py:104 assets/serializers/system_user.py:233 +#: assets/serializers/asset.py:104 assets/serializers/system_user.py:249 #: orgs/mixins/serializers.py:26 msgid "Org name" msgstr "组织名称" @@ -862,7 +862,7 @@ msgid "private key invalid" msgstr "密钥不合法" #: assets/serializers/domain.py:13 assets/serializers/label.py:12 -#: assets/serializers/system_user.py:53 +#: assets/serializers/system_user.py:54 #: perms/serializers/asset/permission.py:72 msgid "Assets amount" msgstr "资产数量" @@ -892,48 +892,52 @@ msgstr "同级别节点名字不能重复" msgid "SSH key fingerprint" msgstr "密钥指纹" -#: assets/serializers/system_user.py:52 +#: assets/serializers/system_user.py:29 +msgid "Apps amount" +msgstr "应用数量" + +#: assets/serializers/system_user.py:53 #: perms/serializers/asset/permission.py:73 msgid "Nodes amount" msgstr "节点数量" -#: assets/serializers/system_user.py:54 assets/serializers/system_user.py:216 +#: assets/serializers/system_user.py:55 assets/serializers/system_user.py:232 msgid "Login mode display" msgstr "认证方式名称" -#: assets/serializers/system_user.py:56 +#: assets/serializers/system_user.py:57 msgid "Ad domain" msgstr "Ad 网域" -#: assets/serializers/system_user.py:57 +#: assets/serializers/system_user.py:58 msgid "Is asset protocol" msgstr "" -#: assets/serializers/system_user.py:97 +#: assets/serializers/system_user.py:98 msgid "Username same with user with protocol {} only allow 1" msgstr "用户名和用户相同的一种协议只允许存在一个" -#: assets/serializers/system_user.py:107 common/validators.py:14 +#: assets/serializers/system_user.py:108 common/validators.py:14 msgid "Special char not allowed" msgstr "不能包含特殊字符" -#: assets/serializers/system_user.py:116 +#: assets/serializers/system_user.py:117 msgid "* Automatic login mode must fill in the username." msgstr "自动登录模式,必须填写用户名" -#: assets/serializers/system_user.py:130 +#: assets/serializers/system_user.py:132 msgid "Path should starts with /" msgstr "路径应该以 / 开头" -#: assets/serializers/system_user.py:155 +#: assets/serializers/system_user.py:144 msgid "Password or private key required" msgstr "密码或密钥密码需要一个" -#: assets/serializers/system_user.py:232 +#: assets/serializers/system_user.py:248 msgid "System user name" msgstr "系统用户名称" -#: assets/serializers/system_user.py:242 +#: assets/serializers/system_user.py:258 msgid "Asset hostname" msgstr "资产主机名" @@ -1625,35 +1629,35 @@ msgstr "等待登录复核处理" msgid "Login confirm ticket was {}" msgstr "登录复核 {}" -#: authentication/errors.py:261 +#: authentication/errors.py:265 msgid "IP is not allowed" msgstr "来源 IP 不被允许登录" -#: authentication/errors.py:268 +#: authentication/errors.py:272 msgid "Time Period is not allowed" msgstr "该 时间段 不被允许登录" -#: authentication/errors.py:301 +#: authentication/errors.py:305 msgid "SSO auth closed" msgstr "SSO 认证关闭了" -#: authentication/errors.py:306 authentication/mixins.py:340 +#: authentication/errors.py:310 authentication/mixins.py:340 msgid "Your password is too simple, please change it for security" msgstr "你的密码过于简单,为了安全,请修改" -#: authentication/errors.py:315 authentication/mixins.py:347 +#: authentication/errors.py:319 authentication/mixins.py:347 msgid "You should to change your password before login" msgstr "登录完成前,请先修改密码" -#: authentication/errors.py:324 authentication/mixins.py:354 +#: authentication/errors.py:328 authentication/mixins.py:354 msgid "Your password has expired, please reset before logging in" msgstr "您的密码已过期,先修改再登录" -#: authentication/errors.py:358 +#: authentication/errors.py:362 msgid "Your password is invalid" msgstr "您的密码无效" -#: authentication/errors.py:364 +#: authentication/errors.py:368 msgid "No upload or download permission" msgstr "没有上传下载权限" @@ -1732,7 +1736,7 @@ msgid "Secret" msgstr "密钥" #: authentication/templates/authentication/_access_key_modal.html:33 -#: terminal/notifications.py:93 terminal/notifications.py:138 +#: terminal/notifications.py:92 terminal/notifications.py:140 msgid "Date" msgstr "日期" @@ -1821,16 +1825,16 @@ msgid "" "concern your account security" msgstr "请点击下面链接重置密码, 如果不是您申请的,请关注账号安全" -#: authentication/templates/authentication/_msg_reset_password.html:9 +#: authentication/templates/authentication/_msg_reset_password.html:10 msgid "Click here reset password" msgstr "点击这里重置密码" -#: authentication/templates/authentication/_msg_reset_password.html:13 +#: authentication/templates/authentication/_msg_reset_password.html:15 #: users/templates/users/_msg_user_created.html:17 msgid "This link is valid for 1 hour. After it expires" msgstr "这个链接有效期1小时, 超过时间您可以" -#: authentication/templates/authentication/_msg_reset_password.html:15 +#: authentication/templates/authentication/_msg_reset_password.html:17 #: users/templates/users/_msg_user_created.html:18 msgid "request new one" msgstr "重新申请" @@ -2243,7 +2247,7 @@ msgstr "邮件" msgid "Site message" msgstr "站内信" -#: notifications/notifications.py:167 ops/models/adhoc.py:246 +#: notifications/notifications.py:172 ops/models/adhoc.py:246 #: xpack/plugins/change_auth_plan/models/base.py:108 #: xpack/plugins/change_auth_plan/models/base.py:190 #: xpack/plugins/gathered_user/models.py:79 @@ -2424,11 +2428,11 @@ msgstr "任务列表" msgid "Update task content: {}" msgstr "更新任务内容: {}" -#: orgs/api.py:77 +#: orgs/api.py:79 msgid "The current organization ({}) cannot be deleted" msgstr "当前组织 ({}) 不能被删除" -#: orgs/api.py:85 +#: orgs/api.py:87 msgid "The organization have resource ({}) cannot be deleted" msgstr "组织存在资源 ({}) 不能被删除" @@ -2534,35 +2538,35 @@ msgstr "失效日期" msgid "From ticket" msgstr "来自工单" -#: perms/notifications.py:15 +#: perms/notifications.py:17 msgid "You permed assets is about to expire" msgstr "你授权的资产即将到期" -#: perms/notifications.py:19 +#: perms/notifications.py:21 msgid "permed assets" msgstr "授权的资产" -#: perms/notifications.py:57 +#: perms/notifications.py:59 msgid "Asset permissions is about to expire" msgstr "资产授权规则将要过期" -#: perms/notifications.py:61 +#: perms/notifications.py:63 msgid "asset permissions of organization {}" msgstr "组织 ({}) 的资产授权" -#: perms/notifications.py:87 +#: perms/notifications.py:89 msgid "Your permed applications is about to expire" msgstr "你授权的应用即将过期" -#: perms/notifications.py:90 +#: perms/notifications.py:92 msgid "permed applications" msgstr "授权的应用" -#: perms/notifications.py:128 +#: perms/notifications.py:127 msgid "Application permissions is about to expire" msgstr "应用授权规则即将过期" -#: perms/notifications.py:131 +#: perms/notifications.py:130 msgid "application permissions of organization {}" msgstr "组织 ({}) 的应用授权" @@ -4235,11 +4239,11 @@ msgstr "录像存储" msgid "Danger command alert" msgstr "危险命令告警" -#: terminal/notifications.py:92 terminal/notifications.py:137 +#: terminal/notifications.py:91 terminal/notifications.py:139 msgid "Level" msgstr "级别" -#: terminal/notifications.py:110 +#: terminal/notifications.py:109 msgid "Batch danger command alert" msgstr "批量危险命令告警" @@ -4462,35 +4466,35 @@ msgid "" msgstr "" "通过工单创建, 工单标题: {}, 工单申请人: {}, 工单处理人: {}, 工单 ID: {}" -#: tickets/handler/base.py:86 +#: tickets/handler/base.py:88 msgid "{} {} the ticket" msgstr "{} {} 工单" -#: tickets/handler/base.py:114 +#: tickets/handler/base.py:116 msgid "Ticket title" msgstr "工单标题" -#: tickets/handler/base.py:115 +#: tickets/handler/base.py:117 msgid "Ticket type" msgstr "工单类型" -#: tickets/handler/base.py:116 +#: tickets/handler/base.py:118 msgid "Ticket status" msgstr "工单状态" -#: tickets/handler/base.py:117 +#: tickets/handler/base.py:119 msgid "Ticket applicant" msgstr "工单申请人" -#: tickets/handler/base.py:119 +#: tickets/handler/base.py:121 msgid "Ticket basic info" msgstr "工单基本信息" -#: tickets/handler/base.py:130 +#: tickets/handler/base.py:132 msgid "No content" msgstr "无内容" -#: tickets/handler/base.py:132 +#: tickets/handler/base.py:134 msgid "Ticket applied info" msgstr "工单申请信息" @@ -4611,19 +4615,19 @@ msgstr "流程" msgid "TicketFlow" msgstr "工单流程" -#: tickets/notifications.py:56 +#: tickets/notifications.py:57 msgid "Your has a new ticket, applicant - {}" msgstr "你有一个新的工单, 申请人 - {}" -#: tickets/notifications.py:62 +#: tickets/notifications.py:63 msgid "New Ticket - {} ({})" msgstr "新工单 - {} ({})" -#: tickets/notifications.py:84 +#: tickets/notifications.py:85 msgid "Your ticket has been processed, processor - {}" msgstr "你的工单已被处理, 处理人 - {}" -#: tickets/notifications.py:88 +#: tickets/notifications.py:89 msgid "Ticket has processed - {} ({})" msgstr "你的工单已被处理, 处理人 - {} ({})" @@ -4748,7 +4752,7 @@ msgstr "当前组织已存在该类型" msgid "Click here to review" msgstr "点击查看" -#: users/api/user.py:207 +#: users/api/user.py:209 msgid "Could not reset self otp, use profile reset instead" msgstr "不能在该页面重置多因子认证, 请去个人信息页面重置" @@ -4923,19 +4927,19 @@ msgstr "重置密码" msgid "Reset password success" msgstr "重置密码成功" -#: users/notifications.py:110 +#: users/notifications.py:107 msgid "Password is about expire" msgstr "密码即将过期" -#: users/notifications.py:137 +#: users/notifications.py:135 msgid "Account is about expire" msgstr "账号即将过期" -#: users/notifications.py:161 +#: users/notifications.py:157 msgid "Reset SSH Key" msgstr "重置 SSH 密钥" -#: users/notifications.py:181 +#: users/notifications.py:178 msgid "Reset MFA" msgstr "重置 MFA" @@ -5364,8 +5368,8 @@ msgstr "* 新密码不能是最近 {} 次的密码" msgid "Reset password success, return to login page" msgstr "重置密码成功,返回到登录页面" -#: xpack/plugins/change_auth_plan/api/app.py:113 -#: xpack/plugins/change_auth_plan/api/asset.py:100 +#: xpack/plugins/change_auth_plan/api/app.py:114 +#: xpack/plugins/change_auth_plan/api/asset.py:101 msgid "The parameter 'action' must be [{}]" msgstr "参数 'action' 必须是 [{}]"