fix: allow users to reset wallet runtime

chore/issuance-comments-zh
chenyuan 3 weeks ago
parent 72b771b409
commit ab9be4afc2

@ -1,11 +1,8 @@
package com.yau.digitalrmb.shared.wallet; package com.yau.digitalrmb.shared.wallet;
import com.yau.digitalrmb.identity.domain.UserRole;
import com.yau.digitalrmb.institutionidentity.application.InstitutionKeySubject; import com.yau.digitalrmb.institutionidentity.application.InstitutionKeySubject;
import com.yau.digitalrmb.security.context.AuthContextHolder; import com.yau.digitalrmb.security.context.AuthContextHolder;
import com.yau.digitalrmb.security.context.JwtUser; import com.yau.digitalrmb.security.context.JwtUser;
import com.yau.digitalrmb.shared.api.ErrorCode;
import com.yau.digitalrmb.shared.exception.BusinessException;
import com.yau.digitalrmb.shared.api.ApiResponse; import com.yau.digitalrmb.shared.api.ApiResponse;
import com.yau.digitalrmb.shared.web.TraceIdFilter; import com.yau.digitalrmb.shared.web.TraceIdFilter;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -19,23 +16,19 @@ import javax.annotation.Resource;
@RestController @RestController
@RequestMapping("/api/v1/wallet-runtime") @RequestMapping("/api/v1/wallet-runtime")
@Tag(name = "钱包运行数据-彻底重开", description = "清空兑换/支付历史并重建模块三投影(教师/管理员专用)") @Tag(name = "钱包运行数据重置", description = "清空当前用户兑换/支付历史并重建模块三投影")
public class WalletRuntimeResetController { public class WalletRuntimeResetController {
@Resource @Resource
private WalletRuntimeResetService resetService; private WalletRuntimeResetService resetService;
@PostMapping("/reset") @PostMapping("/reset")
@Operation(summary = "彻底重开兑换与支付实验", @Operation(summary = "重新开始兑换与支付实验",
description = "删除当前用户的全部兑换/支付订单与流水(含已确权完成的),把涉及币串回退到商业银行库," + description = "删除当前用户的全部兑换/支付订单与流水(含已确权完成的),把涉及币串回退到商业银行库," +
"并清空模块三投影出的共享钱包/银行账户/证书/合约/绑定与实验attempt," + "并清空模块三投影出的共享钱包/银行账户/证书/合约/绑定与实验attempt," +
"随后立即按最新模块三结果重新投影,模块四/五可直接重新开始。仅教师和管理员可调用。") "随后立即按最新模块三结果重新投影,模块四/五可直接重新开始。仅影响当前登录用户。")
public ApiResponse<WalletRuntimeResetResult> reset() { public ApiResponse<WalletRuntimeResetResult> reset() {
JwtUser jwtUser = AuthContextHolder.get(); JwtUser jwtUser = AuthContextHolder.get();
Integer roleId = jwtUser.getRoleId();
if (roleId == null || (roleId != UserRole.ADMIN.getId() && roleId != UserRole.TEACHER.getId())) {
throw new BusinessException(ErrorCode.FORBIDDEN, "仅教师或管理员可以彻底重开兑换与支付实验");
}
return ApiResponse.success(resetService.reset(InstitutionKeySubject.from(jwtUser)), traceId()); return ApiResponse.success(resetService.reset(InstitutionKeySubject.from(jwtUser)), traceId());
} }

@ -105,7 +105,7 @@ class WalletRuntimeResetTest {
} }
@Test @Test
void teacherResetRollsBackCompletedExchangeAndReprojectsFreshModuleThree() throws Exception { void userResetRollsBackCompletedExchangeAndReprojectsFreshModuleThree() throws Exception {
String context = mockMvc.perform(get("/api/v1/exchanges/context").with(role(4))) String context = mockMvc.perform(get("/api/v1/exchanges/context").with(role(4)))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); .andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
String walletId = JsonPath.read(context, "$.data.walletId"); String walletId = JsonPath.read(context, "$.data.walletId");
@ -131,7 +131,7 @@ class WalletRuntimeResetTest {
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.data.bankCardNumber").value("6216610100001234567")); .andExpect(jsonPath("$.data.bankCardNumber").value("6216610100001234567"));
mockMvc.perform(post("/api/v1/wallet-runtime/reset").with(role(3))) mockMvc.perform(post("/api/v1/wallet-runtime/reset").with(role(4)))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.data.deletedExchangeOrderCount").value(1)) .andExpect(jsonPath("$.data.deletedExchangeOrderCount").value(1))
.andExpect(jsonPath("$.data.restoredCoinCount").value(2)) .andExpect(jsonPath("$.data.restoredCoinCount").value(2))
@ -170,10 +170,8 @@ class WalletRuntimeResetTest {
} }
@Test @Test
void studentRoleCannotReset() throws Exception { void studentCanResetOwnRuntime() throws Exception {
mockMvc.perform(post("/api/v1/wallet-runtime/reset").with(role(4))) mockMvc.perform(post("/api/v1/wallet-runtime/reset").with(role(4)))
.andExpect(status().isForbidden());
mockMvc.perform(post("/api/v1/wallet-runtime/reset").with(role(1)))
.andExpect(status().isOk()); .andExpect(status().isOk());
} }

Loading…
Cancel
Save