Admin persistence changes (#5086)

This commit is contained in:
Joseph Insalaco 2024-08-16 22:31:57 -04:00 committed by GitHub
parent 090a48515c
commit b111f0921c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 148 additions and 10 deletions

View file

@ -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,
}),
}

View file

@ -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))
},
}

View file

@ -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 {

View file

@ -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;
}

View file

@ -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',
};

View file

@ -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,

View file

@ -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.';

View file

@ -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() {

View file

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