Skip to content

Commit

Permalink
feat(frontend): 临时密码异步修改 TencentBlueKing#7031
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 22964
  • Loading branch information
JustaCattt committed Nov 6, 2024
1 parent 59806a4 commit 37bc610
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 53 deletions.
1 change: 1 addition & 0 deletions dbm-ui/frontend/src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3630,5 +3630,6 @@
"请按行输入IP,每行代表一个单元格的值。多个IP用逗号、空格、|分隔": "请按行输入IP,每行代表一个单元格的值。多个IP用逗号、空格、|分隔",
"无只读主机": "无只读主机",
"批量录入:按行录入,快速批量输入多个单元格的值": "批量录入:按行录入,快速批量输入多个单元格的值",
"指定特殊字符(s)": "指定特殊字符(s)",
"这行勿动!新增翻译请在上一行添加!": ""
}
42 changes: 30 additions & 12 deletions dbm-ui/frontend/src/services/source/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,38 @@ interface AdminPasswordResultItem {
}[];
}

const path = '/apis/conf/password_policy';

/**
* 查询密码安全策略
*/
export const getPasswordPolicy = (params: { name: string }) =>
http.get<PasswordPolicy>('/apis/conf/password_policy/get_password_policy/', params);
http.get<PasswordPolicy>(`${path}/get_password_policy/`, params);

/**
* 更新密码安全策略
*/
export const updatePasswordPolicy = (params: PasswordPolicy & { reset: boolean }) =>
http.post('/apis/conf/password_policy/update_password_policy/', params);
http.post(`${path}/update_password_policy/`, params);

/**
* 查询随机化周期
*/
export const queryRandomCycle = (params = {}, payload = {} as IRequestPayload) =>
http.get<RamdomCycle>('/apis/conf/password_policy/query_random_cycle/', params, payload);
http.get<RamdomCycle>(`${path}/query_random_cycle/`, params, payload);

/**
* 更新随机化周期
*/
export const modifyRandomCycle = (params: RamdomCycle) =>
http.post('/apis/conf/password_policy/modify_random_cycle/', params);
export const modifyRandomCycle = (params: RamdomCycle) => http.post(`${path}/modify_random_cycle/`, params);

/**
* 获取符合密码强度的字符串
*/
export const getRandomPassword = (params?: { security_type: string }) =>
http.get<{
password: string;
}>('/apis/conf/password_policy/get_random_password/', params);
}>(`${path}/get_random_password/`, params);

/**
* 修改实例密码(admin)
Expand All @@ -85,11 +86,16 @@ export const modifyAdminPassword = (params: {
cluster_type: ClusterTypes;
role: string;
}[];
// 是否异步
is_async?: boolean;
}) =>
http.post<{
success: AdminPasswordResultItem[] | null;
fail: AdminPasswordResultItem[] | null;
}>('/apis/conf/password_policy/modify_admin_password/', params);
http.post<
| {
success: AdminPasswordResultItem[] | null;
fail: AdminPasswordResultItem[] | null;
}
| string // 异步修改时返回root_id
>(`${path}/modify_admin_password/`, params);

/**
* 查询生效实例密码(admin)
Expand All @@ -102,11 +108,23 @@ export const queryAdminPassword = (params: {
instances?: string;
db_type?: DBTypes;
}) =>
http.post<ListBase<AdminPasswordModel[]>>('/apis/conf/password_policy/query_admin_password/', params).then((res) => ({
http.post<ListBase<AdminPasswordModel[]>>(`${path}/query_admin_password/`, params).then((res) => ({
...res,
results: res.results.map((item) => new AdminPasswordModel(item)),
}));

/**
* 查询异步密码修改执行结果
*/
export const queryAsyncModifyResult = (params: { root_id: string }) =>
http.post<{
data: {
success: AdminPasswordResultItem[] | null;
fail: AdminPasswordResultItem[] | null;
};
status: string;
}>(`${path}/query_async_modify_result/`, params);

/**
* 获取公钥列表
*/
Expand All @@ -123,4 +141,4 @@ export const getRSAPublicKeys = (params: { names: string[] }) =>
* 校验密码强度
*/
export const verifyPasswordStrength = (params: { security_type: string; password: string }) =>
http.post<PasswordStrength>('/apis/conf/password_policy/verify_password_strength/', params);
http.post<PasswordStrength>(`${path}/verify_password_strength/`, params);
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@
},
});
const { run: getPasswordPolicyRun } = useRequest(getPasswordPolicy, {
manual: true,
useRequest(getPasswordPolicy, {
defaultParams: [{ name: passwordParam.value }],
onSuccess(data) {
const {
min_length: minLength,
Expand Down Expand Up @@ -198,6 +198,13 @@
},
});
watch(
() => props.dbType,
() => {
modelValue.value = '';
},
);
/**
* 获取加密密码
*/
Expand Down Expand Up @@ -287,18 +294,6 @@
tippyInstance.hide();
};
watch(modelValue, () => {
if (modelValue.value) {
debounceVerifyPassword();
}
});
onMounted(() => {
getPasswordPolicyRun({
name: passwordParam.value,
});
});
onUnmounted(() => {
tippyInstance.destroy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@
<template>
<SmartAction :offset-target="getSmartActionOffsetTarget">
<div class="password-temporary-modify">
<div
v-if="submitting"
class="submitting-mask">
<DbIcon
class="submitting-icon"
svg
type="sync-pending" />
<p class="submitting-text">
{{ t('密码正在修改中,请稍等') }}
</p>
</div>
<UpdateResult
v-else-if="submitted"
:password="formData.password"
:submit-length="submitLength"
:submit-res="submitRes"
:submit-role-map="submitRoleMap"
@refresh="handleRefresh"
@retry="handleSubmit" />
<template v-if="submitted">
<div
v-if="queryLoading"
class="submitting-mask">
<DbIcon
class="submitting-icon"
svg
type="sync-pending" />
<p class="submitting-text">
{{ t('密码正在修改中,请稍等') }}
</p>
</div>
<UpdateResult
v-else
:password="formData.password"
:submit-length="submitLength"
:submit-res="modifyResult"
:submit-role-map="submitRoleMap"
@refresh="handleRefresh"
@retry="handleSubmit" />
</template>
<DbForm
v-else
ref="formRef"
Expand Down Expand Up @@ -81,17 +83,21 @@
import { useI18n } from 'vue-i18n';
import { useRequest } from 'vue-request';

import { modifyAdminPassword } from '@services/source/permission';
import { modifyAdminPassword, queryAsyncModifyResult } from '@services/source/permission';

import { ClusterTypes, DBTypes } from '@common/const';

import PasswordInput from '@views/db-manage/common/password-input/Index.vue';

import { useTimeoutPoll } from '@vueuse/core';

import InstanceList from './components/form-item/InstanceList.vue';
import ValidDuration from './components/form-item/ValidDuration.vue';
import RenderPasswordInstance from './components/render-passwrod-instance/Index.vue';
import UpdateResult from './components/UpdateResult.vue';

type ModifyAdminPassword = ServiceReturnType<typeof modifyAdminPassword>;

const { t } = useI18n();

const createDefaultData = () => ({
Expand Down Expand Up @@ -130,23 +136,47 @@
},
);

const {
loading: submitting,
run: modifyAdminPasswordRun,
data: submitRes,
} = useRequest(modifyAdminPassword, {
const currentScope = getCurrentScope();
const rootId = ref('');
const modifyResult = ref<ModifyAdminPassword>();

const { run: queryAsyncModifyResultRun, loading: queryLoading } = useRequest(queryAsyncModifyResult, {
manual: true,
onSuccess({ data, status }) {
modifyResult.value = data;
// 设置轮询
if (currentScope?.active) {
!isActive.value && ['PENDING', 'RUNNING', 'FINISHED'].includes(status) && resume();
} else {
pause();
}
},
onError() {
modifyResult.value = {} as ModifyAdminPassword;
},
});

// 轮询
const { isActive, resume, pause } = useTimeoutPoll(() => {
queryAsyncModifyResultRun({
root_id: rootId.value,
});
}, 10000);

const { run: modifyAdminPasswordRun, loading: submitting } = useRequest(modifyAdminPassword, {
manual: true,
onSuccess() {
onSuccess(data) {
submitted.value = true;
window.changeConfirm = false;
rootId.value = data as string;
resume();
},
});

const getSmartActionOffsetTarget = () => document.querySelector('.bk-form-content');

const submitValidator = async () => {
await formRef.value.validate();

handleSubmit(formData.instanceList);
};

Expand Down Expand Up @@ -183,6 +213,7 @@
lock_hour: lockHour,
password: formData.password,
instance_list: instanceListParam,
is_async: true,
};

submitLength.value = instanceListParam.length;
Expand Down

0 comments on commit 37bc610

Please sign in to comment.