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");
}
}