AI Implementation feature(913): Admin Area Players Management 1.00 (#57)

This commit was merged in pull request #57.
This commit is contained in:
2026-07-23 08:43:46 +00:00
parent e4ccf0fe13
commit d468cca766
11 changed files with 674 additions and 53 deletions
@@ -8,6 +8,7 @@ import {
import { CommonModule } from '@angular/common';
import { AdminService, AdminUser } from '../../core/services/admin.service';
import { NotificationService } from '../../core/services/notification.service';
import { AuthService } from '../../core/services/auth.service';
import {
adminPlayerApiErrorMessage,
extractFieldErrors,
@@ -169,6 +170,7 @@ import {
export class AdminUsersComponent implements OnInit {
private readonly admin = inject(AdminService);
private readonly notify = inject(NotificationService);
private readonly auth = inject(AuthService);
readonly rows = signal<AdminUser[]>([]);
readonly loading = signal(false);
@@ -241,6 +243,11 @@ export class AdminUsersComponent implements OnInit {
const updated = await this.withInflight(row.id, () => this.admin.updatePlayerRole(row.id, nextRole));
this.rows.set(replacePlayer(this.rows(), { ...row, ...updated }));
this.statusMessage.set(`Role updated to ${updated.role}.`);
const me = this.auth.currentUser();
if (me && me.id === updated.id && me.role !== updated.role) {
this.auth.applyPeerRoleChange(updated.role);
this.auth.publishRoleChange(updated.id, updated.role);
}
} catch (e) {
if (isLastAdminError(e)) {
this.notify.error(lastAdminMessage());
@@ -17,6 +17,8 @@ import { EventStatusStore } from '../../core/services/event-status.store';
import { AuthenticatedEventSourceService } from '../../core/services/authenticated-event-source.service';
import { UserStore } from '../../core/services/user.store';
import { ChallengesStore } from '../challenges/challenges.store';
import { NotificationService } from '../../core/services/notification.service';
import { CrossTabRoleChangeMessage } from '../../core/services/auth-session-events.pure';
import { ShellHeaderComponent } from '../shell/header/shell-header.component';
import {
ChangePasswordModalComponent,
@@ -95,6 +97,7 @@ export class HomeComponent implements OnInit, OnDestroy {
private readonly challengesStore = inject(ChallengesStore);
private readonly router = inject(Router);
private readonly destroyRef = inject(DestroyRef);
private readonly notifications = inject(NotificationService);
readonly userMenuOpen = signal(false);
readonly changePasswordOpen = signal(false);
@@ -138,6 +141,9 @@ export class HomeComponent implements OnInit, OnDestroy {
this.peerInvalidationUnsubscribe = this.auth.onPeerInvalidation((reason) =>
this.handleSessionInvalidated(reason),
);
this.peerRoleChangeUnsubscribe = this.auth.onPeerRoleChange((msg) =>
this.handlePeerRoleChange(msg),
);
}
ngOnDestroy(): void {
@@ -146,6 +152,10 @@ export class HomeComponent implements OnInit, OnDestroy {
this.peerInvalidationUnsubscribe();
this.peerInvalidationUnsubscribe = null;
}
if (this.peerRoleChangeUnsubscribe) {
this.peerRoleChangeUnsubscribe();
this.peerRoleChangeUnsubscribe = null;
}
}
goHome(): void {
@@ -207,6 +217,7 @@ export class HomeComponent implements OnInit, OnDestroy {
}
private peerInvalidationUnsubscribe: (() => void) | null = null;
private peerRoleChangeUnsubscribe: (() => void) | null = null;
private navigatingToLogin = false;
private async handleSessionInvalidated(
@@ -225,4 +236,14 @@ export class HomeComponent implements OnInit, OnDestroy {
this.navigatingToLogin = false;
}
}
private handlePeerRoleChange(msg: CrossTabRoleChangeMessage): void {
const me = this.auth.currentUser();
if (!me || me.id !== msg.userId) return;
this.userStore.setRole(msg.newRole);
if (!this.router.url.startsWith('/admin/')) return;
this.notifications.info(
`Your role was changed to "${msg.newRole}" by another admin. You may need to refresh or log in again to continue.`,
);
}
}