fix(aihr): enforce disabled scenario gate
This commit is contained in:
+22
-1
@@ -481,7 +481,9 @@ public class AihrPracticeSeedService {
|
||||
}
|
||||
|
||||
public StartResponse start(StartRequest request) {
|
||||
ScenarioSeed scenario = resolveScenario(resolveStartScenarioId(request), null);
|
||||
String scenarioId = resolveStartScenarioId(request);
|
||||
ensureScenarioEnabledForStart(scenarioId);
|
||||
ScenarioSeed scenario = resolveScenario(scenarioId, null);
|
||||
RoundSeed firstRound = scenario.rounds().get(0);
|
||||
String sessionId = "seed-" + scenario.id() + "-" + System.currentTimeMillis();
|
||||
String trainee = resolveTrainee(request, scenario);
|
||||
@@ -2146,6 +2148,25 @@ public class AihrPracticeSeedService {
|
||||
return assignedScenarioId;
|
||||
}
|
||||
|
||||
private void ensureScenarioEnabledForStart(String scenarioId) {
|
||||
if (isBlank(scenarioId)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
List<Boolean> enabledRows = jdbcTemplate.query("""
|
||||
SELECT enabled
|
||||
FROM aihr_practice_scenario
|
||||
WHERE tenant_id = ? AND scenario_code = ?
|
||||
LIMIT 1
|
||||
""", (rs, rowNum) -> rs.getBoolean("enabled"), tenantId(), scenarioId.trim());
|
||||
if (!enabledRows.isEmpty() && !Boolean.TRUE.equals(enabledRows.get(0))) {
|
||||
throw new ServiceException("训练场景已停用,无法开始");
|
||||
}
|
||||
} catch (DataAccessException ignored) {
|
||||
// A missing/unavailable scenario table keeps the existing local seed fallback.
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveExtPartyId(StartRequest request, String trainee) {
|
||||
if (request == null || isBlank(request.extPartyId())) {
|
||||
return trainee;
|
||||
|
||||
+11
@@ -223,6 +223,17 @@ public class AihrPracticeSeedServiceTest {
|
||||
assertEquals("训练会话不存在或无权访问", missing.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startChecksScenarioEnabledBeforeSeedFallback() throws Exception {
|
||||
String source = Files.readString(Path.of("src/main/java/org/dromara/aihr/service/AihrPracticeSeedService.java"));
|
||||
int methodStart = source.indexOf("public StartResponse start(StartRequest request)");
|
||||
int methodEnd = source.indexOf("public TurnResponse turn", methodStart);
|
||||
String method = source.substring(methodStart, methodEnd);
|
||||
|
||||
assertTrue(method.contains("ensureScenarioEnabledForStart(scenarioId)"));
|
||||
assertTrue(source.contains("训练场景已停用,无法开始"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAssignmentRejectsOutOfProjectAssignee() {
|
||||
JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||
|
||||
Reference in New Issue
Block a user