feat(系统管理): 切换语言时后台用户信息进行记录
This commit is contained in:
parent
685e5d9934
commit
47e57788f4
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.system.controller;
|
||||
|
||||
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.PersonalUpdateRequest;
|
||||
import io.metersphere.system.dto.user.PersonalDTO;
|
||||
|
@ -40,6 +41,12 @@ PersonalCenterController {
|
|||
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")
|
||||
@Operation(summary = "个人中心-修改密码")
|
||||
@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.request.UserInviteRequest;
|
||||
import io.metersphere.system.dto.request.UserRegisterRequest;
|
||||
import io.metersphere.system.dto.request.user.PersonalUpdatePasswordRequest;
|
||||
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.request.user.*;
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import io.metersphere.system.dto.sdk.ExcelParseDTO;
|
||||
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) {
|
||||
this.checkUserEmail(request.getId(), request.getEmail());
|
||||
User editUser = new User();
|
||||
|
|
|
@ -96,7 +96,7 @@ public class UserLogService {
|
|||
.method(HttpMethodConstants.POST.name())
|
||||
.path("/personal/update-password")
|
||||
.sourceId(request.getId())
|
||||
.content(user.getName() + StringUtils.SPACE + Translator.get("personal.change.password"))
|
||||
.content(Translator.get("personal.change.password"))
|
||||
.originalValue(JSON.toJSONBytes(user))
|
||||
.build().getLogDTO();
|
||||
return dto;
|
||||
|
@ -196,7 +196,7 @@ public class UserLogService {
|
|||
.method(HttpMethodConstants.POST.name())
|
||||
.path("/system/user/delete")
|
||||
.sourceId(user.getId())
|
||||
.content(Translator.get("user.delete") + " : " + user.getName())
|
||||
.content(user.getName())
|
||||
.originalValue(JSON.toJSONBytes(user))
|
||||
.build().getLogDTO();
|
||||
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.UserExtend;
|
||||
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.PersonalUpdateRequest;
|
||||
import io.metersphere.system.dto.user.UserDTO;
|
||||
|
@ -166,8 +167,28 @@ public class PersonalControllerTests extends BaseTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@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 {
|
||||
RsaKey rsaKey = RsaUtils.getRsaKey();
|
||||
|
||||
|
|
|
@ -5,5 +5,6 @@ public class PersonalRequestUtils {
|
|||
//用户管理URL
|
||||
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_LANGUAGE = "/personal/update-locale";
|
||||
public static final String URL_PERSONAL_UPDATE_PASSWORD = "/personal/update-password";
|
||||
}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
VITE_API_BASE_URL= 'front'
|
||||
VITE_DEV_DOMAIN='http://172.16.200.18:8081/'
|
||||
VITE_DEV_DOMAIN='http://172.16.200.18:8081/'
|
||||
|
|
|
@ -33,6 +33,7 @@ import {
|
|||
SavePlatformUrl,
|
||||
UpdateAPIKEYUrl,
|
||||
UpdateInfoUrl,
|
||||
UpdateLanguageUrl,
|
||||
UpdateLocalConfigUrl,
|
||||
UpdatePswUrl,
|
||||
ValidAPIKEYUrl,
|
||||
|
@ -50,6 +51,7 @@ import type {
|
|||
PersonalInfo,
|
||||
UpdateAPIKEYParams,
|
||||
UpdateBaseInfo,
|
||||
UpdateLanguage,
|
||||
UpdateLocalConfigParams,
|
||||
UpdatePswParams,
|
||||
} from '@/models/user';
|
||||
|
@ -199,6 +201,11 @@ export function updateBaseInfo(data: UpdateBaseInfo) {
|
|||
return MSR.post({ url: UpdateInfoUrl, data });
|
||||
}
|
||||
|
||||
// 个人信息-修改基本信息
|
||||
export function updateLanguage(data: UpdateLanguage) {
|
||||
return MSR.post({ url: UpdateLanguageUrl, data });
|
||||
}
|
||||
|
||||
// 个人信息-修改密码
|
||||
export function updatePsw(data: UpdatePswParams) {
|
||||
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 UpdatePswUrl = '/personal/update-password'; // 个人信息-修改密码
|
||||
export const UpdateInfoUrl = '/personal/update-info'; // 个人信息-修改信息
|
||||
export const UpdateLanguageUrl = '/personal/update-locale'; // 个人信息-修改语言
|
||||
export const GetInfoUrl = '/personal/get'; // 个人信息-获取信息
|
||||
export const ValidatePlatformUrl = '/user/platform/validate'; // 个人信息-校验服务集成信息
|
||||
export const SavePlatformUrl = '/user/platform/save'; // 个人信息-保存三方平台账号信息
|
||||
|
|
|
@ -147,7 +147,7 @@
|
|||
</a-dropdown>
|
||||
</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-button type="secondary">
|
||||
<template #icon>
|
||||
|
@ -186,6 +186,7 @@
|
|||
|
||||
import { getMessageUnReadCount } from '@/api/modules/message';
|
||||
import { switchProject } from '@/api/modules/project-management/project';
|
||||
import { updateBaseInfo, updateLanguage } from '@/api/modules/user';
|
||||
import { MENU_LEVEL, type PathMapRoute } from '@/config/pathMap';
|
||||
import { useI18n } from '@/hooks/useI18n';
|
||||
import usePathMap from '@/hooks/usePathMap';
|
||||
|
@ -196,6 +197,7 @@
|
|||
import { getFirstRouteNameByPermission, hasAnyPermission } from '@/utils/permission';
|
||||
|
||||
import { IconInfoCircle } from '@arco-design/web-vue/es/icon';
|
||||
import type { LocaleType } from '#/global';
|
||||
|
||||
const props = defineProps<{
|
||||
isPreview?: boolean;
|
||||
|
@ -293,6 +295,11 @@
|
|||
messageCenterVisible.value = true;
|
||||
}
|
||||
|
||||
function changeLanguage(locale: LocaleType) {
|
||||
// 修改当前用户的语言
|
||||
updateLanguage({ language: locale });
|
||||
changeLocale(locale);
|
||||
}
|
||||
function handleHelpSelect(val: string | number | Record<string, any> | undefined) {
|
||||
switch (val) {
|
||||
case 'doc':
|
||||
|
|
|
@ -145,6 +145,10 @@ export interface UpdateBaseInfo {
|
|||
avatar: string;
|
||||
}
|
||||
|
||||
export interface UpdateLanguage {
|
||||
language: string;
|
||||
}
|
||||
|
||||
export interface OrgOptionItem {
|
||||
id: string;
|
||||
name: string;
|
||||
|
|
Loading…
Reference in New Issue