Browse Source

Merge pull request #43 in DEC/decision-webui-dcm from ~ALAN/decision-webui-dcm:feature/10.0 to feature/10.0

* commit 'b3687829fa719ce68518940d80dafc7848b3197d':
  fix: BI-51537 未拥有编辑权限的不可编辑、删除、重命名、复制。
qufenxi
alan 5 years ago
parent
commit
96a31f953b
  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>',
}),
globals: {
'ts-jest': {
diagnostics: {
ignoreCodes: ['TS151001'],
},
},
DecCst: false,
},
};

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 { 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;
}

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

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

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 { 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'),
},
],

Loading…
Cancel
Save