From b3687829fa719ce68518940d80dafc7848b3197d Mon Sep 17 00:00:00 2001 From: alan Date: Thu, 12 Sep 2019 10:33:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20BI-51537=20=E6=9C=AA=E6=8B=A5=E6=9C=89?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=9D=83=E9=99=90=E7=9A=84=E4=B8=8D=E5=8F=AF?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E3=80=81=E5=88=A0=E9=99=A4=E3=80=81=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E3=80=81=E5=A4=8D=E5=88=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jest.config.js | 6 +-- src/modules/__test__/app.test.ts | 48 +++++++++++++++++++ src/modules/app.service.ts | 10 ++++ src/modules/crud/crud.typings.d.ts | 4 ++ src/modules/pages/connection/connection.ts | 5 +- .../connection/list/list_item/list_item.ts | 9 +++- 6 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 src/modules/__test__/app.test.ts diff --git a/jest.config.js b/jest.config.js index ce14d8a..e869435 100644 --- a/jest.config.js +++ b/jest.config.js @@ -17,10 +17,6 @@ module.exports = { prefix: '', }), globals: { - 'ts-jest': { - diagnostics: { - ignoreCodes: ['TS151001'], - }, - }, + DecCst: false, }, }; diff --git a/src/modules/__test__/app.test.ts b/src/modules/__test__/app.test.ts new file mode 100644 index 0000000..5b8cf72 --- /dev/null +++ b/src/modules/__test__/app.test.ts @@ -0,0 +1,48 @@ +import { connectionCanEdit } from '../app.service'; +const connection = { + connectionId: '', + connectionType: '', + connectionName: '', + connectionData: '', +}; + +test('BI-51537 判断数据连接是否有权限', () => { + expect(connectionCanEdit({ + ...connection, + })).toEqual(true); + + expect(connectionCanEdit({ + ...connection, + privilegeDetailBeanList: null, + })).toEqual(true); + + expect(connectionCanEdit({ + ...connection, + privilegeDetailBeanList: [ + { + privilegeType: 4, + privilegeValue: 2, + }, + ], + })).toEqual(true); + + expect(connectionCanEdit({ + ...connection, + privilegeDetailBeanList: [ + { + privilegeType: 4, + privilegeValue: 1, + }, + ], + })).toEqual(false); + + expect(connectionCanEdit({ + ...connection, + privilegeDetailBeanList: [ + { + privilegeType: 2, + privilegeValue: 1, + }, + ], + })).toEqual(false); +}); diff --git a/src/modules/app.service.ts b/src/modules/app.service.ts index d919bf7..adbf831 100644 --- a/src/modules/app.service.ts +++ b/src/modules/app.service.ts @@ -1,6 +1,7 @@ import { DATA_BASE_TYPES, DATA_BASE_TYPES_OTHER } from '@constants/constant'; import { CONSTANT_PLUGIN_TYPES, CONSTANT_PLUGIN_SHOW, CONSTANT_PLUGIN_EDIT } from '@constants/plugin'; import { DatabaseType } from './app.typings'; +import { Connection } from './crud/crud.typings'; export function getAllDatabaseTypes():DatabaseType[] { return [ ...DATA_BASE_TYPES, @@ -76,3 +77,12 @@ export function resolveUrlInfo (url: string) { urlInfo: '', }; } + +export function connectionCanEdit(connection: Connection) { + if (connection.privilegeDetailBeanList) { + // privilegeType === 4 代表编辑权限,privilegeValue === 2 代表有权限 + return connection.privilegeDetailBeanList.some(item => item.privilegeType === 4 && item.privilegeValue === 2); + } + + return true; +} diff --git a/src/modules/crud/crud.typings.d.ts b/src/modules/crud/crud.typings.d.ts index 0e3ecf6..00c1f1e 100644 --- a/src/modules/crud/crud.typings.d.ts +++ b/src/modules/crud/crud.typings.d.ts @@ -19,6 +19,10 @@ export interface Connection { connectionType: string; connectionName: string; connectionData: ConnectionJDBC | ConnectionJNDI | ConnectionPlugin | string; + privilegeDetailBeanList?: { + privilegeType: number; + privilegeValue: number; + }[] } export interface ConnectionJDBC { diff --git a/src/modules/pages/connection/connection.ts b/src/modules/pages/connection/connection.ts index 088bcd3..338126c 100644 --- a/src/modules/pages/connection/connection.ts +++ b/src/modules/pages/connection/connection.ts @@ -7,7 +7,7 @@ import { ConnectionJdbcXtype } from './connection_jdbc/connection_jdbc'; import { ConnectionJndiXtype } from './connection_jndi/connection_jndi'; import { ConnectionPluginXtype } from './connection_plugin/connection_plugin'; import { connectionType } from '@constants/env'; -import { getAllDatabaseTypes } from '../../app.service'; +import { getAllDatabaseTypes, connectionCanEdit } from '../../app.service'; export const ConnectionXtype = 'dec.dcm.connection'; @shortcut(ConnectionXtype) @@ -23,8 +23,9 @@ export class Connection extends BI.Widget { watch = { connectionSelected:(name: string) => { + const canEdit = connectionCanEdit(this.model.connectionSelectedOne); this.connectionTitleWidget.setText(`${name}`); - this.connectionEditWidget.setVisible(!!name); + this.connectionEditWidget.setVisible(!!name && canEdit); if (name) { const hasRegistered = this.hasRegistered(); this.title.setVisible(hasRegistered); diff --git a/src/modules/pages/connection/list/list_item/list_item.ts b/src/modules/pages/connection/list/list_item/list_item.ts index 4ff7652..ee039f6 100644 --- a/src/modules/pages/connection/list/list_item/list_item.ts +++ b/src/modules/pages/connection/list/list_item/list_item.ts @@ -7,6 +7,8 @@ import { TestStatusXtype, TestStatus, EVENT_CLOSE, EVENT_RELOAD } from 'src/modu import { hasRegistered } from '../list.service'; import { connectionType } from '@constants/env'; import { ConnectionJDBC } from 'src/modules/crud/crud.typings'; +import { connectionCanEdit } from '../../../../app.service'; + export const ListItemXtype = 'dec.dcm.connection.list_item'; @shortcut(ListItemXtype) @store(ListItemModelXtype) @@ -101,7 +103,8 @@ export class ListItem extends BI.BasicButton { } private renderDownList() { - const { creator, databaseType } = this.options; + const { creator, databaseType, name } = this.options; + const canEdit = connectionCanEdit(this.model.connections.find(item => item.connectionName === name)); const isRegistered = hasRegistered(databaseType); const otherIcons = [ { @@ -129,21 +132,25 @@ export class ListItem extends BI.BasicButton { text: BI.i18nText('Dec-Dcm_Edit'), cls: 'dcm-link-edit-font', value: 'edit', + invisible: !canEdit, }, { text: BI.i18nText('Dec-Dcm_Change_Name'), cls: 'dcm-change-name-font', value: 'changeName', + invisible: !canEdit, }, { text: BI.i18nText('Dec-Dcm_Copy'), cls: 'copy-font', value: 'copy', + invisible: !canEdit, }, { text: BI.i18nText('Dec-Dcm_Delete'), cls: 'dcm-delete-font', value: 'delete', + invisible: !canEdit, bubble: BI.i18nText('Dec-Dcm_Connection_Make_Sure_Delete'), }, ],