RBAC 管理后台对齐老系统:用户/角色/部门/菜单/数据权限 增删改 + amis 管理页(A1–A5)
A1 SYS_MENU CRUD(软删+清role_menu+有子拒删)+menuAll isGroup+sys-admin-menu crud树
A2 用户 reset-password(MD5 110)+sys-admin-user 新建/编辑/停用/重置按钮
A3 SYS_ROLE CRUD(删清三关联表+evictAll)+sys-admin-role 新建/编辑/删除
A4 SYS_DEPART CRUD(有子拒删)+departs/tree 读端点+新页 sys-admin-depart
A5 sys_filterrule CRUD+set-roles+filterrules/{id}/roles+sys-admin-filterrule 授权UI
AdminWriteControllerTest 35测 + AdminUserControllerTest 3测;全部 API e2e 对真实库 + 浏览器验收
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -157,6 +157,29 @@ public class AdminUserController {
|
||||
return ResponseEntity.ok(ok("用户" + action + "成功"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员重置用户密码为系统初始密码(MD5("110"))。
|
||||
*
|
||||
* <p>密码列不下发;仅管理员可调。用于用户遗忘密码后的运维重置。
|
||||
*
|
||||
* @param id SYS_USER.SYS_USER_ID
|
||||
*/
|
||||
@PostMapping("/users/{id}/reset-password")
|
||||
public ResponseEntity<Map<String, Object>> resetPassword(@PathVariable String id) {
|
||||
requireAdmin();
|
||||
long now = System.currentTimeMillis();
|
||||
String operator = currentUserId();
|
||||
int rows = jdbcTemplate.update(
|
||||
"UPDATE sys_user SET password=?, updatetime=?, updateby=?, version=version+1"
|
||||
+ " WHERE TRIM(sys_user_id)=? AND isactive=1",
|
||||
DEFAULT_PASSWORD, now, operator, id.trim());
|
||||
if (rows == 0) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(fail("用户不存在或已停用: " + id));
|
||||
}
|
||||
log.info("[A2][重置密码] operator={} userId={}", operator, id.trim());
|
||||
return ResponseEntity.ok(ok("密码已重置为初始密码(110)"));
|
||||
}
|
||||
|
||||
// ================================================================ 内部工具
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.eip4.platform.auth.security;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.contains;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
/**
|
||||
* A2 AdminUserController 单测(mock JdbcTemplate + UserSession,不连库)。
|
||||
*
|
||||
* <p>本轮新增覆盖管理员重置密码端点:正例(重置为初始密码)、404、403。
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
class AdminUserControllerTest {
|
||||
|
||||
private JdbcTemplate jdbc;
|
||||
private AdminUserController controller;
|
||||
private MockedStatic<UserSession> userSessionMock;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
jdbc = mock(JdbcTemplate.class);
|
||||
controller = new AdminUserController(jdbc);
|
||||
userSessionMock = mockStatic(UserSession.class);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
userSessionMock.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("1. 管理员重置密码 → status=0,写 password 列")
|
||||
void resetPassword_ok() {
|
||||
mockAdmin();
|
||||
when(jdbc.update(contains("SET password"), any(), any(), any(), anyString())).thenReturn(1);
|
||||
ResponseEntity<Map<String, Object>> resp = controller.resetPassword("uid-1");
|
||||
assertEquals(HttpStatus.OK, resp.getStatusCode());
|
||||
assertEquals(0, resp.getBody().get("status"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("2. 重置密码用户不存在 → 404")
|
||||
void resetPassword_notFound_404() {
|
||||
mockAdmin();
|
||||
when(jdbc.update(contains("SET password"), any(), any(), any(), anyString())).thenReturn(0);
|
||||
ResponseEntity<Map<String, Object>> resp = controller.resetPassword("no-such");
|
||||
assertEquals(HttpStatus.NOT_FOUND, resp.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("3. 非管理员重置密码 → 403")
|
||||
void resetPassword_nonAdmin_403() {
|
||||
mockNonAdmin();
|
||||
ResponseStatusException ex = assertThrows(ResponseStatusException.class,
|
||||
() -> controller.resetPassword("uid-1"));
|
||||
assertEquals(HttpStatus.FORBIDDEN, ex.getStatusCode());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 工具
|
||||
|
||||
private void mockAdmin() {
|
||||
Properties ctx = new Properties();
|
||||
ctx.setProperty(LoggedInUser.CURRENTUSER, "ADMIN");
|
||||
userSessionMock.when(UserSession::get).thenReturn(ctx);
|
||||
}
|
||||
|
||||
private void mockNonAdmin() {
|
||||
Properties ctx = new Properties();
|
||||
ctx.setProperty(LoggedInUser.CURRENTUSER, "normal-user-id");
|
||||
userSessionMock.when(UserSession::get).thenReturn(ctx);
|
||||
when(jdbc.queryForObject(contains("account"), eq(Integer.class), anyString()))
|
||||
.thenReturn(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user