mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add user flags field
This commit is contained in:
@@ -66,3 +66,4 @@ export { UpdateNetworkTimeVerificationAction } from './updatenetworktimeverifica
|
||||
export { UpdateParentBlockedTimesAction } from './updateparentblockedtimes'
|
||||
export { UpdateParentNotificationFlagsAction } from './updateparentnotificationflags'
|
||||
export { UpdateTimelimitRuleAction } from './updatetimelimitrule'
|
||||
export { UpdateUserFlagsAction } from './updateuserflags'
|
||||
|
||||
@@ -55,6 +55,7 @@ import { SerialiizedUpdateNetworkTimeVerificationAction, UpdateNetworkTimeVerifi
|
||||
import { SerializedUpdateParentBlockedTimesAction, UpdateParentBlockedTimesAction } from '../updateparentblockedtimes'
|
||||
import { SerializedUpdateParentNotificationFlagsAction, UpdateParentNotificationFlagsAction } from '../updateparentnotificationflags'
|
||||
import { SerializedUpdateTimelimitRuleAction, UpdateTimelimitRuleAction } from '../updatetimelimitrule'
|
||||
import { SerializedUpdateUserFlagsAction, UpdateUserFlagsAction } from '../updateuserflags'
|
||||
|
||||
export type SerializedParentAction =
|
||||
SerializedAddCategoryAppsAction |
|
||||
@@ -95,7 +96,8 @@ export type SerializedParentAction =
|
||||
SerialiizedUpdateNetworkTimeVerificationAction |
|
||||
SerializedUpdateParentBlockedTimesAction |
|
||||
SerializedUpdateParentNotificationFlagsAction |
|
||||
SerializedUpdateTimelimitRuleAction
|
||||
SerializedUpdateTimelimitRuleAction |
|
||||
SerializedUpdateUserFlagsAction
|
||||
|
||||
export const parseParentAction = (action: SerializedParentAction): ParentAction => {
|
||||
if (action.type === 'ADD_CATEGORY_APPS') {
|
||||
@@ -176,6 +178,8 @@ export const parseParentAction = (action: SerializedParentAction): ParentAction
|
||||
return UpdateParentNotificationFlagsAction.parse(action)
|
||||
} else if (action.type === 'UPDATE_TIMELIMIT_RULE') {
|
||||
return UpdateTimelimitRuleAction.parse(action)
|
||||
} else if (action.type === 'UPDATE_USER_FLAGS') {
|
||||
return UpdateUserFlagsAction.parse(action)
|
||||
} else {
|
||||
throw new Error('illegal state: invalid type for action at parseParentAction')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { UserFlags } from '../model/userflags'
|
||||
import { assertIdWithinFamily } from '../util/token'
|
||||
import { ParentAction } from './basetypes'
|
||||
|
||||
export class UpdateUserFlagsAction extends ParentAction {
|
||||
readonly userId: string
|
||||
readonly modifiedBits: number
|
||||
readonly newValues: number
|
||||
|
||||
constructor ({ userId, modifiedBits, newValues }: {
|
||||
userId: string
|
||||
modifiedBits: number
|
||||
newValues: number
|
||||
}) {
|
||||
super()
|
||||
|
||||
assertIdWithinFamily(userId)
|
||||
|
||||
if ((!Number.isSafeInteger(modifiedBits)) || (!Number.isSafeInteger(newValues))) {
|
||||
throw new Error('flags must be an integer')
|
||||
}
|
||||
|
||||
if ((modifiedBits | UserFlags.ALL_FLAGS) !== UserFlags.ALL_FLAGS || (modifiedBits | newValues) !== modifiedBits) {
|
||||
throw new Error('flags are out of the valid range')
|
||||
}
|
||||
|
||||
this.userId = userId
|
||||
this.modifiedBits = modifiedBits
|
||||
this.newValues = newValues
|
||||
}
|
||||
|
||||
serialize = (): SerializedUpdateUserFlagsAction => ({
|
||||
type: 'UPDATE_USER_FLAGS',
|
||||
userId: this.userId,
|
||||
modified: this.modifiedBits,
|
||||
values: this.newValues
|
||||
})
|
||||
|
||||
static parse = ({ userId, modified, values }: SerializedUpdateUserFlagsAction) => (
|
||||
new UpdateUserFlagsAction({
|
||||
userId,
|
||||
modifiedBits: modified,
|
||||
newValues: values
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedUpdateUserFlagsAction {
|
||||
type: 'UPDATE_USER_FLAGS'
|
||||
userId: string
|
||||
modified: number
|
||||
values: number
|
||||
}
|
||||
Reference in New Issue
Block a user