Skip to content

Commit

Permalink
feat: 数据源用户重置密码
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri0528 committed Dec 22, 2023
1 parent 225589c commit 105852f
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,6 @@ cliff.toml
# igonre symlinks
src/bk-user/bkuser/idp_plugins
src/bk-login/bklogin/idp_plugins


pre-*-bkcodeai
91 changes: 91 additions & 0 deletions src/pages/src/components/ResetPassword.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<template>
<bk-dialog
:is-show="config.isShow"
:title="config.title"
theme="primary"
:quick-close="false"
:is-loading="isLoading"
@closed="$emit('closed')"
@confirm="confirm"
>
<bk-form
form-type="vertical"
ref="formRef"
:model="formData"
:rules="rules">
<bk-form-item label="新密码" property="password" required>
<div style="display: flex;">
<bk-input v-model="formData.password" />
<bk-button outline theme="primary" class="ml-[8px]" @click="handleRandomPassword">随机生成</bk-button>
</div>
</bk-form-item>
</bk-form>
</bk-dialog>
</template>

<script setup lang="ts">
import { Message } from 'bkui-vue';
import { reactive, ref, watch } from 'vue';
import useValidate from '@/hooks/use-validate';
import { putUsersPassword, randomPasswords } from '@/http/dataSourceFiles';
const validate = useValidate();
const emit = defineEmits(['closed', 'changePassword']);
const props = defineProps({
config: {
type: Object,
default: () => ({}),
},
});
const formRef = ref();
const formData = reactive({
password: '',
});
const isLoading = ref(false);
const rules = {
name: [validate.required],
};
watch(() => props.config?.isShow, (value: boolean) => {
if (value) {
formData.password = '';
}
});
const handleRandomPassword = async () => {
try {
const params = {
data_source_id: Number(props.config?.dataSourceId),
password_rule_config: {},
};
const passwordRes = await randomPasswords(params);
formData.password = passwordRes.data.password;
} catch (e) {
console.warn(e);
}
};
const confirm = async () => {
try {
await formRef.value.validate();
isLoading.value = true;
await putUsersPassword({
id: props.config?.userId,
password: formData.password,
});
emit('changePassword');
Message({ theme: 'success', message: '重置密码成功' });
} catch (e) {
isLoading.value = false;
} finally {
isLoading.value = false;
}
};
</script>

<style>
</style>
2 changes: 1 addition & 1 deletion src/pages/src/css/tenantViewStyle.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.details-info-wrapper {
height: calc(100vh - 140px);
padding-bottom: 24px;

.details-info-content {
padding: 24px;
Expand Down
9 changes: 8 additions & 1 deletion src/pages/src/http/dataSourceFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import type {
DataSourceUsersParams,
DataSourceUsersResult,
DepartmentsParams,
GeneratePasswordParams,
LeadersParams,
NewDataSourceParams,
NewDataSourceUserParams,
PutDataSourceParams,
PutDataSourceUserParams,
ResetPasswordParams,
SyncRecordsParams,
TestConnectionParams,
} from './types/dataSourceFiles';
Expand Down Expand Up @@ -99,7 +101,7 @@ export const postOperationsSync = (id: string) => http.post(`/api/v1/web/data-so
/**
* 生成数据源用户随机密码
*/
export const randomPasswords = () => http.post('/api/v1/web/data-sources/random-passwords/');
export const randomPasswords = (params: GeneratePasswordParams) => http.post('/api/v1/web/data-sources/random-passwords/', params);

/**
* 数据源更新记录
Expand All @@ -118,3 +120,8 @@ export const getSyncLogs = (id: string) => http.get(`/api/v1/web/data-sources/sy
* 数据源用户所属部门组织路径
*/
export const getOrganizationPaths = (id: string) => http.get(`/api/v1/web/data-sources/users/${id}/organization-paths/`);

/**
* 重置数据源用户密码
*/
export const putUsersPassword = (params: ResetPasswordParams) => http.put(`/api/v1/web/data-sources/users/${params.id}/password/`, params);
16 changes: 16 additions & 0 deletions src/pages/src/http/types/dataSourceFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,19 @@ export interface SyncRecordsParams {
pageSize: number,
status: string,
}

/**
* 生成数据源用户随机密码参数
*/
export interface GeneratePasswordParams {
data_source_id?: string,
password_rule_config?: {},
}

/**
* 数据源用户密码重置参数
*/
export interface ResetPasswordParams {
id: string,
password: string,
}
1 change: 0 additions & 1 deletion src/pages/src/views/data-source/LocalDataSource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ function handleClick(item) {
name: 'dataConfDetails',
params: {
id: item.id,
status: item.status,
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/src/views/data-source/local-details/PswInfo.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<bk-loading :loading="isLoading" class="details-info-wrapper user-scroll-y">
<bk-loading :loading="isLoading" class="details-info-wrapper">
<ul class="details-info-content" v-if="openPasswordLogin">
<li class="content-item">
<div class="item-header">
Expand Down
51 changes: 44 additions & 7 deletions src/pages/src/views/data-source/local-details/UserInfo.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<bk-loading :loading="isLoading" class="user-info-wrapper user-scroll-y">
<bk-loading :loading="isLoading" class="user-info-wrapper">
<header>
<div>
<template v-if="pluginId === 'local'">
Expand Down Expand Up @@ -80,10 +80,15 @@
>
编辑
</bk-button>
<!-- <bk-button theme="primary" text class="mr8">
<bk-button
v-if="isPasswordLogin"
theme="primary"
text
class="mr8"
@click="handleResetPassword(row)">
重置密码
</bk-button>
<bk-button theme="primary" text>
<!-- <bk-button theme="primary" text>
删除
</bk-button> -->
</template>
Expand All @@ -108,8 +113,12 @@
@click="handleClick('edit', detailsConfig)">
编辑
</bk-button>
<!-- <bk-button>重置</bk-button>
<bk-button>删除</bk-button> -->
<bk-button
v-if="isPasswordLogin"
@click="handleResetPassword(detailsConfig)">
重置密码
</bk-button>
<!-- <bk-button>删除</bk-button> -->
</div>
</template>
<template #default>
Expand Down Expand Up @@ -219,6 +228,10 @@
</div>
</template>
</bk-dialog>
<ResetPassword
:config="resetPasswordConfig"
@closed="closedResetPassword"
@changePassword="changePassword" />
</bk-loading>
</template>

Expand All @@ -233,6 +246,7 @@ import EditUser from './EditUser.vue';
import ViewUser from './ViewUser.vue';
import Empty from '@/components/Empty.vue';
import ResetPassword from '@/components/ResetPassword.vue';
import { useCustomFields } from '@/hooks/useCustomFields';
import { getDataSourceUserDetails, getDataSourceUsers, getOrganizationPaths } from '@/http/dataSourceFiles';
import { getFields } from '@/http/settingFiles';
Expand All @@ -247,6 +261,10 @@ const props = defineProps({
type: String,
default: '',
},
isPasswordLogin: {
type: Boolean,
default: false,
},
});
const editLeaveBefore = inject('editLeaveBefore');
Expand Down Expand Up @@ -570,13 +588,32 @@ const tipsShowFn = async (id: string) => {
tipsText.value = '';
}
};
const resetPasswordConfig = reactive({
isShow: false,
title: '重置密码',
dataSourceId: props.dataSourceId,
userId: '',
});
const handleResetPassword = (item: any) => {
resetPasswordConfig.isShow = true;
resetPasswordConfig.userId = item.id;
};
const closedResetPassword = () => {
resetPasswordConfig.isShow = false;
};
const changePassword = () => {
resetPasswordConfig.isShow = false;
};
</script>

<style lang="less" scoped>
.user-info-wrapper {
width: 100%;
height: calc(100vh - 140px);
padding: 24px;
padding-bottom: 24px;
header {
display: flex;
Expand Down
36 changes: 34 additions & 2 deletions src/pages/src/views/data-source/local-details/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
@change="changeTab"
>
<bk-tab-panel name="user" label="用户信息">
<UserInfo v-if="activeKey === 'user'" :data-source-id="currentId" :plugin-id="pluginId" />
<UserInfo
v-if="activeKey === 'user'"
:data-source-id="currentId"
:plugin-id="pluginId"
:is-password-login="isPasswordLogin" />
</bk-tab-panel>
<bk-tab-panel :visible="pluginId === 'local'" name="account" label="账密信息">
<PswInfo v-if="activeKey === 'account'" />
Expand All @@ -52,7 +56,13 @@ import PswInfo from './PswInfo.vue';
import UserInfo from './UserInfo.vue';
import MainBreadcrumbsDetails from '@/components/layouts/MainBreadcrumbsDetails.vue';
import { changeSwitchStatus, getDataSourceList, getDataSourcePlugins, postOperationsSync } from '@/http/dataSourceFiles';
import {
changeSwitchStatus,
getDataSourceDetails,
getDataSourceList,
getDataSourcePlugins,
postOperationsSync,
} from '@/http/dataSourceFiles';
import router from '@/router/index';
const route = useRoute();
Expand All @@ -66,6 +76,8 @@ const subtitle = ref('');
const statusText = ref('');
const typeList = ref([]);
const pluginId = ref('');
// 是否开启账密登录
const isPasswordLogin = ref(false);
onMounted(async () => {
isLoading.value = true;
Expand All @@ -78,6 +90,8 @@ onMounted(async () => {
}
});
const pluginsRes = await getDataSourcePlugins();
const loginRes = await getDataSourceDetails(currentId?.value);
isPasswordLogin.value = loginRes.data?.plugin_config?.enable_account_password_login;
typeList.value = pluginsRes.data;
isLoading.value = false;
});
Expand Down Expand Up @@ -140,4 +154,22 @@ const toBack = () => {
padding-right: 10px;
}
}
::v-deep .tab-details {
.bk-tab-content {
height: calc(100vh - 140px);
padding: 24px;
overflow-y: auto;
&::-webkit-scrollbar {
width: 4px;
background-color: transparent;
}
&::-webkit-scrollbar-thumb {
background-color: #dcdee5;
border-radius: 4px;
}
}
}
</style>
2 changes: 1 addition & 1 deletion src/pages/src/views/data-source/new-data/Local.vue
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ const changeAccountPassword = (value) => {
const handleRandomPassword = async () => {
try {
const passwordRes = await randomPasswords();
const passwordRes = await randomPasswords({});
formData.config.password_initial.fixed_password = passwordRes.data.password;
window.changeInput = true;
} catch (e) {
Expand Down
5 changes: 5 additions & 0 deletions src/pages/src/views/organization/details/DetailsInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,9 @@ const updateTenantsList = () => {

<style lang="less" scoped>
@import url("@/css/tenantViewStyle.less");
.details-info-wrapper {
height: calc(100vh - 140px);
padding-bottom: 0;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ const handleChange = () => {
const handleRandomPassword = async () => {
try {
const passwordRes = await randomPasswords();
const passwordRes = await randomPasswords({});
formData.password_initial_config.fixed_password = passwordRes.data.password;
window.changeInput = true;
} catch (e) {
Expand Down

0 comments on commit 105852f

Please sign in to comment.