Skip to content

Commit

Permalink
fix(frontend): 集群授权bug修复 TencentBlueKing#7703
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 22890
  • Loading branch information
JustaCattt authored and hLinx committed Nov 6, 2024
1 parent 6bfeab5 commit 346cd11
Show file tree
Hide file tree
Showing 24 changed files with 376 additions and 438 deletions.
4 changes: 3 additions & 1 deletion dbm-ui/frontend/src/components/ip-selector/IpSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
cloudInfo?: { id?: number | string; name?: string };
disableDialogSubmitMethod?: (hostList: Array<any>) => string | boolean;
disableHostMethod?: (...args: any) => string | boolean;
onlyAliveHost?: boolean;
serviceMode?: 'all' | 'idle_only';
panelList?: Array<'staticTopo' | 'manualInput' | 'dbmWhitelist'>;
disableTips?: string;
Expand All @@ -178,6 +179,7 @@
cloudInfo: () => ({}),
disableDialogSubmitMethod: () => false,
disableHostMethod: () => false,
onlyAliveHost: true,
serviceMode: 'idle_only',
panelList: () => ['staticTopo', 'manualInput'],
disableTips: '',
Expand Down Expand Up @@ -283,7 +285,7 @@
});

const disableHostMethodHandler = (data: any, selected: any[]) => {
if (data.alive === 0) {
if (props.onlyAliveHost && data.alive !== 1) {
return t('Agent异常无法使用');
}
if (props.osTypes.length > 0 && !props.osTypes.includes(Number(data.os_type))) {
Expand Down
7 changes: 2 additions & 5 deletions dbm-ui/frontend/src/services/model/ticket/details/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ export interface MysqlIpItem extends DetailBase {
export interface MysqlAuthorizationDetails extends DetailBase {
authorize_uid: string;
authorize_data: AuthorizePreCheckData;
// 批量导入
excel_url: string;
authorize_plugin_infos: Array<
AuthorizePreCheckData & {
bk_biz_id: number;
}
>;
authorize_data_list: AuthorizePreCheckData[];
}

export interface MySQLForceImportSQLFileExecuteSqlFiles {
Expand Down
10 changes: 6 additions & 4 deletions dbm-ui/frontend/src/services/types/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ export type AccountRulePrivilegeKey = keyof AccountRulePrivilege;
*/
export interface AuthorizePreCheckData {
access_dbs: string[];
source_ips?: {
bk_host_id?: number;
ip: string;
}[];
source_ips?:
| {
bk_host_id?: number;
ip: string;
}[]
| string[];
target_instances: string[];
user: string;
cluster_type: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
:is-show="isShow"
:quick-close="false"
:title="t('导入授权')"
:width="600">
:width="600"
@closed="handleCloseUpload">
<div class="excel-authorize">
<BkAlert
class="mb-12"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@
selected?: {
master_domain: string;
cluster_name: string;
cluster_type: ClusterTypes;
db_module_name?: string;
isMaster?: boolean;
}[];
clusterTypes?: ClusterTypes[];
clusterTypes?: string[];
rules?: PermissionRule['rules'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,29 @@
</div>
</template>
</BkTableColumn>
<BkTableColumn
:label="t('集群域名')"
:width="250">
<template #default="{ data }: { data: IDataRow }">
<div class="cell-cluster">
<p
v-for="(item, index) in data.clusterDomains"
:key="index">
{{ item }}
<DbIcon
v-if="index === 0"
type="copy"
@click="handleCopyDomains" />
</p>
</div>
</template>
</BkTableColumn>
<BkTableColumn
:label="t('账号')"
prop="account"
:width="150" />
<BkTableColumn
:label="t('访问的DB')"
:label="t('访问DB')"
:width="150">
<template #default="{ data }: { data: IDataRow }">
<div>
Expand All @@ -86,23 +103,6 @@
</div>
</template>
</BkTableColumn>
<BkTableColumn
:label="t('集群域名')"
:width="250">
<template #default="{ data }: { data: IDataRow }">
<div class="cell-cluster">
<p
v-for="(item, index) in data.clusterDomains"
:key="index">
{{ item }}
<DbIcon
v-if="index === 0"
type="copy"
@click="handleCopyDomains" />
</p>
</div>
</template>
</BkTableColumn>
<BkTableColumn
:label="t('权限')"
:width="350">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
button-text="添加 IP"
:data="selected"
:is-cloud-area-restrictions="false"
:only-alive-host="false"
:panel-list="['staticTopo', 'manualInput', 'dbmWhitelist']"
service-mode="all"
@change="handleChangeIP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@
interface Props {
accountType: AccountTypes;
clusterTypes: ClusterTypes[];
clusterTypes: string[];
data: {
master_domain: string;
cluster_name: string;
cluster_type: ClusterTypes;
db_module_name?: string;
isMaster?: boolean;
}[];
Expand Down Expand Up @@ -239,11 +240,18 @@
});
watch(
() => [props.clusterTypes, props.data],
() => props.data,
() => {
[state.clusterType] = props.clusterTypes;
updateTableData(props.data);
if (props.data.length > 0) {
state.clusterType = props.data[0].cluster_type;
nextTick(() => {
updateTableData(props.data);
})
}
},
{
immediate: true,
}
);
const handleShowTargetCluster = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
selected?: {
master_domain: string;
cluster_name: string;
cluster_type: ClusterTypes;
db_module_name?: string;
isMaster?: boolean;
}[];
clusterTypes?: ClusterTypes[];
clusterTypes?: string[];
rules?: PermissionRule['rules'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
selected: {
master_domain: string;
cluster_name: string;
cluster_type: ClusterTypes;
db_module_name?: string;
isMaster?: boolean;
}[];
clusterTypes: ClusterTypes[];
clusterTypes: string[];
}
interface Exposes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
selected?: {
master_domain: string;
cluster_name: string;
cluster_type: ClusterTypes;
db_module_name?: string;
isMaster?: boolean;
}[];
clusterTypes?: ClusterTypes[];
clusterTypes?: string[];
rules?: PermissionRule['rules'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
selected: {
master_domain: string;
cluster_name: string;
cluster_type: ClusterTypes;
db_module_name?: string;
isMaster?: boolean;
}[];
clusterTypes: ClusterTypes[];
clusterTypes: string[];
}
interface Exposes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
},
[AccountTypes.TENDBCLUSTER]: {
ticketType: TicketTypes.TENDBCLUSTER_AUTHORIZE_RULES,
clusterTypes: [ClusterTypes.TENDBCLUSTER],
clusterTypes: [ClusterTypes.TENDBCLUSTER, 'tendbclusterSlave'],
dbOperations: mysqlDbOperations[AccountTypes.TENDBCLUSTER].dbOperations,
dataSource: getMysqlPermissionRules,
deleteAccount: deleteMysqlAccount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,33 +184,6 @@
}
})

/**
* 创建时检验是否已存在规则
*/
const { run: preCheckAddAccountRuleRun } = useRequest(preCheckAddAccountRule, {
manual: true,
onSuccess: async ({ warning }) => {
if (warning) {
precheckWarnTip.value = (
<div class="pre-check-content">
{warning.split('\n').map(line => <div>{line}</div>)}
</div>
);
showPopConfirm.value = true;
return;
}
const params = await generateRequestParam();
createAccountRuleRun(params);
},
onError() {
messageError(t('提交失败'));
},
onAfter() {
isSubmitting.value = false;
handleClose();
}
});

/**
* 规则变更(有权限被删除)时走单据
*/
Expand Down Expand Up @@ -317,7 +290,22 @@
});
}
} else {
preCheckAddAccountRuleRun(params)
preCheckAddAccountRule(params)
.then((result) => {
if (result.warning) {
precheckWarnTip.value = (
<div class="pre-check-content">
{result.warning.split('\n').map(line => <div>{line}</div>)}
</div>
);
showPopConfirm.value = true;
return;
}
createAccountRuleRun(params);
})
.finally(() => {
isSubmitting.value = false;
});
}
};
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
:biz-id="currentBizId"
button-text=""
:data="localHostList"
:os-types="[OSTypes.Linux]"
:only-alive-host="false"
:panel-list="['staticTopo', 'dbmWhitelist', 'manualInput']"
service-mode="all"
:show-view="false"
Expand All @@ -55,7 +55,7 @@
import TendbhaModel from '@services/model/mysql/tendbha';
import type { HostInfo } from '@services/types/ip';
import { ClusterTypes, OSTypes } from '@common/const';
import { ClusterTypes } from '@common/const';
import ClusterSelector from '@components/cluster-selector/Index.vue';
import IpSelector, { type IPSelectorResult } from '@components/ip-selector/IpSelector.vue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
name: clusterData.bk_cloud_name,
}"
:data="localHostList"
:os-types="[OSTypes.Linux]"
:only-alive-host="false"
:panel-list="['staticTopo', 'dbmWhitelist', 'manualInput']"
service-mode="all"
:show-view="false"
Expand All @@ -95,9 +95,7 @@
import { useI18n } from 'vue-i18n';

import { checkHost } from '@services/source/ipchooser';
import type { HostInfo } from '@services/types/ip';

import { OSTypes } from '@common/const';
import type { HostInfo } from '@services/types';

import IpSelector, { type IPSelectorResult } from '@components/ip-selector/IpSelector.vue';
import RenderHost from '@components/render-table/columns/select-disable/index.vue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
:biz-id="currentBizId"
button-text=""
:data="selectedIps"
:os-types="[OSTypes.Linux]"
:only-alive-host="false"
service-mode="all"
:show-view="false"
@change="handleHostChange" />
Expand Down Expand Up @@ -84,7 +84,7 @@

import { useGlobalBizs } from '@stores';

import { OSTypes, TicketTypes } from '@common/const';
import { TicketTypes } from '@common/const';

import IpSelector from '@components/ip-selector/IpSelector.vue';
import TicketRemark from '@components/ticket-remark/Index.vue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
import { useI18n } from 'vue-i18n';

import { checkHost, getHostTopoInfos } from '@services/source/ipchooser';
import type { HostInfo } from '@services/types/ip';
import type { HostInfo } from '@services/types';

import { useGlobalBizs } from '@stores';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
:biz-id="currentBizId"
button-text=""
:data="localHostList"
:os-types="[OSTypes.Linux]"
:only-alive-host="false"
:panel-list="['staticTopo', 'dbmWhitelist', 'manualInput']"
service-mode="all"
:show-view="false"
Expand All @@ -56,7 +56,7 @@
import TendbClusterModel from '@services/model/tendbcluster/tendbcluster';
import type { HostInfo } from '@services/types';
import { ClusterTypes, OSTypes } from '@common/const';
import { ClusterTypes } from '@common/const';
import ClusterSelector from '@components/cluster-selector/Index.vue';
import IpSelector, { type IPSelectorResult } from '@components/ip-selector/IpSelector.vue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
name: clusterData.bk_cloud_name,
}"
:data="localHostList"
:os-types="[OSTypes.Linux]"
:only-alive-host="false"
:panel-list="['staticTopo', 'dbmWhitelist', 'manualInput']"
service-mode="all"
:show-view="false"
Expand All @@ -94,9 +94,7 @@
import _ from 'lodash';
import { useI18n } from 'vue-i18n';

import type { HostInfo } from '@services/types/ip';

import { OSTypes } from '@common/const';
import type { HostInfo } from '@services/types';

import IpSelector, { type IPSelectorResult } from '@components/ip-selector/IpSelector.vue';
import RenderHost from '@components/render-table/columns/select-disable/index.vue';
Expand Down
Loading

0 comments on commit 346cd11

Please sign in to comment.