fix(mobile-api): keep a deactivated member already on an event's team

Only users being added must be active admins; someone already on the team stays
until an admin removes them, so an unrelated event edit no longer fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-11-27 01:48:35 +08:00
1 parent 2efdcba1ae
commit 33f1e7a505
3 files changed
+27 -6

No files matched your search

@@ -82,7 +82,7 @@ public class AdminEventService {
public Map<String, Object> create(AdminEventRequest r) {
Fields f = validate(r);
User caller = caller();
List<Long> team = checkedTeam(r.salespersonIds());
List<Long> team = checkedTeam(r.salespersonIds(), List.of());
Event event = new Event();
apply(event, f);
event.setCreateBy(caller.getUsername());
@@ -96,7 +96,7 @@ public class AdminEventService {
Fields f = validate(r);
User caller = caller();
Event event = load(uuid);
List<Long> team = r.salespersonIds() == null ? null : checkedTeam(r.salespersonIds());
List<Long> team = r.salespersonIds() == null ? null : checkedTeam(r.salespersonIds(), teamIds(event.getUuid()));
apply(event, f);
if (r.enabled() != null) event.setEnabled(r.enabled() ? GeneralEnum.FlagYesNo.Y : GeneralEnum.FlagYesNo.N);
event.setDoneBy(caller.getUsername());
@@ -163,11 +163,14 @@ public class AdminEventService {
e.setDateEnd(LocalDateTime.of(f.end(), LocalTime.of(23, 59, 59)));
}
/** Duplicates collapse; every id must be an enabled admin user. One services-system lookup per id. */
private List<Long> checkedTeam(List<Long> ids) {
/**
* Duplicates collapse; every id added to the team must be an enabled admin user. Someone already on the team
* stays even if deactivated since, so an unrelated edit does not fail until an admin removes them.
*/
private List<Long> checkedTeam(List<Long> ids, List<Long> current) {
List<Long> team = ids == null ? List.of() : new ArrayList<>(new LinkedHashSet<>(ids));
for (Long id : team) {
if (id == null || !isActiveAdmin(user(id))) {
if (id == null || !current.contains(id) && !isActiveAdmin(user(id))) {
throw error(HttpStatus.BAD_REQUEST, "Unknown or inactive admin user " + id, "UNKNOWN_USER", "salespersonIds");
}
}
@@ -64,6 +64,8 @@ class AdminEventServiceTest {
when(rest.postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any()))
.thenAnswer(i -> ResponseEntity.ok(i.getArgument(2)));
when(rest.postForEntity(eq(REPLACE), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(List.of()));
// default: the event has no team yet (tests that need one stub TEAM themselves)
when(rest.getForEntity(eq(TEAM), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(List.of()));
}
@AfterEach
@@ -379,6 +381,21 @@ class AdminEventServiceTest {
verify(rest, never()).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
}
@Test
void update_keepsADeactivatedMemberAlreadyOnTheTeam() {
stubFind(event());
when(rest.getForEntity(eq(TEAM), any(ParameterizedTypeReference.class), eq(UUID)))
.thenReturn(ResponseEntity.ok(List.of(Map.of("userId", 2))));
stubUser(2, "A", false);
stubUser(3, "A", true);
when(rest.postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any()))
.thenAnswer(i -> ResponseEntity.ok(i.getArgument(2)));
service.update(String.valueOf(UUID), req("N", "L", "2027-01-01", "2027-01-02", List.of(2L, 3L)));
assertThat(replaceBody()).containsEntry("userIds", List.of(2L, 3L));
}
@Test
void salespersonOptions_onlyEnabledTypeAUsersSortedByName() {
List<Map<String, Object>> users = List.of(