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