feat(账号到期): 普通账号不再带自己的到期时间,入口与接口一起收窄
口径(2026-10-05 用户定):到期时间只需要设在管理员/公司超管身上,普通账号的停用 由上级级联决定(组长 + 创建人 + 本公司公司超管,见 AccountExpiryService)。 此前这条只存在于约定里,任何调用方都能给普通账号写 expires_at。 - 后端 AdminUserService:建号/编辑两道 400(绕过界面直接打接口传值就拒), 把管理员改成普通账号时同批把 expires_at 置 null;判据 mayCarryOwnExpiry = admin|company_super_admin。 - 前端:user-create-model 导出同名判据(一支跨端用例逐字钉两端集合相等), toCreateUserRequest 对 normal 不下发;toEditUserUpdateRequest 按"改完之后 的角色"决定,不能带就发空串=清空,公司超管目标因请求不带 role 而保留原值; 两个对话框的「到期时间」项加 v-if="expiryEditable"。 - 用例:后端新增 4 支(含一条「普通账号仍可传空串清除」控制组,14 例绿); 前端新增 9 支;旧 company-user-create 那条编码旧口径的断言改 role=admin。
This commit is contained in:
+82
@@ -22,11 +22,13 @@ import org.mockito.ArgumentCaptor;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.catchThrowableOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -236,6 +238,86 @@ class AdminUserServiceCompanySuperAdminTest {
|
||||
.hasMessageContaining("只有超级管理员可以删除公司超级管理员");
|
||||
}
|
||||
|
||||
// ---------- 普通账号不带自身到期(2026-10-05 定案:到期只设在管理员/公司超管身上)----------
|
||||
|
||||
@Test
|
||||
void createRejectsExpiryOnNormalAccount() {
|
||||
AdminUserEntity operator = user(1L, "super_admin", 1L, null);
|
||||
AdminUserCreateRequest request = new AdminUserCreateRequest();
|
||||
request.setUsername("staff-1");
|
||||
request.setPassword("secret1");
|
||||
request.setRole("normal");
|
||||
request.setCreatedById(7L);
|
||||
request.setExpiresAt("2026-12-31 23:59");
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
|
||||
BusinessException ex = catchThrowableOfType(() -> service.createUser(operator, request),
|
||||
BusinessException.class);
|
||||
assertThat(ex).isNotNull();
|
||||
assertThat(ex.getCode()).isEqualTo(400);
|
||||
assertThat(ex.getMessage()).contains("普通账号");
|
||||
verify(userMapper, never()).insert(any(AdminUserEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateRejectsExpiryOnNormalTarget() {
|
||||
AdminUserEntity operator = user(1L, "super_admin", 1L, null);
|
||||
AdminUserEntity target = user(9L, "normal", 1L, 7L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
when(userMapper.selectById(9L)).thenReturn(target);
|
||||
|
||||
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
|
||||
request.setExpiresAt("2026-12-31 23:59");
|
||||
|
||||
BusinessException ex = catchThrowableOfType(() -> service.updateUser(operator, 9L, request),
|
||||
BusinessException.class);
|
||||
assertThat(ex).isNotNull();
|
||||
assertThat(ex.getCode()).isEqualTo(400);
|
||||
verify(userMapper, never()).update(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void demotingAdminToNormalClearsOwnExpiry() {
|
||||
AdminUserEntity operator = user(1L, "super_admin", 1L, null);
|
||||
AdminUserEntity target = user(9L, "admin", 1L, 1L);
|
||||
target.setExpiresAt(LocalDateTime.of(2026, 12, 31, 23, 59));
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
when(userMapper.selectById(9L)).thenReturn(target);
|
||||
|
||||
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
|
||||
request.setRole("normal");
|
||||
|
||||
service.updateUser(operator, 9L, request);
|
||||
|
||||
ArgumentCaptor<LambdaUpdateWrapper<AdminUserEntity>> captor =
|
||||
ArgumentCaptor.forClass(LambdaUpdateWrapper.class);
|
||||
verify(userMapper).update(org.mockito.ArgumentMatchers.isNull(), captor.capture());
|
||||
assertThat(captor.getValue().getSqlSet()).contains("expires_at");
|
||||
// 清的是 null,不是把原时间照抄回去
|
||||
assertThat(captor.getValue().getParamNameValuePairs().values())
|
||||
.noneMatch(value -> value instanceof LocalDateTime);
|
||||
}
|
||||
|
||||
/** 控制用例:收掉入口不许顺手把「清空」也禁掉——空串仍要能把历史值摘成永不过期。 */
|
||||
@Test
|
||||
void normalTargetCanStillClearExpiryWithBlankValue() {
|
||||
AdminUserEntity operator = user(1L, "super_admin", 1L, null);
|
||||
AdminUserEntity target = user(9L, "normal", 1L, 7L);
|
||||
target.setExpiresAt(LocalDateTime.of(2026, 12, 31, 23, 59));
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
when(userMapper.selectById(9L)).thenReturn(target);
|
||||
|
||||
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
|
||||
request.setExpiresAt("");
|
||||
|
||||
service.updateUser(operator, 9L, request);
|
||||
|
||||
ArgumentCaptor<LambdaUpdateWrapper<AdminUserEntity>> captor =
|
||||
ArgumentCaptor.forClass(LambdaUpdateWrapper.class);
|
||||
verify(userMapper).update(org.mockito.ArgumentMatchers.isNull(), captor.capture());
|
||||
assertThat(captor.getValue().getSqlSet()).contains("expires_at");
|
||||
}
|
||||
|
||||
// ---------- helpers ----------
|
||||
|
||||
private static AdminUserEntity user(Long id, String role, Long companyId, Long createdById) {
|
||||
|
||||
Reference in New Issue
Block a user