Remove parent blocked time support

This commit is contained in:
Jonas Lochmann
2020-12-21 01:00:00 +01:00
parent 3baab5072f
commit 9dc797a96c
13 changed files with 45 additions and 528 deletions
-2
View File
@@ -38,7 +38,6 @@ export { RemoveInstalledAppsAction } from './removeinstalledapps'
export { RemoveUserAction } from './removeuser'
export { ResetCategoryNetworkIdsAction } from './resetcategorynetworkids'
export { RenameChildAction } from './renamechild'
export { ResetParentBlockedTimesAction } from './resetparentblockedtimes'
export { SetCategoryExtraTimeAction } from './setcategoryextratime'
export { SetCategoryForUnassignedAppsAction } from './setcategoryforunassignedapps'
export { SetChildPasswordAction } from './setchildpassword'
@@ -67,7 +66,6 @@ export { UpdateDeviceNameAction } from './updatedevicename'
export { UpdateDeviceStatusAction } from './updatedevicestatus'
export { UpdateEnableActivityLevelBlockingAction } from './updateenableactivitylevelblocking'
export { UpdateNetworkTimeVerificationAction } from './updatenetworktimeverification'
export { UpdateParentBlockedTimesAction } from './updateparentblockedtimes'
export { UpdateParentNotificationFlagsAction } from './updateparentnotificationflags'
export { UpdateTimelimitRuleAction } from './updatetimelimitrule'
export { UpdateUserFlagsAction } from './updateuserflags'
-46
View File
@@ -1,46 +0,0 @@
/*
* 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 { ParentAction } from './basetypes'
import { assertIdWithinFamily } from './meta/util'
const actionType = 'ResetParentBlockedTimesAction'
export class ResetParentBlockedTimesAction extends ParentAction {
readonly parentId: string
constructor ({ parentId }: {
parentId: string
}) {
super()
assertIdWithinFamily({ actionType, field: 'parentId', value: parentId })
this.parentId = parentId
}
static parse = ({ parentId }: SerializedResetParentBlockedTimesAction) => (
new ResetParentBlockedTimesAction({
parentId
})
)
}
export interface SerializedResetParentBlockedTimesAction {
type: 'RESET_PARENT_BLOCKED_TIMES'
parentId: string
}
-8
View File
@@ -32,7 +32,6 @@ import { RemoveCategoryAppsAction, SerializedRemoveCategoryAppsAction } from '..
import { RemoveUserAction, SerializedRemoveUserAction } from '../removeuser'
import { RenameChildAction, SerializedRenameChildAction } from '../renamechild'
import { ResetCategoryNetworkIdsAction, SerializeResetCategoryNetworkIdsAction } from '../resetcategorynetworkids'
import { ResetParentBlockedTimesAction, SerializedResetParentBlockedTimesAction } from '../resetparentblockedtimes'
import { ReviewChildTaskAction, SerializedReviewChildTaskAction } from '../reviewchildtaskaction'
import { SerializedSetCategoryExtraTimeAction, SetCategoryExtraTimeAction } from '../setcategoryextratime'
import { SerializedSetCategoryForUnassignedAppsAction, SetCategoryForUnassignedAppsAction } from '../setcategoryforunassignedapps'
@@ -59,7 +58,6 @@ import { SerializedUpdateChildTaskAction, UpdateChildTaskAction } from '../updat
import { SerializedUpdateDeviceNameAction, UpdateDeviceNameAction } from '../updatedevicename'
import { SerializedUpdateEnableActivityLevelBlockingAction, UpdateEnableActivityLevelBlockingAction } from '../updateenableactivitylevelblocking'
import { SerialiizedUpdateNetworkTimeVerificationAction, UpdateNetworkTimeVerificationAction } from '../updatenetworktimeverification'
import { SerializedUpdateParentBlockedTimesAction, UpdateParentBlockedTimesAction } from '../updateparentblockedtimes'
import { SerializedUpdateParentNotificationFlagsAction, UpdateParentNotificationFlagsAction } from '../updateparentnotificationflags'
import { SerializedUpdateTimelimitRuleAction, UpdateTimelimitRuleAction } from '../updatetimelimitrule'
import { SerializedUpdateUserFlagsAction, UpdateUserFlagsAction } from '../updateuserflags'
@@ -81,7 +79,6 @@ export type SerializedParentAction =
SerializedRemoveUserAction |
SerializedRenameChildAction |
SerializeResetCategoryNetworkIdsAction |
SerializedResetParentBlockedTimesAction |
SerializedReviewChildTaskAction |
SerializedSetCategoryForUnassignedAppsAction |
SerializedSetChildPasswordAction |
@@ -108,7 +105,6 @@ export type SerializedParentAction =
SerializedUpdateDeviceNameAction |
SerializedUpdateEnableActivityLevelBlockingAction |
SerialiizedUpdateNetworkTimeVerificationAction |
SerializedUpdateParentBlockedTimesAction |
SerializedUpdateParentNotificationFlagsAction |
SerializedUpdateTimelimitRuleAction |
SerializedUpdateUserFlagsAction |
@@ -145,8 +141,6 @@ export const parseParentAction = (action: SerializedParentAction): ParentAction
return RenameChildAction.parse(action)
} else if (action.type === 'RESET_CATEGORY_NETWORK_IDS') {
return ResetCategoryNetworkIdsAction.parse(action)
} else if (action.type === 'RESET_PARENT_BLOCKED_TIMES') {
return ResetParentBlockedTimesAction.parse(action)
} else if (action.type === 'REVIEW_CHILD_TASK') {
return ReviewChildTaskAction.parse(action)
} else if (action.type === 'SET_CATEGORY_EXTRA_TIME') {
@@ -199,8 +193,6 @@ export const parseParentAction = (action: SerializedParentAction): ParentAction
return UpdateEnableActivityLevelBlockingAction.parse(action)
} else if (action.type === 'UPDATE_NETWORK_TIME_VERIFICATION') {
return UpdateNetworkTimeVerificationAction.parse(action)
} else if (action.type === 'UPDATE_PARENT_BLOCKED_TIMES') {
return UpdateParentBlockedTimesAction.parse(action)
} else if (action.type === 'UPDATE_PARENT_NOTIFICATION_FLAGS') {
return UpdateParentNotificationFlagsAction.parse(action)
} else if (action.type === 'UPDATE_TIMELIMIT_RULE') {
-81
View File
@@ -1,81 +0,0 @@
/*
* 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 { BitmapValidationException, validateAndParseBitmask } from '../util/bitmask'
import { ParentAction } from './basetypes'
import { InvalidActionParameterException } from './meta/exception'
import { assertIdWithinFamily } from './meta/util'
const actionType = 'UpdateParentBlockedTimesAction'
export class UpdateParentBlockedTimesAction extends ParentAction {
readonly parentId: string
readonly blockedTimes: string
constructor ({ parentId, blockedTimes }: {
parentId: string
blockedTimes: string
}) {
super()
assertIdWithinFamily({ actionType, field: 'parentId', value: parentId })
try {
const parsedBlockedTimes = validateAndParseBitmask(blockedTimes, 60 * 24 * 7 /* number of minutes per week */)
for (let day = 0; day < 7; day++) {
let blockedMinutes = 0
for (let minute = 0; minute < 60 * 24 /* 1 day */; minute++) {
if (parsedBlockedTimes[day * 60 * 24 + minute]) {
blockedMinutes++
}
}
if (blockedMinutes > 60 * 18 /* 18 hours */) {
throw new InvalidActionParameterException({
actionType,
staticMessage: 'too much blocked minutes per day'
})
}
}
} catch (ex) {
if (ex instanceof BitmapValidationException) {
throw new InvalidActionParameterException({
actionType,
staticMessage: 'invalid bitmask'
})
} else throw ex
}
this.parentId = parentId
this.blockedTimes = blockedTimes
}
static parse = ({ parentId, times }: SerializedUpdateParentBlockedTimesAction) => (
new UpdateParentBlockedTimesAction({
parentId,
blockedTimes: times
})
)
}
export interface SerializedUpdateParentBlockedTimesAction {
type: 'UPDATE_PARENT_BLOCKED_TIMES'
parentId: string
times: string
}
-48
View File
@@ -572,25 +572,6 @@ const definitions = {
"type"
]
},
"SerializedResetParentBlockedTimesAction": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"RESET_PARENT_BLOCKED_TIMES"
]
},
"parentId": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"parentId",
"type"
]
},
"SerializedReviewChildTaskAction": {
"type": "object",
"properties": {
@@ -1221,29 +1202,6 @@ const definitions = {
"type"
]
},
"SerializedUpdateParentBlockedTimesAction": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"UPDATE_PARENT_BLOCKED_TIMES"
]
},
"parentId": {
"type": "string"
},
"times": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"parentId",
"times",
"type"
]
},
"SerializedUpdateParentNotificationFlagsAction": {
"type": "object",
"properties": {
@@ -2648,9 +2606,6 @@ export const isSerializedParentAction: (value: object) => value is SerializedPar
{
"$ref": "#/definitions/SerializeResetCategoryNetworkIdsAction"
},
{
"$ref": "#/definitions/SerializedResetParentBlockedTimesAction"
},
{
"$ref": "#/definitions/SerializedReviewChildTaskAction"
},
@@ -2729,9 +2684,6 @@ export const isSerializedParentAction: (value: object) => value is SerializedPar
{
"$ref": "#/definitions/SerialiizedUpdateNetworkTimeVerificationAction"
},
{
"$ref": "#/definitions/SerializedUpdateParentBlockedTimesAction"
},
{
"$ref": "#/definitions/SerializedUpdateParentNotificationFlagsAction"
},
+1
View File
@@ -52,6 +52,7 @@ export interface UserAttributesVersion4 {
}
export interface UserAttributesVersion5 {
// currently unused
blockedTimes: string
}
@@ -32,7 +32,6 @@ import {
RemoveUserAction,
RenameChildAction,
ResetCategoryNetworkIdsAction,
ResetParentBlockedTimesAction,
ReviewChildTaskAction,
SetCategoryExtraTimeAction,
SetCategoryForUnassignedAppsAction,
@@ -59,7 +58,6 @@ import {
UpdateDeviceNameAction,
UpdateEnableActivityLevelBlockingAction,
UpdateNetworkTimeVerificationAction,
UpdateParentBlockedTimesAction,
UpdateParentNotificationFlagsAction,
UpdateTimelimitRuleAction,
UpdateUserFlagsAction,
@@ -83,7 +81,6 @@ import { dispatchRemoveCategoryApps } from './removecategoryapps'
import { dispatchRemoveUser } from './removeuser'
import { dispatchRenameChild } from './renamechild'
import { dispatchResetCategoryNetworkIds } from './resetcategorynetworkids'
import { dispatchResetParentBlockedTimes } from './resetparentblockedtimes'
import { dispatchReviewChildTaskAction } from './reviewchildtaskaction'
import { dispatchSetCategoryExtraTime } from './setcategoryextratime'
import { dispatchSetCategoryForUnassignedApps } from './setcategoryforunassignedapps'
@@ -110,7 +107,6 @@ import { dispatchUpdateChildTaskAction } from './updatechildtaskaction'
import { dispatchUpdateDeviceName } from './updatedevicename'
import { dispatchUpdateEnableActivityLevelBlocking } from './updateenableactivitylevelblocking'
import { dispatchUpdateNetworkTimeVerification } from './updatenetworktimeverification'
import { dispatchUpdateParentBlockedTimes } from './updateparentblockedtimes'
import { dispatchUpdateParentNotificationFlags } from './updateparentnotificationflags'
import { dispatchUpdateTimelimitRule } from './updatetimelimitrule'
import { dispatchUpdateUserFlagsAction } from './updateuserflags'
@@ -208,10 +204,6 @@ export const dispatchParentAction = async ({ action, cache, parentUserId, source
return dispatchIgnoreManipulation({ action, cache })
} else if (action instanceof UpdateCategoryTimeWarningsAction) {
return dispatchUpdateCategoryTimeWarnings({ action, cache })
} else if (action instanceof ResetParentBlockedTimesAction) {
return dispatchResetParentBlockedTimes({ action, cache })
} else if (action instanceof UpdateParentBlockedTimesAction) {
return dispatchUpdateParentBlockedTimes({ action, cache, parentUserId })
} else if (action instanceof UpdateUserFlagsAction) {
return dispatchUpdateUserFlagsAction({ action, cache })
} else if (action instanceof UpdateUserLimitLoginCategory) {
@@ -1,52 +0,0 @@
/*
* 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 { ResetParentBlockedTimesAction } from '../../../../action'
import { Cache } from '../cache'
import { MissingUserException } from '../exception/missing-item'
export async function dispatchResetParentBlockedTimes ({ action, cache }: {
action: ResetParentBlockedTimesAction
cache: Cache
}) {
const oldItem = await cache.database.user.findOne({
where: {
familyId: cache.familyId,
userId: action.parentId,
type: 'parent'
},
transaction: cache.transaction
})
if (!oldItem) {
throw new MissingUserException()
}
await cache.database.user.update({
blockedTimes: ''
}, {
where: {
familyId: cache.familyId,
userId: action.parentId,
type: 'parent'
},
transaction: cache.transaction
})
cache.invalidiateUserList = true
cache.areChangesImportant = true
}
@@ -1,58 +0,0 @@
/*
* 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 { UpdateParentBlockedTimesAction } from '../../../../action'
import { Cache } from '../cache'
import { ApplyActionException } from '../exception/index'
import { MissingUserException } from '../exception/missing-item'
export async function dispatchUpdateParentBlockedTimes ({ action, cache, parentUserId }: {
action: UpdateParentBlockedTimesAction
cache: Cache
parentUserId: string
}) {
if (parentUserId !== action.parentId && action.blockedTimes !== '') {
throw new ApplyActionException({ staticMessage: 'only a parent itself can add limits' })
}
const oldUser = await cache.database.user.findOne({
where: {
familyId: cache.familyId,
userId: action.parentId,
type: 'parent'
},
transaction: cache.transaction
})
if (!oldUser) {
throw new MissingUserException()
}
await cache.database.user.update({
blockedTimes: action.blockedTimes
}, {
where: {
familyId: cache.familyId,
userId: action.parentId,
type: 'parent'
},
transaction: cache.transaction
})
cache.invalidiateUserList = true
cache.areChangesImportant = true
}
@@ -42,7 +42,6 @@ export async function getUserList ({ database, transaction, familyEntry }: {
'categoryForNotAssignedApps',
'relaxPrimaryDeviceRule',
'mailNotificationFlags',
'blockedTimes',
'flags'
],
transaction
@@ -59,7 +58,6 @@ export async function getUserList ({ database, transaction, familyEntry }: {
categoryForNotAssignedApps: item.categoryForNotAssignedApps,
relaxPrimaryDeviceRule: item.relaxPrimaryDeviceRule,
mailNotificationFlags: item.mailNotificationFlags,
blockedTimes: item.blockedTimes,
flags: item.flags
}))
@@ -102,7 +100,7 @@ export async function getUserList ({ database, transaction, familyEntry }: {
categoryForNotAssignedApps: item.categoryForNotAssignedApps,
relaxPrimaryDevice: item.relaxPrimaryDeviceRule,
mailNotificationFlags: item.mailNotificationFlags,
blockedTimes: item.blockedTimes,
blockedTimes: '',
flags: parseInt(item.flags, 10),
llc: getLimitLoginCategory(item.userId)
}))