Skip to content

Commit

Permalink
PullRequest: 485 fix/dev-4.3.1-table-roles
Browse files Browse the repository at this point in the history
Merge branch 'fix/dev-4.3.1-table-roles of [email protected]:oceanbase/oceanbase-developer-center.git into dev-4.3.1

https://code.alipay.com/oceanbase/oceanbase-developer-center/pull_requests/485


Signed-off-by: 晓康 <[email protected]>


* fix: change database select permission function to adapt to table roles
* fix: use 'type' field to control btn when sql execute error
  • Loading branch information
yezaoshu committed Jul 29, 2024
1 parent cb327fd commit 30b4692
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/component/Task/helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ export { TaskTypeMap } from '@/component/Task/component/TaskTable';
export const ENABLED_SYS_FROM_ITEM = false;

export const hasPermission = (taskType: TaskType, permissions: DatabasePermissionType[]) => {
/* 如果有ACCESS(没有库权限, 只有库下的某个表权限), 则先全部粗颗粒放开 */
if (permissions.includes(DatabasePermissionType.ACCESS)) {
return permissions?.length > 0; // 考虑有表没有库权限的情况
}
let _permissions = [];
switch (taskType) {
case TaskType.EXPORT:
return permissions?.length > 0; // 考虑有表没有库权限的情况
_permissions = [DatabasePermissionType.EXPORT];
break;
case TaskType.EXPORT_RESULT_SET:
return permissions?.length > 0; // 考虑有表没有库权限的情况
case TaskType.ASYNC:
return permissions?.length > 0; // 考虑有表没有库权限的情况
_permissions = [DatabasePermissionType.EXPORT, DatabasePermissionType.QUERY];
break;
default:
_permissions = [DatabasePermissionType.CHANGE];
}
Expand Down
6 changes: 6 additions & 0 deletions src/d.ts/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ export enum TablePermissionType {
EXPORT = 'EXPORT',
}

export enum UnauthorizedPermissionTypeInSQLExecute {
ODC_TABLE = 'ODC_TABLE',
ODC_DATABASE = 'ODC_DATABASE',
}

export interface IUnauthorizedDBResources {
unauthorizedPermissionTypes: (DatabasePermissionType & TablePermissionType)[];
dataSourceId: number;
Expand All @@ -220,6 +225,7 @@ export interface IUnauthorizedDBResources {
tableName: string;
tableId: number;
applicable: boolean;
type: UnauthorizedPermissionTypeInSQLExecute;
}
export interface IColumnStoreServerType {
allColumns?: boolean;
Expand Down
13 changes: 10 additions & 3 deletions src/page/Workspace/components/SQLResultSet/DBPermissionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import { CloseCircleFilled } from '@ant-design/icons';
import { ModalStore } from '@/store/modal';
import DisplayTable from '@/component/DisplayTable';
import { DatabasePermissionType } from '@/d.ts/database';
import { IUnauthorizedDBResources, TablePermissionType } from '@/d.ts/table';
import {
IUnauthorizedDBResources,
TablePermissionType,
UnauthorizedPermissionTypeInSQLExecute,
} from '@/d.ts/table';
import Action from '@/component/Action';
import { permissionOptionsMap } from '@/component/Task/ApplyDatabasePermission';
import MultiLineOverflowText from '@/component/MultiLineOverflowText';
Expand Down Expand Up @@ -76,6 +80,9 @@ const getColumns = (
ellipsis: true,
render: (action, _) => {
const dbDisabled = !_.applicable;
const isTablePermissionError = _.type === UnauthorizedPermissionTypeInSQLExecute.ODC_TABLE;
const isDatabasePermissionError =
_.type === UnauthorizedPermissionTypeInSQLExecute.ODC_DATABASE;
let dbTooltip = null,
tableTooltip = null;
if (dbDisabled) {
Expand All @@ -99,7 +106,7 @@ const getColumns = (
return (
<Action.Group size={2}>
<Action.Link
disabled={dbDisabled}
disabled={dbDisabled || !isDatabasePermissionError}
tooltip={dbTooltip}
key="applyDatabase"
onClick={async () => {
Expand All @@ -114,7 +121,7 @@ const getColumns = (
{
<Action.Link
key="applyTable"
disabled={dbDisabled || !_?.tableName}
disabled={dbDisabled || !isTablePermissionError}
tooltip={tableTooltip}
onClick={async () => {
applyTableTask?.(
Expand Down

0 comments on commit 30b4692

Please sign in to comment.