From b111f0921c1567a021d07677a3fe3699ca4921c4 Mon Sep 17 00:00:00 2001 From: Joseph Insalaco Date: Fri, 16 Aug 2024 22:31:57 -0400 Subject: [PATCH] Admin persistence changes (#5086) --- webclient/src/store/server/server.actions.ts | 28 ++++++++ webclient/src/store/server/server.dispatch.ts | 18 +++++ .../src/store/server/server.interfaces.ts | 11 ++- webclient/src/store/server/server.reducer.ts | 70 ++++++++++++++++++- webclient/src/store/server/server.types.ts | 6 ++ webclient/src/types/user.ts | 9 +++ .../commands/moderator/getWarnList.ts | 2 +- .../websocket/persistence/AdminPresistence.ts | 2 +- .../persistence/ModeratorPresistence.ts | 12 ++-- 9 files changed, 148 insertions(+), 10 deletions(-) diff --git a/webclient/src/store/server/server.actions.ts b/webclient/src/store/server/server.actions.ts index 17ab2fa66..ed1f06977 100644 --- a/webclient/src/store/server/server.actions.ts +++ b/webclient/src/store/server/server.actions.ts @@ -131,6 +131,12 @@ export const Actions = { resetPasswordSuccess: () => ({ type: Types.RESET_PASSWORD_SUCCESS, }), + adjustMod: (userName, shouldBeMod, shouldBeJudge) => ({ + type: Types.ADJUST_MOD, + userName, + shouldBeMod, + shouldBeJudge, + }), reloadConfig: () => ({ type: Types.RELOAD_CONFIG, }), @@ -182,4 +188,26 @@ export const Actions = { list, userName, }), + banFromServer: (userName) => ({ + type: Types.BAN_FROM_SERVER, + userName, + }), + banHistory: (userName, banHistory) => ({ + type: Types.BAN_HISTORY, + userName, + banHistory, + }), + warnHistory: (userName, warnHistory) => ({ + type: Types.WARN_HISTORY, + userName, + warnHistory, + }), + warnListOptions: (warnList) => ({ + type: Types.WARN_LIST_OPTIONS, + warnList, + }), + warnUser: (userName) => ({ + type: Types.WARN_USER, + userName, + }), } diff --git a/webclient/src/store/server/server.dispatch.ts b/webclient/src/store/server/server.dispatch.ts index 50b09ca9c..3a958043a 100644 --- a/webclient/src/store/server/server.dispatch.ts +++ b/webclient/src/store/server/server.dispatch.ts @@ -120,6 +120,9 @@ export const Dispatch = { resetPasswordSuccess: () => { store.dispatch(Actions.resetPasswordSuccess()); }, + adjustMod: (userName, shouldBeMod, shouldBeJudge) => { + store.dispatch(Actions.adjustMod(userName, shouldBeMod, shouldBeJudge)); + }, reloadConfig: () => { store.dispatch(Actions.reloadConfig()); }, @@ -159,4 +162,19 @@ export const Dispatch = { removeFromList: (list, userName) => { store.dispatch(Actions.removeFromList(list, userName)) }, + banFromServer: (userName) => { + store.dispatch(Actions.banFromServer(userName)); + }, + banHistory: (userName, banHistory) => { + store.dispatch(Actions.banHistory(userName, banHistory)) + }, + warnHistory: (userName, warnHistory) => { + store.dispatch(Actions.warnHistory(userName, warnHistory)) + }, + warnListOptions: (warnList) => { + store.dispatch(Actions.warnListOptions(warnList)) + }, + warnUser: (userName) => { + store.dispatch(Actions.warnUser(userName)) + }, } diff --git a/webclient/src/store/server/server.interfaces.ts b/webclient/src/store/server/server.interfaces.ts index bd68fc861..499197852 100644 --- a/webclient/src/store/server/server.interfaces.ts +++ b/webclient/src/store/server/server.interfaces.ts @@ -1,4 +1,4 @@ -import { LogItem, SortBy, User, UserSortField, WebSocketConnectOptions } from 'types'; +import { WarnHistoryItem, BanHistoryItem, LogItem, SortBy, User, UserSortField, WebSocketConnectOptions, WarnListItem } from 'types'; import { NotifyUserData, ServerShutdownData, UserMessageData } from 'websocket/events/session/interfaces'; export interface ServerConnectParams { @@ -58,6 +58,15 @@ export interface ServerState { } notifications: NotifyUserData[]; serverShutdown: ServerShutdownData; + banUser: string; + banHistory: { + [userName: string]: BanHistoryItem[]; + }; + warnHistory: { + [userName: string]: WarnHistoryItem[]; + }; + warnListOptions: WarnListItem[]; + warnUser: string; } export interface ServerStateStatus { diff --git a/webclient/src/store/server/server.reducer.ts b/webclient/src/store/server/server.reducer.ts index 5fd29e47b..46daa4007 100644 --- a/webclient/src/store/server/server.reducer.ts +++ b/webclient/src/store/server/server.reducer.ts @@ -1,4 +1,4 @@ -import { SortDirection, StatusEnum, UserSortField } from 'types'; +import { SortDirection, StatusEnum, UserLevelFlag, UserSortField } from 'types'; import { SortUtil } from '../common'; @@ -35,6 +35,11 @@ const initialState: ServerState = { userInfo: {}, notifications: [], serverShutdown: null, + banUser: '', + banHistory: {}, + warnHistory: {}, + warnListOptions: [], + warnUser: '', }; export const serverReducer = (state = initialState, action: any) => { @@ -278,6 +283,69 @@ export const serverReducer = (state = initialState, action: any) => { serverShutdown: data, }; } + case Types.BAN_FROM_SERVER: { + const { userName } = action; + + return { + ...state, + banUser: userName, + }; + } + case Types.BAN_HISTORY: { + const { userName, banHistory } = action; + + return { + ...state, + banHistory: { + ...state.banHistory, + [userName]: banHistory, + } + }; + } + case Types.WARN_HISTORY: { + const { userName, warnHistory } = action; + + return { + ...state, + warnHistory: { + ...state.warnHistory, + [userName]: warnHistory, + } + }; + } + case Types.WARN_LIST_OPTIONS: { + const { warnList } = action; + + return { + ...state, + warnListOptions: warnList, + }; + } + case Types.WARN_USER: { + const { userName } = action; + return { + ...state, + warnUser: userName, + }; + } + case Types.ADJUST_MOD: { + const { userName, shouldBeMod, shouldBeJudge } = action; + + return { + ...state, + users: state.users.map((user) => { + if (user.name !== userName) { + return user; + } + const judgeFlag = shouldBeJudge ? UserLevelFlag.IsJudge : UserLevelFlag.IsNothing; + const modFlag = shouldBeMod ? UserLevelFlag.IsModerator : UserLevelFlag.IsNothing; + return { + ...user, + userLevel: user.userLevel & (judgeFlag | modFlag) + } + }) + }; + } default: return state; } diff --git a/webclient/src/store/server/server.types.ts b/webclient/src/store/server/server.types.ts index 2a6a63104..ab9307295 100644 --- a/webclient/src/store/server/server.types.ts +++ b/webclient/src/store/server/server.types.ts @@ -35,6 +35,7 @@ export const Types = { RESET_PASSWORD_FAILED: '[Server] Reset Password Failed', RESET_PASSWORD_CHALLENGE: '[Server] Reset Password Challenge', RESET_PASSWORD_SUCCESS: '[Server] Reset Password Success', + ADJUST_MOD: '[Server] Adjust Mod', RELOAD_CONFIG: '[Server] Reload Config', SHUTDOWN_SERVER: '[Server] Shutdown Server', UPDATE_SERVER_MESSAGE: '[Server] Update Server Message', @@ -48,4 +49,9 @@ export const Types = { USER_MESSAGE: '[Server] User Message', ADD_TO_LIST: '[Server] Add To List', REMOVE_FROM_LIST: '[Server] Remove From List', + BAN_FROM_SERVER: '[Server] Ban From Server', + BAN_HISTORY: '[Server] Ban History', + WARN_HISTORY: '[Server] Warn History', + WARN_LIST_OPTIONS: '[Server] Warn List Options', + WARN_USER: '[Server] Warn User', }; diff --git a/webclient/src/types/user.ts b/webclient/src/types/user.ts index 9dab52e0d..2d0383eb7 100644 --- a/webclient/src/types/user.ts +++ b/webclient/src/types/user.ts @@ -8,6 +8,15 @@ export interface User { avatarBmp?: Uint8Array; } +export enum UserLevelFlag { + IsNothing = 0, + IsUser = 1, + IsRegistered = 2, + IsModerator = 4, + IsAdmin = 8, + IsJudge = 16, +} + export enum UserPrivLevel { NONE = 0, VIP = 1, diff --git a/webclient/src/websocket/commands/moderator/getWarnList.ts b/webclient/src/websocket/commands/moderator/getWarnList.ts index 83be78c89..f83e5eb1b 100644 --- a/webclient/src/websocket/commands/moderator/getWarnList.ts +++ b/webclient/src/websocket/commands/moderator/getWarnList.ts @@ -13,7 +13,7 @@ export function getWarnList(modName: string, userName: string, userClientid: str switch (responseCode) { case webClient.protobuf.controller.Response.ResponseCode.RespOk: const { warning } = raw['.Response_WarnList.ext']; - ModeratorPersistence.warnList(warning); + ModeratorPersistence.warnListOptions(warning); return; default: error = 'Failed to get warn list.'; diff --git a/webclient/src/websocket/persistence/AdminPresistence.ts b/webclient/src/websocket/persistence/AdminPresistence.ts index 1fd9c3db6..9552d8abf 100644 --- a/webclient/src/websocket/persistence/AdminPresistence.ts +++ b/webclient/src/websocket/persistence/AdminPresistence.ts @@ -2,7 +2,7 @@ import { ServerDispatch } from 'store'; export class AdminPersistence { static adjustMod(userName: string, shouldBeMod: boolean, shouldBeJudge: boolean) { - console.log('adjustMod'); + ServerDispatch.adjustMod(userName, shouldBeMod, shouldBeJudge) } static reloadConfig() { diff --git a/webclient/src/websocket/persistence/ModeratorPresistence.ts b/webclient/src/websocket/persistence/ModeratorPresistence.ts index 4b2f1a6d2..e6a57f601 100644 --- a/webclient/src/websocket/persistence/ModeratorPresistence.ts +++ b/webclient/src/websocket/persistence/ModeratorPresistence.ts @@ -5,11 +5,11 @@ import NormalizeService from '../utils/NormalizeService'; export class ModeratorPersistence { static banFromServer(userName: string): void { - console.log(userName); + ServerDispatch.banFromServer(userName); } static banHistory(userName: string, banHistory: BanHistoryItem[]): void { - console.log(userName, banHistory); + ServerDispatch.banHistory(userName, banHistory); } static viewLogs(logs: LogItem[]): void { @@ -17,14 +17,14 @@ export class ModeratorPersistence { } static warnHistory(userName: string, warnHistory: WarnHistoryItem[]): void { - console.log(userName, warnHistory); + ServerDispatch.warnHistory(userName, warnHistory); } - static warnList(warnList: WarnListItem[]): void { - console.log(warnList); + static warnListOptions(warnList: WarnListItem[]): void { + ServerDispatch.warnListOptions(warnList); } static warnUser(userName: string): void { - console.log(userName); + ServerDispatch.warnUser(userName); } }