feat(系统管理): 切换语言时后台用户信息进行记录
This commit is contained in:
parent
685e5d9934
commit
47e57788f4
|
@ -1,6 +1,7 @@
|
||||||
package io.metersphere.system.controller;
|
package io.metersphere.system.controller;
|
||||||
|
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
|
import io.metersphere.system.dto.request.user.PersonalLocaleRequest;
|
||||||
import io.metersphere.system.dto.request.user.PersonalUpdatePasswordRequest;
|
import io.metersphere.system.dto.request.user.PersonalUpdatePasswordRequest;
|
||||||
import io.metersphere.system.dto.request.user.PersonalUpdateRequest;
|
import io.metersphere.system.dto.request.user.PersonalUpdateRequest;
|
||||||
import io.metersphere.system.dto.user.PersonalDTO;
|
import io.metersphere.system.dto.user.PersonalDTO;
|
||||||
|
@ -40,6 +41,12 @@ PersonalCenterController {
|
||||||
return simpleUserService.updateAccount(request, SessionUtils.getUserId());
|
return simpleUserService.updateAccount(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/update-locale")
|
||||||
|
@Operation(summary = "个人中心-修改信息")
|
||||||
|
public void updateLocale(@Validated @RequestBody PersonalLocaleRequest request) {
|
||||||
|
simpleUserService.updateLanguage(request, SessionUtils.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/update-password")
|
@PostMapping("/update-password")
|
||||||
@Operation(summary = "个人中心-修改密码")
|
@Operation(summary = "个人中心-修改密码")
|
||||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updatePasswordLog(#request)", msClass = UserLogService.class)
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updatePasswordLog(#request)", msClass = UserLogService.class)
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package io.metersphere.system.dto.request.user;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.Pattern;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PersonalLocaleRequest {
|
||||||
|
@Schema(description = "国际化", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@Pattern(regexp = "(zh-CN)|(en-US)", message = "locale格式不正确")
|
||||||
|
@NotEmpty
|
||||||
|
private String language;
|
||||||
|
}
|
|
@ -14,10 +14,7 @@ import io.metersphere.system.dto.excel.UserExcel;
|
||||||
import io.metersphere.system.dto.excel.UserExcelRowDTO;
|
import io.metersphere.system.dto.excel.UserExcelRowDTO;
|
||||||
import io.metersphere.system.dto.request.UserInviteRequest;
|
import io.metersphere.system.dto.request.UserInviteRequest;
|
||||||
import io.metersphere.system.dto.request.UserRegisterRequest;
|
import io.metersphere.system.dto.request.UserRegisterRequest;
|
||||||
import io.metersphere.system.dto.request.user.PersonalUpdatePasswordRequest;
|
import io.metersphere.system.dto.request.user.*;
|
||||||
import io.metersphere.system.dto.request.user.PersonalUpdateRequest;
|
|
||||||
import io.metersphere.system.dto.request.user.UserChangeEnableRequest;
|
|
||||||
import io.metersphere.system.dto.request.user.UserEditRequest;
|
|
||||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||||
import io.metersphere.system.dto.sdk.ExcelParseDTO;
|
import io.metersphere.system.dto.sdk.ExcelParseDTO;
|
||||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||||
|
@ -558,6 +555,12 @@ public class SimpleUserService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateLanguage(PersonalLocaleRequest request, String operator) {
|
||||||
|
User editUser = new User();
|
||||||
|
editUser.setId(operator);
|
||||||
|
editUser.setLanguage(request.getLanguage());
|
||||||
|
userMapper.updateByPrimaryKeySelective(editUser);
|
||||||
|
}
|
||||||
public boolean updateAccount(PersonalUpdateRequest request, String operator) {
|
public boolean updateAccount(PersonalUpdateRequest request, String operator) {
|
||||||
this.checkUserEmail(request.getId(), request.getEmail());
|
this.checkUserEmail(request.getId(), request.getEmail());
|
||||||
User editUser = new User();
|
User editUser = new User();
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class UserLogService {
|
||||||
.method(HttpMethodConstants.POST.name())
|
.method(HttpMethodConstants.POST.name())
|
||||||
.path("/personal/update-password")
|
.path("/personal/update-password")
|
||||||
.sourceId(request.getId())
|
.sourceId(request.getId())
|
||||||
.content(user.getName() + StringUtils.SPACE + Translator.get("personal.change.password"))
|
.content(Translator.get("personal.change.password"))
|
||||||
.originalValue(JSON.toJSONBytes(user))
|
.originalValue(JSON.toJSONBytes(user))
|
||||||
.build().getLogDTO();
|
.build().getLogDTO();
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -196,7 +196,7 @@ public class UserLogService {
|
||||||
.method(HttpMethodConstants.POST.name())
|
.method(HttpMethodConstants.POST.name())
|
||||||
.path("/system/user/delete")
|
.path("/system/user/delete")
|
||||||
.sourceId(user.getId())
|
.sourceId(user.getId())
|
||||||
.content(Translator.get("user.delete") + " : " + user.getName())
|
.content(user.getName())
|
||||||
.originalValue(JSON.toJSONBytes(user))
|
.originalValue(JSON.toJSONBytes(user))
|
||||||
.build().getLogDTO();
|
.build().getLogDTO();
|
||||||
logDTOList.add(dto);
|
logDTOList.add(dto);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import io.metersphere.system.controller.handler.ResultHolder;
|
||||||
import io.metersphere.system.domain.UserExample;
|
import io.metersphere.system.domain.UserExample;
|
||||||
import io.metersphere.system.domain.UserExtend;
|
import io.metersphere.system.domain.UserExtend;
|
||||||
import io.metersphere.system.domain.UserExtendExample;
|
import io.metersphere.system.domain.UserExtendExample;
|
||||||
|
import io.metersphere.system.dto.request.user.PersonalLocaleRequest;
|
||||||
import io.metersphere.system.dto.request.user.PersonalUpdatePasswordRequest;
|
import io.metersphere.system.dto.request.user.PersonalUpdatePasswordRequest;
|
||||||
import io.metersphere.system.dto.request.user.PersonalUpdateRequest;
|
import io.metersphere.system.dto.request.user.PersonalUpdateRequest;
|
||||||
import io.metersphere.system.dto.user.UserDTO;
|
import io.metersphere.system.dto.user.UserDTO;
|
||||||
|
@ -166,8 +167,28 @@ public class PersonalControllerTests extends BaseTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
|
void testPersonalUpdateLanguage() throws Exception {
|
||||||
|
PersonalLocaleRequest request = new PersonalLocaleRequest();
|
||||||
|
request.setLanguage("zh-CN");
|
||||||
|
this.requestPostWithOk(PersonalRequestUtils.URL_PERSONAL_UPDATE_LANGUAGE, request);
|
||||||
|
Assertions.assertEquals(userMapper.selectByPrimaryKey(loginUser).getLanguage(), "zh-CN");
|
||||||
|
|
||||||
|
request.setLanguage("en-US");
|
||||||
|
this.requestPostWithOk(PersonalRequestUtils.URL_PERSONAL_UPDATE_LANGUAGE, request);
|
||||||
|
Assertions.assertEquals(userMapper.selectByPrimaryKey(loginUser).getLanguage(), "en-US");
|
||||||
|
|
||||||
|
request.setLanguage(null);
|
||||||
|
this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_LANGUAGE, request).andExpect(status().isBadRequest());
|
||||||
|
|
||||||
|
request.setLanguage("ABCDE");
|
||||||
|
this.requestPost(PersonalRequestUtils.URL_PERSONAL_UPDATE_LANGUAGE, request).andExpect(status().isBadRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(3)
|
||||||
void testPersonalUpdatePassword() throws Exception {
|
void testPersonalUpdatePassword() throws Exception {
|
||||||
RsaKey rsaKey = RsaUtils.getRsaKey();
|
RsaKey rsaKey = RsaUtils.getRsaKey();
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,6 @@ public class PersonalRequestUtils {
|
||||||
//用户管理URL
|
//用户管理URL
|
||||||
public static final String URL_PERSONAL_GET = "/personal/get/%s";
|
public static final String URL_PERSONAL_GET = "/personal/get/%s";
|
||||||
public static final String URL_PERSONAL_UPDATE_INFO = "/personal/update-info";
|
public static final String URL_PERSONAL_UPDATE_INFO = "/personal/update-info";
|
||||||
|
public static final String URL_PERSONAL_UPDATE_LANGUAGE = "/personal/update-locale";
|
||||||
public static final String URL_PERSONAL_UPDATE_PASSWORD = "/personal/update-password";
|
public static final String URL_PERSONAL_UPDATE_PASSWORD = "/personal/update-password";
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import {
|
||||||
SavePlatformUrl,
|
SavePlatformUrl,
|
||||||
UpdateAPIKEYUrl,
|
UpdateAPIKEYUrl,
|
||||||
UpdateInfoUrl,
|
UpdateInfoUrl,
|
||||||
|
UpdateLanguageUrl,
|
||||||
UpdateLocalConfigUrl,
|
UpdateLocalConfigUrl,
|
||||||
UpdatePswUrl,
|
UpdatePswUrl,
|
||||||
ValidAPIKEYUrl,
|
ValidAPIKEYUrl,
|
||||||
|
@ -50,6 +51,7 @@ import type {
|
||||||
PersonalInfo,
|
PersonalInfo,
|
||||||
UpdateAPIKEYParams,
|
UpdateAPIKEYParams,
|
||||||
UpdateBaseInfo,
|
UpdateBaseInfo,
|
||||||
|
UpdateLanguage,
|
||||||
UpdateLocalConfigParams,
|
UpdateLocalConfigParams,
|
||||||
UpdatePswParams,
|
UpdatePswParams,
|
||||||
} from '@/models/user';
|
} from '@/models/user';
|
||||||
|
@ -199,6 +201,11 @@ export function updateBaseInfo(data: UpdateBaseInfo) {
|
||||||
return MSR.post({ url: UpdateInfoUrl, data });
|
return MSR.post({ url: UpdateInfoUrl, data });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 个人信息-修改基本信息
|
||||||
|
export function updateLanguage(data: UpdateLanguage) {
|
||||||
|
return MSR.post({ url: UpdateLanguageUrl, data });
|
||||||
|
}
|
||||||
|
|
||||||
// 个人信息-修改密码
|
// 个人信息-修改密码
|
||||||
export function updatePsw(data: UpdatePswParams) {
|
export function updatePsw(data: UpdatePswParams) {
|
||||||
return MSR.post({ url: UpdatePswUrl, data });
|
return MSR.post({ url: UpdatePswUrl, data });
|
||||||
|
|
|
@ -20,6 +20,7 @@ export const DeleteAPIKEYUrl = '/user/api/key/delete'; // 个人设置-删除 AP
|
||||||
export const AddAPIKEYUrl = '/user/api/key/add'; // 个人设置-生成 APIKEY
|
export const AddAPIKEYUrl = '/user/api/key/add'; // 个人设置-生成 APIKEY
|
||||||
export const UpdatePswUrl = '/personal/update-password'; // 个人信息-修改密码
|
export const UpdatePswUrl = '/personal/update-password'; // 个人信息-修改密码
|
||||||
export const UpdateInfoUrl = '/personal/update-info'; // 个人信息-修改信息
|
export const UpdateInfoUrl = '/personal/update-info'; // 个人信息-修改信息
|
||||||
|
export const UpdateLanguageUrl = '/personal/update-locale'; // 个人信息-修改语言
|
||||||
export const GetInfoUrl = '/personal/get'; // 个人信息-获取信息
|
export const GetInfoUrl = '/personal/get'; // 个人信息-获取信息
|
||||||
export const ValidatePlatformUrl = '/user/platform/validate'; // 个人信息-校验服务集成信息
|
export const ValidatePlatformUrl = '/user/platform/validate'; // 个人信息-校验服务集成信息
|
||||||
export const SavePlatformUrl = '/user/platform/save'; // 个人信息-保存三方平台账号信息
|
export const SavePlatformUrl = '/user/platform/save'; // 个人信息-保存三方平台账号信息
|
||||||
|
|
|
@ -147,7 +147,7 @@
|
||||||
</a-dropdown>
|
</a-dropdown>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a-dropdown trigger="click" position="br" @select="changeLocale as any">
|
<a-dropdown trigger="click" position="br" @select="changeLanguage as any">
|
||||||
<a-tooltip :content="t('settings.language')" position="br">
|
<a-tooltip :content="t('settings.language')" position="br">
|
||||||
<a-button type="secondary">
|
<a-button type="secondary">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
|
@ -186,6 +186,7 @@
|
||||||
|
|
||||||
import { getMessageUnReadCount } from '@/api/modules/message';
|
import { getMessageUnReadCount } from '@/api/modules/message';
|
||||||
import { switchProject } from '@/api/modules/project-management/project';
|
import { switchProject } from '@/api/modules/project-management/project';
|
||||||
|
import { updateBaseInfo, updateLanguage } from '@/api/modules/user';
|
||||||
import { MENU_LEVEL, type PathMapRoute } from '@/config/pathMap';
|
import { MENU_LEVEL, type PathMapRoute } from '@/config/pathMap';
|
||||||
import { useI18n } from '@/hooks/useI18n';
|
import { useI18n } from '@/hooks/useI18n';
|
||||||
import usePathMap from '@/hooks/usePathMap';
|
import usePathMap from '@/hooks/usePathMap';
|
||||||
|
@ -196,6 +197,7 @@
|
||||||
import { getFirstRouteNameByPermission, hasAnyPermission } from '@/utils/permission';
|
import { getFirstRouteNameByPermission, hasAnyPermission } from '@/utils/permission';
|
||||||
|
|
||||||
import { IconInfoCircle } from '@arco-design/web-vue/es/icon';
|
import { IconInfoCircle } from '@arco-design/web-vue/es/icon';
|
||||||
|
import type { LocaleType } from '#/global';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
isPreview?: boolean;
|
isPreview?: boolean;
|
||||||
|
@ -293,6 +295,11 @@
|
||||||
messageCenterVisible.value = true;
|
messageCenterVisible.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeLanguage(locale: LocaleType) {
|
||||||
|
// 修改当前用户的语言
|
||||||
|
updateLanguage({ language: locale });
|
||||||
|
changeLocale(locale);
|
||||||
|
}
|
||||||
function handleHelpSelect(val: string | number | Record<string, any> | undefined) {
|
function handleHelpSelect(val: string | number | Record<string, any> | undefined) {
|
||||||
switch (val) {
|
switch (val) {
|
||||||
case 'doc':
|
case 'doc':
|
||||||
|
|
|
@ -145,6 +145,10 @@ export interface UpdateBaseInfo {
|
||||||
avatar: string;
|
avatar: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UpdateLanguage {
|
||||||
|
language: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface OrgOptionItem {
|
export interface OrgOptionItem {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
Loading…
Reference in New Issue