Browse Source

fix: 批量删除管理用户报错信息太丑

pull/5288/head
xinwen 4 years ago committed by Jiangjie.Bai
parent
commit
4f5f92deb8
  1. 5
      apps/common/drf/exc_handlers.py
  2. 6
      apps/common/exceptions.py
  3. BIN
      apps/locale/zh/LC_MESSAGES/django.mo
  4. 162
      apps/locale/zh/LC_MESSAGES/django.po

5
apps/common/drf/exc_handlers.py

@ -1,11 +1,12 @@
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist as DJObjectDoesNotExist
from django.http import Http404
from django.utils.translation import gettext
from django.db.models.deletion import ProtectedError
from rest_framework import exceptions
from rest_framework.views import set_rollback
from rest_framework.response import Response
from common.exceptions import JMSObjectDoesNotExist
from common.exceptions import JMSObjectDoesNotExist, ReferencedByOthers
from logging import getLogger
logger = getLogger('drf_exception')
@ -31,6 +32,8 @@ def common_exception_handler(exc, context):
exc = exceptions.PermissionDenied()
elif isinstance(exc, DJObjectDoesNotExist):
exc = JMSObjectDoesNotExist(object_name=extract_object_name(exc, 0))
elif isinstance(exc, ProtectedError):
exc = ReferencedByOthers()
if isinstance(exc, exceptions.APIException):
headers = {}

6
apps/common/exceptions.py

@ -33,3 +33,9 @@ class Timeout(JMSException):
class M2MReverseNotAllowed(JMSException):
status_code = status.HTTP_400_BAD_REQUEST
default_detail = _('M2M reverse not allowed')
class ReferencedByOthers(JMSException):
status_code = status.HTTP_400_BAD_REQUEST
default_code = 'referenced_by_others'
default_detail = _('Is referenced by other objects and cannot be deleted')

BIN
apps/locale/zh/LC_MESSAGES/django.mo

Binary file not shown.

162
apps/locale/zh/LC_MESSAGES/django.po

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: JumpServer 0.3.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-12-10 21:21+0800\n"
"POT-Creation-Date: 2020-12-17 14:38+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: ibuler <ibuler@qq.com>\n"
"Language-Team: JumpServer team<ibuler@qq.com>\n"
@ -95,7 +95,7 @@ msgstr "类型"
#: assets/models/domain.py:55 assets/models/group.py:23
#: assets/models/label.py:23 ops/models/adhoc.py:37 orgs/models.py:26
#: perms/models/base.py:56 settings/models.py:32 terminal/models/storage.py:28
#: terminal/models/storage.py:65 terminal/models/terminal.py:142
#: terminal/models/storage.py:65 terminal/models/terminal.py:145
#: tickets/models/ticket.py:43 users/models/group.py:16
#: users/models/user.py:528 users/templates/users/user_detail.html:115
#: users/templates/users/user_granted_database_app.html:38
@ -154,7 +154,7 @@ msgstr "Kubernetes应用"
#: assets/serializers/admin_user.py:32 assets/serializers/asset_user.py:47
#: assets/serializers/asset_user.py:84 assets/serializers/system_user.py:191
#: audits/models.py:38 perms/forms/asset_permission.py:89
#: perms/models/asset_permission.py:92 templates/index.html:82
#: perms/models/asset_permission.py:94 templates/index.html:82
#: terminal/backends/command/models.py:19
#: terminal/backends/command/serializers.py:13 terminal/models/session.py:39
#: users/templates/users/user_asset_permission.html:40
@ -342,7 +342,7 @@ msgstr "系统平台"
#: assets/models/asset.py:191 assets/serializers/asset_user.py:45
#: assets/serializers/gathered_user.py:20 settings/serializers/settings.py:51
#: tickets/api/request_asset_perm.py:67
#: tickets/serializers/request_asset_perm.py:25
#: tickets/serializers/request_asset_perm.py:23
#: users/templates/users/_granted_assets.html:25
#: users/templates/users/user_asset_permission.html:157
msgid "Hostname"
@ -359,7 +359,7 @@ msgid "Protocols"
msgstr "协议组"
#: assets/models/asset.py:199 assets/models/user.py:98
#: perms/models/asset_permission.py:93
#: perms/models/asset_permission.py:95
#: xpack/plugins/change_auth_plan/models.py:56
#: xpack/plugins/gathered_user/models.py:24
msgid "Nodes"
@ -373,7 +373,7 @@ msgstr "激活"
#: assets/models/asset.py:203 assets/models/cluster.py:19
#: assets/models/user.py:66 templates/_nav.html:44
#: xpack/plugins/cloud/models.py:143 xpack/plugins/cloud/serializers.py:115
#: xpack/plugins/cloud/models.py:143 xpack/plugins/cloud/serializers.py:114
msgid "Admin user"
msgstr "管理用户"
@ -565,7 +565,7 @@ msgstr "每行一个命令"
#: assets/models/cmd_filter.py:56 audits/models.py:57
#: authentication/templates/authentication/_access_key_modal.html:34
#: perms/forms/asset_permission.py:20
#: tickets/serializers/request_asset_perm.py:65
#: tickets/serializers/request_asset_perm.py:63
#: tickets/serializers/ticket.py:30
#: users/templates/users/_granted_assets.html:29
#: users/templates/users/user_asset_permission.html:44
@ -617,12 +617,12 @@ msgstr "默认资产组"
#: audits/models.py:69 audits/serializers.py:81 authentication/models.py:44
#: authentication/models.py:88 orgs/models.py:18 orgs/models.py:396
#: perms/forms/asset_permission.py:83 perms/forms/database_app_permission.py:38
#: perms/forms/remote_app_permission.py:40 perms/models/asset_permission.py:169
#: perms/forms/remote_app_permission.py:40 perms/models/asset_permission.py:171
#: perms/models/base.py:49 templates/index.html:78
#: terminal/backends/command/models.py:18
#: terminal/backends/command/serializers.py:12 terminal/models/session.py:37
#: tickets/models/ticket.py:30 tickets/models/ticket.py:136
#: tickets/serializers/request_asset_perm.py:66
#: tickets/serializers/request_asset_perm.py:64
#: tickets/serializers/ticket.py:31 users/forms/group.py:15
#: users/models/user.py:159 users/models/user.py:643
#: users/serializers/group.py:20
@ -650,7 +650,7 @@ msgstr "新节点"
msgid "empty"
msgstr "空"
#: assets/models/node.py:400 perms/models/asset_permission.py:144
#: assets/models/node.py:400 perms/models/asset_permission.py:146
msgid "Key"
msgstr "键"
@ -658,7 +658,7 @@ msgstr "键"
msgid "Full value"
msgstr "全称"
#: assets/models/node.py:405 perms/models/asset_permission.py:148
#: assets/models/node.py:405 perms/models/asset_permission.py:150
msgid "Parent key"
msgstr "ssh私钥"
@ -667,7 +667,7 @@ msgstr "ssh私钥"
#: users/templates/users/user_asset_permission.html:41
#: users/templates/users/user_asset_permission.html:73
#: users/templates/users/user_asset_permission.html:158
#: xpack/plugins/cloud/models.py:139 xpack/plugins/cloud/serializers.py:116
#: xpack/plugins/cloud/models.py:139 xpack/plugins/cloud/serializers.py:115
msgid "Node"
msgstr "节点"
@ -733,14 +733,14 @@ msgstr "用户组"
#: assets/models/user.py:211 audits/models.py:39
#: perms/forms/asset_permission.py:95 perms/forms/remote_app_permission.py:49
#: perms/models/application_permission.py:22
#: perms/models/asset_permission.py:94
#: perms/models/asset_permission.py:96
#: perms/models/database_app_permission.py:22
#: perms/models/k8s_app_permission.py:22
#: perms/models/remote_app_permission.py:16 templates/_nav.html:45
#: terminal/backends/command/models.py:20
#: terminal/backends/command/serializers.py:14 terminal/models/session.py:41
#: tickets/api/request_asset_perm.py:68
#: tickets/serializers/request_asset_perm.py:27
#: tickets/serializers/request_asset_perm.py:25
#: users/templates/users/_granted_assets.html:27
#: users/templates/users/user_asset_permission.html:42
#: users/templates/users/user_asset_permission.html:76
@ -1060,7 +1060,7 @@ msgid "Success"
msgstr "成功"
#: audits/models.py:43 ops/models/command.py:28 perms/models/base.py:52
#: terminal/models/session.py:51 tickets/serializers/request_asset_perm.py:29
#: terminal/models/session.py:51 tickets/serializers/request_asset_perm.py:27
#: xpack/plugins/change_auth_plan/models.py:177
#: xpack/plugins/change_auth_plan/models.py:307
#: xpack/plugins/gathered_user/models.py:76
@ -1151,7 +1151,7 @@ msgstr "多因子认证"
msgid "Reason"
msgstr "原因"
#: audits/models.py:106 tickets/serializers/request_asset_perm.py:64
#: audits/models.py:106 tickets/serializers/request_asset_perm.py:62
#: tickets/serializers/ticket.py:29 xpack/plugins/cloud/models.py:224
#: xpack/plugins/cloud/models.py:282
msgid "Status"
@ -1177,7 +1177,7 @@ msgstr "状态(显示名称)"
msgid "MFA for display"
msgstr "多因子认证状态(显示名称)"
#: audits/serializers.py:66 audits/serializers.py:78 ops/models/adhoc.py:244
#: audits/serializers.py:66 audits/serializers.py:78 ops/models/adhoc.py:246
#: terminal/serializers/session.py:34
msgid "Is success"
msgstr "是否成功"
@ -1614,6 +1614,10 @@ msgstr "您的请求超时了"
msgid "M2M reverse not allowed"
msgstr ""
#: common/exceptions.py:41
msgid "Is referenced by other objects and cannot be deleted"
msgstr "被其他对象关联,不能删除"
#: common/fields/form.py:33
msgid "Not a valid json"
msgstr "不是合法json"
@ -1786,46 +1790,46 @@ msgstr "Become"
msgid "Create by"
msgstr "创建者"
#: ops/models/adhoc.py:237
#: ops/models/adhoc.py:239
msgid "Task display"
msgstr "任务展示"
#: ops/models/adhoc.py:238
#: ops/models/adhoc.py:240
msgid "Host amount"
msgstr "主机数量"
#: ops/models/adhoc.py:240
#: ops/models/adhoc.py:242
msgid "Start time"
msgstr "开始时间"
#: ops/models/adhoc.py:241
#: ops/models/adhoc.py:243
msgid "End time"
msgstr "完成时间"
#: ops/models/adhoc.py:242 xpack/plugins/change_auth_plan/models.py:180
#: ops/models/adhoc.py:244 xpack/plugins/change_auth_plan/models.py:180
#: xpack/plugins/change_auth_plan/models.py:310
#: xpack/plugins/gathered_user/models.py:79
msgid "Time"
msgstr "时间"
#: ops/models/adhoc.py:243 ops/models/command.py:26
#: ops/models/adhoc.py:245 ops/models/command.py:26
#: terminal/serializers/session.py:38
msgid "Is finished"
msgstr "是否完成"
#: ops/models/adhoc.py:245
#: ops/models/adhoc.py:247
msgid "Adhoc raw result"
msgstr "结果"
#: ops/models/adhoc.py:246
#: ops/models/adhoc.py:248
msgid "Adhoc result summary"
msgstr "汇总"
#: ops/models/adhoc.py:286 xpack/plugins/change_auth_plan/utils.py:137
#: ops/models/adhoc.py:288 xpack/plugins/change_auth_plan/utils.py:137
msgid "{} Start task: {}"
msgstr "{} 任务开始: {}"
#: ops/models/adhoc.py:295 xpack/plugins/change_auth_plan/utils.py:149
#: ops/models/adhoc.py:297 xpack/plugins/change_auth_plan/utils.py:149
msgid "{} Task finish"
msgstr "{} 任务结束"
@ -1983,16 +1987,16 @@ msgstr "剪贴板粘贴"
msgid "Clipboard copy paste"
msgstr "剪贴板复制粘贴"
#: perms/models/asset_permission.py:95 perms/serializers/asset/permission.py:60
#: perms/models/asset_permission.py:97 perms/serializers/asset/permission.py:60
msgid "Actions"
msgstr "动作"
#: perms/models/asset_permission.py:99 templates/_nav.html:78
#: perms/models/asset_permission.py:101 templates/_nav.html:78
#: users/templates/users/_user_detail_nav_header.html:31
msgid "Asset permission"
msgstr "资产授权"
#: perms/models/base.py:53 tickets/serializers/request_asset_perm.py:31
#: perms/models/base.py:53 tickets/serializers/request_asset_perm.py:29
#: users/models/user.py:533 users/templates/users/user_detail.html:93
#: users/templates/users/user_profile.html:120
msgid "Date expired"
@ -2101,100 +2105,100 @@ msgstr "设置"
msgid "Auto"
msgstr "自动"
#: settings/utils/ldap.py:389
#: settings/utils/ldap.py:411
msgid "Host or port is disconnected: {}"
msgstr "主机或端口不可连接: {}"
#: settings/utils/ldap.py:391
#: settings/utils/ldap.py:413
msgid "The port is not the port of the LDAP service: {}"
msgstr "端口不是LDAP服务端口: {}"
#: settings/utils/ldap.py:393
#: settings/utils/ldap.py:415
msgid "Please add certificate: {}"
msgstr "请添加证书"
#: settings/utils/ldap.py:395 settings/utils/ldap.py:422
#: settings/utils/ldap.py:452 settings/utils/ldap.py:480
#: settings/utils/ldap.py:417 settings/utils/ldap.py:444
#: settings/utils/ldap.py:474 settings/utils/ldap.py:502
msgid "Unknown error: {}"
msgstr "未知错误: {}"
#: settings/utils/ldap.py:409
#: settings/utils/ldap.py:431
msgid "Bind DN or Password incorrect"
msgstr "绑定DN或密码错误"
#: settings/utils/ldap.py:416
#: settings/utils/ldap.py:438
msgid "Please enter Bind DN: {}"
msgstr "请输入绑定DN: {}"
#: settings/utils/ldap.py:418
#: settings/utils/ldap.py:440
msgid "Please enter Password: {}"
msgstr "请输入密码: {}"
#: settings/utils/ldap.py:420
#: settings/utils/ldap.py:442
msgid "Please enter correct Bind DN and Password: {}"
msgstr "请输入正确的绑定DN和密码: {}"
#: settings/utils/ldap.py:438
#: settings/utils/ldap.py:460
msgid "Invalid User OU or User search filter: {}"
msgstr "不合法的用户OU或用户过滤器: {}"
#: settings/utils/ldap.py:469
#: settings/utils/ldap.py:491
msgid "LDAP User attr map not include: {}"
msgstr "LDAP属性映射没有包含: {}"
#: settings/utils/ldap.py:476
#: settings/utils/ldap.py:498
msgid "LDAP User attr map is not dict"
msgstr "LDAP属性映射不合法"
#: settings/utils/ldap.py:495
#: settings/utils/ldap.py:517
msgid "LDAP authentication is not enabled"
msgstr "LDAP认证没有启用"
#: settings/utils/ldap.py:513
#: settings/utils/ldap.py:535
msgid "Error (Invalid LDAP server): {}"
msgstr "错误 (不合法的LDAP服务器地址): {}"
#: settings/utils/ldap.py:515
#: settings/utils/ldap.py:537
msgid "Error (Invalid Bind DN): {}"
msgstr "错误(不合法的绑定DN): {}"
#: settings/utils/ldap.py:517
#: settings/utils/ldap.py:539
msgid "Error (Invalid LDAP User attr map): {}"
msgstr "错误(不合法的LDAP属性映射): {}"
#: settings/utils/ldap.py:519
#: settings/utils/ldap.py:541
msgid "Error (Invalid User OU or User search filter): {}"
msgstr "错误(不合法的用户OU或用户过滤器): {}"
#: settings/utils/ldap.py:521
#: settings/utils/ldap.py:543
msgid "Error (Not enabled LDAP authentication): {}"
msgstr "错误(没有启用LDAP认证): {}"
#: settings/utils/ldap.py:523
#: settings/utils/ldap.py:545
msgid "Error (Unknown): {}"
msgstr "错误(未知): {}"
#: settings/utils/ldap.py:526
#: settings/utils/ldap.py:548
msgid "Succeed: Match {} s user"
msgstr "成功匹配 {} 个用户"
#: settings/utils/ldap.py:559
#: settings/utils/ldap.py:581
msgid "Authentication failed (configuration incorrect): {}"
msgstr "认证失败(配置错误): {}"
#: settings/utils/ldap.py:561
#: settings/utils/ldap.py:583
msgid "Authentication failed (before login check failed): {}"
msgstr "认证失败(登录前检查失败): {}"
#: settings/utils/ldap.py:563
#: settings/utils/ldap.py:585
msgid "Authentication failed (username or password incorrect): {}"
msgstr "认证失败 (用户名或密码不正确): {}"
#: settings/utils/ldap.py:565
#: settings/utils/ldap.py:587
msgid "Authentication failed (Unknown): {}"
msgstr "认证失败: (未知): {}"
#: settings/utils/ldap.py:568
#: settings/utils/ldap.py:590
msgid "Authentication success: {}"
msgstr "认证成功: {}"
@ -2803,27 +2807,27 @@ msgstr "运行时间"
msgid "Args"
msgstr "参数"
#: terminal/models/terminal.py:132
#: terminal/models/terminal.py:134
msgid "type"
msgstr "类型"
#: terminal/models/terminal.py:133
#: terminal/models/terminal.py:136
msgid "Remote Address"
msgstr "远端地址"
#: terminal/models/terminal.py:134
#: terminal/models/terminal.py:137
msgid "SSH Port"
msgstr "SSH端口"
#: terminal/models/terminal.py:135
#: terminal/models/terminal.py:138
msgid "HTTP Port"
msgstr "HTTP端口"
#: terminal/models/terminal.py:136
#: terminal/models/terminal.py:139
msgid "Command storage"
msgstr "命令存储"
#: terminal/models/terminal.py:137
#: terminal/models/terminal.py:140
msgid "Replay storage"
msgstr "录像存储"
@ -2913,12 +2917,12 @@ msgid "Ticket has %s"
msgstr "工单已%s"
#: tickets/api/request_asset_perm.py:66
#: tickets/serializers/request_asset_perm.py:23
#: tickets/serializers/request_asset_perm.py:21
msgid "IP group"
msgstr "IP组"
#: tickets/api/request_asset_perm.py:69
#: tickets/serializers/request_asset_perm.py:35
#: tickets/serializers/request_asset_perm.py:33
msgid "Confirmed assets"
msgstr "确认的资产"
@ -3027,19 +3031,19 @@ msgstr "{} {} 这个工单"
msgid "this ticket"
msgstr "这个工单"
#: tickets/serializers/request_asset_perm.py:39
#: tickets/serializers/request_asset_perm.py:37
msgid "Confirmed system user"
msgstr "确认的系统用户"
#: tickets/serializers/request_asset_perm.py:88
#: tickets/serializers/request_asset_perm.py:86
msgid "Invalid `org_id`"
msgstr "无效的 `org_id`"
#: tickets/serializers/request_asset_perm.py:97
#: tickets/serializers/request_asset_perm.py:95
msgid "Field `assignees` must be organization admin or superuser"
msgstr "字段 assignees 必须是组织管理员或者超级管理员"
#: tickets/serializers/request_asset_perm.py:147
#: tickets/serializers/request_asset_perm.py:156
#, python-brace-format
msgid ""
"\n"
@ -3208,8 +3212,8 @@ msgid "Public key should not be the same as your old one."
msgstr "不能和原来的密钥相同"
#: users/forms/profile.py:137 users/forms/user.py:90
#: users/serializers/user.py:192 users/serializers/user.py:274
#: users/serializers/user.py:332
#: users/serializers/user.py:192 users/serializers/user.py:277
#: users/serializers/user.py:335
msgid "Not a valid ssh public key"
msgstr "SSH密钥不合法"
@ -3303,7 +3307,7 @@ msgstr "是否可删除"
msgid "Organization role name"
msgstr "组织角色名称"
#: users/serializers/user.py:78 users/serializers/user.py:245
#: users/serializers/user.py:78 users/serializers/user.py:248
msgid "Is first login"
msgstr "首次登录"
@ -3339,15 +3343,15 @@ msgstr "强制启用多因子认证"
msgid "Role limit to {}"
msgstr "角色只能为 {}"
#: users/serializers/user.py:124 users/serializers/user.py:298
#: users/serializers/user.py:124 users/serializers/user.py:301
msgid "Password does not match security rules"
msgstr "密码不满足安全规则"
#: users/serializers/user.py:290
#: users/serializers/user.py:293
msgid "The old password is incorrect"
msgstr "旧密码错误"
#: users/serializers/user.py:304
#: users/serializers/user.py:307
msgid "The newly set password is inconsistent"
msgstr "两次密码不一致"
@ -3361,7 +3365,7 @@ msgstr "安全令牌验证"
#: users/templates/users/_base_otp.html:14 users/templates/users/_user.html:13
#: users/templates/users/user_profile_update.html:55
#: xpack/plugins/cloud/models.py:125 xpack/plugins/cloud/serializers.py:114
#: xpack/plugins/cloud/models.py:125 xpack/plugins/cloud/serializers.py:113
msgid "Account"
msgstr "账户"
@ -4308,7 +4312,7 @@ msgstr "实例名称"
msgid "Instance name and Partial IP"
msgstr "实例名称和部分IP"
#: xpack/plugins/cloud/models.py:128 xpack/plugins/cloud/serializers.py:90
#: xpack/plugins/cloud/models.py:128 xpack/plugins/cloud/serializers.py:89
msgid "Regions"
msgstr "地域"
@ -4320,7 +4324,7 @@ msgstr "实例"
msgid "Hostname strategy"
msgstr "主机名策略"
#: xpack/plugins/cloud/models.py:147 xpack/plugins/cloud/serializers.py:118
#: xpack/plugins/cloud/models.py:147 xpack/plugins/cloud/serializers.py:117
msgid "Always update"
msgstr "总是更新"
@ -4452,15 +4456,15 @@ msgstr "租户ID"
msgid "Subscription ID"
msgstr "订阅ID"
#: xpack/plugins/cloud/serializers.py:88
#: xpack/plugins/cloud/serializers.py:87
msgid "History count"
msgstr "执行次数"
#: xpack/plugins/cloud/serializers.py:89
#: xpack/plugins/cloud/serializers.py:88
msgid "Instance count"
msgstr "实例个数"
#: xpack/plugins/cloud/serializers.py:117
#: xpack/plugins/cloud/serializers.py:116
#: xpack/plugins/gathered_user/serializers.py:20
msgid "Periodic display"
msgstr "定时执行"

Loading…
Cancel
Save