Browse Source

fix: BI-51537 未拥有编辑权限的不可编辑、删除、重命名、复制。

qufenxi
alan 5 years ago
parent
commit
b3687829fa
  1. 6
      jest.config.js
  2. 48
      src/modules/__test__/app.test.ts
  3. 10
      src/modules/app.service.ts
  4. 4
      src/modules/crud/crud.typings.d.ts
  5. 5
      src/modules/pages/connection/connection.ts
  6. 9
      src/modules/pages/connection/list/list_item/list_item.ts

6
jest.config.js

@ -17,10 +17,6 @@ module.exports = {
prefix: '<rootDir>', prefix: '<rootDir>',
}), }),
globals: { globals: {
'ts-jest': { DecCst: false,
diagnostics: {
ignoreCodes: ['TS151001'],
},
},
}, },
}; };

48
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);
});

10
src/modules/app.service.ts

@ -1,6 +1,7 @@
import { DATA_BASE_TYPES, DATA_BASE_TYPES_OTHER } from '@constants/constant'; 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 { CONSTANT_PLUGIN_TYPES, CONSTANT_PLUGIN_SHOW, CONSTANT_PLUGIN_EDIT } from '@constants/plugin';
import { DatabaseType } from './app.typings'; import { DatabaseType } from './app.typings';
import { Connection } from './crud/crud.typings';
export function getAllDatabaseTypes():DatabaseType[] { export function getAllDatabaseTypes():DatabaseType[] {
return [ return [
...DATA_BASE_TYPES, ...DATA_BASE_TYPES,
@ -76,3 +77,12 @@ export function resolveUrlInfo (url: string) {
urlInfo: '', 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;
}

4
src/modules/crud/crud.typings.d.ts vendored

@ -19,6 +19,10 @@ export interface Connection {
connectionType: string; connectionType: string;
connectionName: string; connectionName: string;
connectionData: ConnectionJDBC | ConnectionJNDI | ConnectionPlugin | string; connectionData: ConnectionJDBC | ConnectionJNDI | ConnectionPlugin | string;
privilegeDetailBeanList?: {
privilegeType: number;
privilegeValue: number;
}[]
} }
export interface ConnectionJDBC { export interface ConnectionJDBC {

5
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 { ConnectionJndiXtype } from './connection_jndi/connection_jndi';
import { ConnectionPluginXtype } from './connection_plugin/connection_plugin'; import { ConnectionPluginXtype } from './connection_plugin/connection_plugin';
import { connectionType } from '@constants/env'; import { connectionType } from '@constants/env';
import { getAllDatabaseTypes } from '../../app.service'; import { getAllDatabaseTypes, connectionCanEdit } from '../../app.service';
export const ConnectionXtype = 'dec.dcm.connection'; export const ConnectionXtype = 'dec.dcm.connection';
@shortcut(ConnectionXtype) @shortcut(ConnectionXtype)
@ -23,8 +23,9 @@ export class Connection extends BI.Widget {
watch = { watch = {
connectionSelected:(name: string) => { connectionSelected:(name: string) => {
const canEdit = connectionCanEdit(this.model.connectionSelectedOne);
this.connectionTitleWidget.setText(`${name}`); this.connectionTitleWidget.setText(`${name}`);
this.connectionEditWidget.setVisible(!!name); this.connectionEditWidget.setVisible(!!name && canEdit);
if (name) { if (name) {
const hasRegistered = this.hasRegistered(); const hasRegistered = this.hasRegistered();
this.title.setVisible(hasRegistered); this.title.setVisible(hasRegistered);

9
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 { hasRegistered } from '../list.service';
import { connectionType } from '@constants/env'; import { connectionType } from '@constants/env';
import { ConnectionJDBC } from 'src/modules/crud/crud.typings'; import { ConnectionJDBC } from 'src/modules/crud/crud.typings';
import { connectionCanEdit } from '../../../../app.service';
export const ListItemXtype = 'dec.dcm.connection.list_item'; export const ListItemXtype = 'dec.dcm.connection.list_item';
@shortcut(ListItemXtype) @shortcut(ListItemXtype)
@store(ListItemModelXtype) @store(ListItemModelXtype)
@ -101,7 +103,8 @@ export class ListItem extends BI.BasicButton {
} }
private renderDownList() { 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 isRegistered = hasRegistered(databaseType);
const otherIcons = [ const otherIcons = [
{ {
@ -129,21 +132,25 @@ export class ListItem extends BI.BasicButton {
text: BI.i18nText('Dec-Dcm_Edit'), text: BI.i18nText('Dec-Dcm_Edit'),
cls: 'dcm-link-edit-font', cls: 'dcm-link-edit-font',
value: 'edit', value: 'edit',
invisible: !canEdit,
}, },
{ {
text: BI.i18nText('Dec-Dcm_Change_Name'), text: BI.i18nText('Dec-Dcm_Change_Name'),
cls: 'dcm-change-name-font', cls: 'dcm-change-name-font',
value: 'changeName', value: 'changeName',
invisible: !canEdit,
}, },
{ {
text: BI.i18nText('Dec-Dcm_Copy'), text: BI.i18nText('Dec-Dcm_Copy'),
cls: 'copy-font', cls: 'copy-font',
value: 'copy', value: 'copy',
invisible: !canEdit,
}, },
{ {
text: BI.i18nText('Dec-Dcm_Delete'), text: BI.i18nText('Dec-Dcm_Delete'),
cls: 'dcm-delete-font', cls: 'dcm-delete-font',
value: 'delete', value: 'delete',
invisible: !canEdit,
bubble: BI.i18nText('Dec-Dcm_Connection_Make_Sure_Delete'), bubble: BI.i18nText('Dec-Dcm_Connection_Make_Sure_Delete'),
}, },
], ],

Loading…
Cancel
Save