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:
@@ -82,7 +82,8 @@ export const createFamily = async ({ database, mailAuthToken, firstParentDevice,
|
||||
categoryForNotAssignedApps: '',
|
||||
relaxPrimaryDeviceRule: false,
|
||||
mailNotificationFlags: 1, // enable warning notifications
|
||||
blockedTimes: ''
|
||||
blockedTimes: '',
|
||||
flags: '0'
|
||||
}, { transaction })
|
||||
|
||||
// add parent device
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 Jonas Lochmann
|
||||
* 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
|
||||
@@ -37,7 +37,8 @@ export async function dispatchAddUser ({ action, cache }: {
|
||||
categoryForNotAssignedApps: '',
|
||||
relaxPrimaryDeviceRule: false,
|
||||
mailNotificationFlags: 0,
|
||||
blockedTimes: ''
|
||||
blockedTimes: '',
|
||||
flags: '0'
|
||||
}, { transaction: cache.transaction })
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
|
||||
@@ -55,7 +55,8 @@ import {
|
||||
UpdateNetworkTimeVerificationAction,
|
||||
UpdateParentBlockedTimesAction,
|
||||
UpdateParentNotificationFlagsAction,
|
||||
UpdateTimelimitRuleAction
|
||||
UpdateTimelimitRuleAction,
|
||||
UpdateUserFlagsAction
|
||||
} from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
import { dispatchAddCategoryApps } from './addcategoryapps'
|
||||
@@ -97,6 +98,7 @@ import { dispatchUpdateNetworkTimeVerification } from './updatenetworktimeverifi
|
||||
import { dispatchUpdateParentBlockedTimes } from './updateparentblockedtimes'
|
||||
import { dispatchUpdateParentNotificationFlags } from './updateparentnotificationflags'
|
||||
import { dispatchUpdateTimelimitRule } from './updatetimelimitrule'
|
||||
import { dispatchUpdateUserFlagsAction } from './updateuserflags'
|
||||
|
||||
export const dispatchParentAction = async ({ action, cache, parentUserId, sourceDeviceId }: {
|
||||
action: ParentAction
|
||||
@@ -182,6 +184,8 @@ export const dispatchParentAction = async ({ action, cache, parentUserId, source
|
||||
await dispatchResetParentBlockedTimes({ action, cache })
|
||||
} else if (action instanceof UpdateParentBlockedTimesAction) {
|
||||
await dispatchUpdateParentBlockedTimes({ action, cache })
|
||||
} else if (action instanceof UpdateUserFlagsAction) {
|
||||
await dispatchUpdateUserFlagsAction({ action, cache })
|
||||
} else {
|
||||
throw new Error('unsupported action type')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 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 { UpdateUserFlagsAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
|
||||
export async function dispatchUpdateUserFlagsAction ({ action, cache }: {
|
||||
action: UpdateUserFlagsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const userEntry = await cache.database.user.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
userId: action.userId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (!userEntry) {
|
||||
throw new Error('user not found')
|
||||
}
|
||||
|
||||
const oldFlags = parseInt(userEntry.flags, 10)
|
||||
|
||||
if (!Number.isSafeInteger(oldFlags)) {
|
||||
throw new Error()
|
||||
}
|
||||
|
||||
const newFlags = (oldFlags & ~action.modifiedBits) | action.newValues
|
||||
|
||||
userEntry.flags = newFlags.toString(10)
|
||||
|
||||
await userEntry.save({ transaction: cache.transaction })
|
||||
|
||||
cache.invalidiateUserList = true
|
||||
}
|
||||
@@ -125,7 +125,8 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI
|
||||
'categoryForNotAssignedApps',
|
||||
'relaxPrimaryDeviceRule',
|
||||
'mailNotificationFlags',
|
||||
'blockedTimes'
|
||||
'blockedTimes',
|
||||
'flags'
|
||||
],
|
||||
transaction
|
||||
})).map((item) => ({
|
||||
@@ -141,7 +142,8 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI
|
||||
categoryForNotAssignedApps: item.categoryForNotAssignedApps,
|
||||
relaxPrimaryDeviceRule: item.relaxPrimaryDeviceRule,
|
||||
mailNotificationFlags: item.mailNotificationFlags,
|
||||
blockedTimes: item.blockedTimes
|
||||
blockedTimes: item.blockedTimes,
|
||||
flags: item.flags
|
||||
}))
|
||||
|
||||
result.users = {
|
||||
@@ -159,7 +161,8 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI
|
||||
categoryForNotAssignedApps: item.categoryForNotAssignedApps,
|
||||
relaxPrimaryDevice: item.relaxPrimaryDeviceRule,
|
||||
mailNotificationFlags: item.mailNotificationFlags,
|
||||
blockedTimes: item.blockedTimes
|
||||
blockedTimes: item.blockedTimes,
|
||||
flags: parseInt(item.flags, 10)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user