From 578d5ec4a7b0f0fd6aa91981047d7fe599314f5a Mon Sep 17 00:00:00 2001 From: chenwenchang <479999519@qq.com> Date: Wed, 4 Dec 2024 15:08:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(frontend):=20mongodb=E6=9D=83=E9=99=90?= =?UTF-8?q?=E8=A7=84=E5=88=99=E4=BC=98=E5=8C=96=20#8407=20#=20Reviewed,=20?= =?UTF-8?q?transaction=20id:=2025862?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/frontend/src/locales/zh-cn.json | 5 ++ .../source/mongodbPermissionAccount.ts | 7 +++ dbm-ui/frontend/src/types/auto-imports.d.ts | 2 +- .../db-manage/common/permission/Index.vue | 39 ++++++++++---- .../components/mongo/CreateRule.vue | 51 ++++++++++++++++--- .../permission/components/mongo/config.ts | 2 +- .../components/mysql/create-rule/Index.vue | 1 + 7 files changed, 87 insertions(+), 20 deletions(-) diff --git a/dbm-ui/frontend/src/locales/zh-cn.json b/dbm-ui/frontend/src/locales/zh-cn.json index 8c92df5a56..1efd606318 100644 --- a/dbm-ui/frontend/src/locales/zh-cn.json +++ b/dbm-ui/frontend/src/locales/zh-cn.json @@ -3704,6 +3704,11 @@ "忽略错误": "忽略错误", "强制失败节点成功": "强制失败节点成功", "不允许使用特殊账号名称n": "不允许使用特殊账号名称 {n}", + "非 admin": "非 admin", + "请输入访问DB名_以字母开头_支持字母_数字_下划线": "请输入访问DB名,以字母开头,支持字母,数字,下划线", + "您输入的访问 DB 名不符合要求_访问 DB 名应以字母开头_且仅包含字母_数字和下划线": "您输入的访问 DB 名不符合要求。访问 DB 名应以字母开头,且仅包含字母、数字和下划线", + "访问 DB 不能为空": "访问 DB 不能为空", + "访问 DB 名不允许为 admin": "访问 DB 名不允许为 admin", "这行勿动!新增翻译请在上一行添加!": "" } diff --git a/dbm-ui/frontend/src/services/source/mongodbPermissionAccount.ts b/dbm-ui/frontend/src/services/source/mongodbPermissionAccount.ts index df1b258e69..2848ac69ea 100644 --- a/dbm-ui/frontend/src/services/source/mongodbPermissionAccount.ts +++ b/dbm-ui/frontend/src/services/source/mongodbPermissionAccount.ts @@ -82,3 +82,10 @@ export function queryAccountRules(params: { user: string; access_dbs: string[]; results: res.results.map((item) => new MongodbPermissonAccountModel(item)), })); } + +/** + * 删除规则 + */ +export function deleteAccountRule(params: { account_id: number; account_type: AccountTypesValues; rule_id: number }) { + return http.delete(`${getRootPath()}/delete_account_rule/`, params); +} diff --git a/dbm-ui/frontend/src/types/auto-imports.d.ts b/dbm-ui/frontend/src/types/auto-imports.d.ts index d0c217f6f1..7021ac5101 100644 --- a/dbm-ui/frontend/src/types/auto-imports.d.ts +++ b/dbm-ui/frontend/src/types/auto-imports.d.ts @@ -71,6 +71,6 @@ declare global { // for type re-export declare global { // @ts-ignore - export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue' + export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue' import('vue') } diff --git a/dbm-ui/frontend/src/views/db-manage/common/permission/Index.vue b/dbm-ui/frontend/src/views/db-manage/common/permission/Index.vue index 04bf1b4c1c..75cd74a1a6 100644 --- a/dbm-ui/frontend/src/views/db-manage/common/permission/Index.vue +++ b/dbm-ui/frontend/src/views/db-manage/common/permission/Index.vue @@ -92,7 +92,7 @@ import { useI18n } from 'vue-i18n'; import { useRequest } from 'vue-request'; - import { deleteAccount as deleteMongodbAccount, getPermissionRules as getMongodbPermissionRules } from '@services/source/mongodbPermissionAccount'; + import { deleteAccount as deleteMongodbAccount, deleteAccountRule as deleteMongodbAccountRule,getPermissionRules as getMongodbPermissionRules } from '@services/source/mongodbPermissionAccount'; import { deleteAccount as deleteMysqlAccount, getPermissionRules as getMysqlPermissionRules } from '@services/source/mysqlPermissionAccount'; import { deleteAccount as deleteSqlserverAccount, getPermissionRules as getSqlserverPermissionRules } from '@services/source/sqlserverPermissionAccount'; import { createTicket } from '@services/source/ticket'; @@ -143,7 +143,6 @@ * dbOperations 权限配置 * ddlSensitiveWords 敏感词 * dataSource 数据源 - * deleteAccount 删除账号api * createRuleComponent 创建规则组件 */ const configMap = { @@ -153,7 +152,6 @@ dbOperations: mysqlDbOperations[AccountTypes.MYSQL].dbOperations, ddlSensitiveWords: mysqlDbOperations[AccountTypes.MYSQL].ddlSensitiveWords, dataSource: getMysqlPermissionRules, - deleteAccount: deleteMysqlAccount, createRuleComponent: MysqlCreateRule, buttonController: { [ButtonTypes.EDIT_RULE]: true, @@ -166,7 +164,6 @@ dbOperations: mysqlDbOperations[AccountTypes.TENDBCLUSTER].dbOperations, ddlSensitiveWords: mysqlDbOperations[AccountTypes.TENDBCLUSTER].ddlSensitiveWords, dataSource: getMysqlPermissionRules, - deleteAccount: deleteMysqlAccount, createRuleComponent: MysqlCreateRule, buttonController: { [ButtonTypes.EDIT_RULE]: true, @@ -179,7 +176,6 @@ dbOperations: sqlserverDbOperations, ddlSensitiveWords: [], dataSource: getSqlserverPermissionRules, - deleteAccount: deleteSqlserverAccount, createRuleComponent: SqlserverCreateRule, buttonController: { [ButtonTypes.EDIT_RULE]: false, @@ -192,11 +188,10 @@ dbOperations: mongoDbOperations, ddlSensitiveWords: [], dataSource: getMongodbPermissionRules, - deleteAccount: deleteMongodbAccount, createRuleComponent: MongoCreateRule, buttonController: { [ButtonTypes.EDIT_RULE]: false, - [ButtonTypes.DELETE_RULE]: false, + [ButtonTypes.DELETE_RULE]: true, } }, }; @@ -488,12 +483,14 @@ content={t('删除规则会创建单据,需此规则所有过往调用方审批后才执行删除。')} title={t('确认删除该规则?')} trigger="click" - onConfirm={() => handleShowDeleteRule(data, index)} + disabled={props.accountType === AccountTypes.MONGODB} + onConfirm={() => handlePopDeleteRule(data, index)} > handleDeleteRule(data, index)} text> {t('删除')} @@ -580,13 +577,19 @@ * 删除账号 */ const handleDeleteAccount = (row: PermissionRule) => { + const apiMap = { + [AccountTypes.MYSQL]: deleteMysqlAccount, + [AccountTypes.TENDBCLUSTER]: deleteMysqlAccount, + [AccountTypes.SQLSERVER]: deleteSqlserverAccount, + [AccountTypes.MONGODB]: deleteMongodbAccount, + } InfoBox({ type: 'warning', title: t('确认删除该账号'), content: t('即将删除账号xx_删除后将不能恢复', { name: row.account.user }), onConfirm: async () => { try { - await configMap[props.accountType].deleteAccount({ + await apiMap[props.accountType]({ bizId: window.PROJECT_CONFIG.BIZ_ID, account_id: row.account.account_id, account_type: props.accountType, @@ -639,7 +642,7 @@ /** * 删除规则 */ - const handleShowDeleteRule = (row: PermissionRule, index: number) => { + const handlePopDeleteRule = (row: PermissionRule, index: number) => { const ticketTypeMap = { [AccountTypes.MYSQL]: TicketTypes.MYSQL_ACCOUNT_RULE_CHANGE, [AccountTypes.TENDBCLUSTER]: TicketTypes.TENDBCLUSTER_ACCOUNT_RULE_CHANGE, @@ -660,6 +663,22 @@ }, }); }; + + /** + * 删除规则(不需要审批) + */ + const handleDeleteRule = async (row: PermissionRule, index: number) => { + await deleteMongodbAccountRule({ + account_id: row.account.account_id, + account_type: props.accountType, + rule_id: row.rules[index].rule_id, + }); + Message({ + message: t('删除成功'), + theme: 'success', + }); + fetchData(); + };