fix(aihr): resolve supervisor identity across roles

This commit is contained in:
2026-07-14 10:08:16 +08:00
parent 4f96df27d2
commit 20330df042
4 changed files with 29 additions and 8 deletions
@@ -2116,7 +2116,7 @@ public class AihrPracticeSeedService {
AND employment_status = 'active'
LIMIT 1
""", (rs, rowNum) -> rs.getString("position_level"), args.toArray());
if (positionLevels.isEmpty() || !canSeeProject(positionLevels.get(0))) {
if (positionLevels.stream().noneMatch(AihrPracticeSeedService::canSeeProject)) {
throw new ServiceException("无主管权限,无法访问主管功能");
}
return identity;
@@ -2149,8 +2149,11 @@ public class AihrPracticeSeedService {
if (owners.isEmpty()) {
return TeamScope.scoped(List.of());
}
OrgScopeRow row = owners.get(0);
if (!canSeeProject(row.positionLevel())) {
OrgScopeRow row = owners.stream()
.filter(scope -> canSeeProject(scope.positionLevel()))
.findFirst()
.orElse(null);
if (row == null) {
return TeamScope.scoped(List.of(owner));
}
List<String> ids = jdbcTemplate.query("""
@@ -241,6 +241,15 @@ public class AihrPracticeSeedServiceTest {
assertEquals(List.of("000000", "13900001111", "13900001111"), jdbcTemplate.authorizationArgs);
}
@Test
public void supervisorIdentityAcceptsSupervisorWhenPhoneAlsoMatchesFrontlineRow() {
SupervisorAuthorizationJdbcTemplate jdbcTemplate = new SupervisorAuthorizationJdbcTemplate(
"13900001111", List.of("一线", "主管"));
AihrPracticeSeedService service = new AihrPracticeSeedService(new ObjectMapper(), jdbcTemplate, null, null);
assertEquals("13900001111", service.requireSupervisorIdentity("13900001111"));
}
@Test
public void supervisorIdentityRejectsFrontlineUnknownAndBlankIdentity() {
SupervisorAuthorizationJdbcTemplate jdbcTemplate = new SupervisorAuthorizationJdbcTemplate(Map.of(
@@ -872,13 +881,18 @@ public class AihrPracticeSeedServiceTest {
}
private static final class SupervisorAuthorizationJdbcTemplate extends JdbcTemplate {
private final Map<String, String> positionLevels;
private final Map<String, List<String>> positionLevels;
private String authorizationSql = "";
private List<Object> authorizationArgs = List.of();
private int authorizationQueryCount;
private SupervisorAuthorizationJdbcTemplate(Map<String, String> positionLevels) {
this.positionLevels = positionLevels;
this.positionLevels = positionLevels.entrySet().stream()
.collect(java.util.stream.Collectors.toMap(Map.Entry::getKey, entry -> List.of(entry.getValue())));
}
private SupervisorAuthorizationJdbcTemplate(String identity, List<String> positionLevels) {
this.positionLevels = Map.of(identity, List.copyOf(positionLevels));
}
@Override
@@ -896,12 +910,14 @@ public class AihrPracticeSeedServiceTest {
authorizationSql = sql;
authorizationArgs = List.of(args);
authorizationQueryCount += 1;
String positionLevel = positionLevels.get(String.valueOf(args[1]));
if (positionLevel == null) {
List<String> positionRows = positionLevels.get(String.valueOf(args[1]));
if (positionRows == null) {
return List.of();
}
try {
return mapRows(rowMapper, List.of(Map.of("position_level", positionLevel)));
return mapRows(rowMapper, positionRows.stream()
.map(positionLevel -> Map.of("position_level", positionLevel))
.toList());
} catch (SQLException e) {
throw new IllegalStateException(e);
}