mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add child task support
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 = 'DeleteChildTaskAction'
|
||||
|
||||
export class DeleteChildTaskAction extends ParentAction {
|
||||
readonly taskId: string
|
||||
|
||||
constructor ({ taskId }: { taskId: string }) {
|
||||
super()
|
||||
|
||||
assertIdWithinFamily({ actionType, field: 'taskId', value: taskId })
|
||||
|
||||
this.taskId = taskId
|
||||
}
|
||||
|
||||
static parse = ({ taskId }: SerializedDeleteChildTaskAction) => (
|
||||
new DeleteChildTaskAction({ taskId })
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedDeleteChildTaskAction {
|
||||
type: 'DELETE_CHILD_TASK'
|
||||
taskId: string
|
||||
}
|
||||
@@ -72,3 +72,7 @@ export { UpdateParentNotificationFlagsAction } from './updateparentnotificationf
|
||||
export { UpdateTimelimitRuleAction } from './updatetimelimitrule'
|
||||
export { UpdateUserFlagsAction } from './updateuserflags'
|
||||
export { UpdateUserLimitLoginCategory } from './updateuserlimitlogincategory'
|
||||
export { MarkTaskPendingAction } from './marktaskpendingaction'
|
||||
export { DeleteChildTaskAction } from './deletechildtaskaction'
|
||||
export { UpdateChildTaskAction } from './updatechildtaskaction'
|
||||
export { ReviewChildTaskAction } from './reviewchildtaskaction'
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 { AppLogicAction } from './basetypes'
|
||||
import { assertIdWithinFamily } from './meta/util'
|
||||
|
||||
const actionType = 'MarkTaskPendingAction'
|
||||
|
||||
export class MarkTaskPendingAction extends AppLogicAction {
|
||||
readonly taskId: string
|
||||
|
||||
constructor ({ taskId }: { taskId: string }) {
|
||||
super()
|
||||
|
||||
assertIdWithinFamily({ actionType, field: 'taskId', value: taskId })
|
||||
|
||||
this.taskId = taskId
|
||||
}
|
||||
|
||||
static parse = ({ taskId }: SerializedMarkTaskPendingAction) => (
|
||||
new MarkTaskPendingAction({ taskId })
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedMarkTaskPendingAction {
|
||||
type: 'MARK_TASK_PENDING'
|
||||
taskId: string
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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, assertSafeInteger, throwOutOfRange } from './meta/util'
|
||||
|
||||
const actionType = 'ReviewChildTaskAction'
|
||||
|
||||
export class ReviewChildTaskAction extends ParentAction {
|
||||
readonly taskId: string
|
||||
readonly ok: boolean
|
||||
readonly time: number
|
||||
|
||||
constructor ({ taskId, ok, time }: {
|
||||
taskId: string
|
||||
ok: boolean
|
||||
time: number
|
||||
}) {
|
||||
super()
|
||||
|
||||
assertIdWithinFamily({ actionType, field: 'taskId', value: taskId })
|
||||
assertSafeInteger({ actionType, field: 'time', value: time })
|
||||
|
||||
if (time <= 0) {
|
||||
throwOutOfRange({ actionType, field: 'time', value: time })
|
||||
}
|
||||
|
||||
this.taskId = taskId
|
||||
this.ok = ok
|
||||
this.time = time
|
||||
}
|
||||
|
||||
static parse = ({ taskId, ok, time }: SerializedReviewChildTaskAction) => (
|
||||
new ReviewChildTaskAction({ taskId, ok, time })
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedReviewChildTaskAction {
|
||||
type: 'REVIEW_CHILD_TASK'
|
||||
taskId: string
|
||||
ok: boolean
|
||||
time: number
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import { AddUsedTimeAction, SerializedAddUsedTimeAction } from '../addusedtime'
|
||||
import { AddUsedTimeActionVersion2, SerializedAddUsedTimeActionVersion2 } from '../addusedtime2'
|
||||
import { AppLogicAction } from '../basetypes'
|
||||
import { ForceSyncAction, SerializedForceSyncAction } from '../forcesync'
|
||||
import { MarkTaskPendingAction, SerializedMarkTaskPendingAction } from '../marktaskpendingaction'
|
||||
import { UnknownActionTypeException } from '../meta/exception'
|
||||
import { RemoveInstalledAppsAction, SerializedRemoveInstalledAppsAction } from '../removeinstalledapps'
|
||||
import { SerializedSignOutAtDeviceAction, SignOutAtDeviceAction } from '../signoutatdevice'
|
||||
@@ -32,6 +33,7 @@ export type SerializedAppLogicAction =
|
||||
SerializedAddUsedTimeAction |
|
||||
SerializedAddUsedTimeActionVersion2 |
|
||||
SerializedForceSyncAction |
|
||||
SerializedMarkTaskPendingAction |
|
||||
SerializedRemoveInstalledAppsAction |
|
||||
SerializedSignOutAtDeviceAction |
|
||||
SerialiezdTriedDisablingDeviceAdminAction |
|
||||
@@ -47,6 +49,8 @@ export const parseAppLogicAction = (serialized: SerializedAppLogicAction): AppLo
|
||||
return AddInstalledAppsAction.parse(serialized)
|
||||
} else if (serialized.type === 'FORCE_SYNC') {
|
||||
return ForceSyncAction.parse(serialized)
|
||||
} else if (serialized.type === 'MARK_TASK_PENDING') {
|
||||
return MarkTaskPendingAction.parse(serialized)
|
||||
} else if (serialized.type === 'REMOVE_INSTALLED_APPS') {
|
||||
return RemoveInstalledAppsAction.parse(serialized)
|
||||
} else if (serialized.type === 'SIGN_OUT_AT_DEVICE') {
|
||||
|
||||
@@ -23,6 +23,7 @@ import { ChangeParentPasswordAction, SerializedChangeParentPasswordAction } from
|
||||
import { CreateCategoryAction, SerializedCreateCategoryAction } from '../createcategory'
|
||||
import { CreateTimeLimitRuleAction, SerializedCreateTimelimtRuleAction } from '../createtimelimitrule'
|
||||
import { DeleteCategoryAction, SerializedDeleteCategoryAction } from '../deletecategory'
|
||||
import { DeleteChildTaskAction, SerializedDeleteChildTaskAction } from '../deletechildtaskaction'
|
||||
import { DeleteTimeLimitRuleAction, SerializedDeleteTimeLimitRuleAction } from '../deletetimelimitrule'
|
||||
import { IgnoreManipulationAction, SerializedIgnoreManipulationAction } from '../ignoremanipulation'
|
||||
import { IncrementCategoryExtraTimeAction, SerializedIncrementCategoryExtraTimeAction } from '../incrementcategoryextratime'
|
||||
@@ -32,6 +33,7 @@ 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'
|
||||
import { SerializedSetChildPasswordAction, SetChildPasswordAction } from '../setchildpassword'
|
||||
@@ -53,6 +55,7 @@ import { SerializedUpdateCategorySortingAction, UpdateCategorySortingAction } fr
|
||||
import { SerializedUpdateCategoryTemporarilyBlockedAction, UpdateCategoryTemporarilyBlockedAction } from '../updatecategorytemporarilyblocked'
|
||||
import { SerializedUpdateCategoryTimeWarningsAction, UpdateCategoryTimeWarningsAction } from '../updatecategorytimewarnings'
|
||||
import { SerializedUpdateCategoryTitleAction, UpdateCategoryTitleAction } from '../updatecategorytitle'
|
||||
import { SerializedUpdateChildTaskAction, UpdateChildTaskAction } from '../updatechildtaskaction'
|
||||
import { SerializedUpdateDeviceNameAction, UpdateDeviceNameAction } from '../updatedevicename'
|
||||
import { SerializedUpdateEnableActivityLevelBlockingAction, UpdateEnableActivityLevelBlockingAction } from '../updateenableactivitylevelblocking'
|
||||
import { SerialiizedUpdateNetworkTimeVerificationAction, UpdateNetworkTimeVerificationAction } from '../updatenetworktimeverification'
|
||||
@@ -70,6 +73,7 @@ export type SerializedParentAction =
|
||||
SerializedCreateCategoryAction |
|
||||
SerializedCreateTimelimtRuleAction |
|
||||
SerializedDeleteCategoryAction |
|
||||
SerializedDeleteChildTaskAction |
|
||||
SerializedDeleteTimeLimitRuleAction |
|
||||
SerializedIgnoreManipulationAction |
|
||||
SerializedIncrementCategoryExtraTimeAction |
|
||||
@@ -78,6 +82,7 @@ export type SerializedParentAction =
|
||||
SerializedRenameChildAction |
|
||||
SerializeResetCategoryNetworkIdsAction |
|
||||
SerializedResetParentBlockedTimesAction |
|
||||
SerializedReviewChildTaskAction |
|
||||
SerializedSetCategoryForUnassignedAppsAction |
|
||||
SerializedSetChildPasswordAction |
|
||||
SerializedSetConsiderRebootManipulationAction |
|
||||
@@ -99,6 +104,7 @@ export type SerializedParentAction =
|
||||
SerializedUpdateCategoryTemporarilyBlockedAction |
|
||||
SerializedUpdateCategoryTimeWarningsAction |
|
||||
SerializedUpdateCategoryTitleAction |
|
||||
SerializedUpdateChildTaskAction |
|
||||
SerializedUpdateDeviceNameAction |
|
||||
SerializedUpdateEnableActivityLevelBlockingAction |
|
||||
SerialiizedUpdateNetworkTimeVerificationAction |
|
||||
@@ -123,6 +129,8 @@ export const parseParentAction = (action: SerializedParentAction): ParentAction
|
||||
return CreateTimeLimitRuleAction.parse(action)
|
||||
} else if (action.type === 'DELETE_CATEGORY') {
|
||||
return DeleteCategoryAction.parse(action)
|
||||
} else if (action.type === 'DELETE_CHILD_TASK') {
|
||||
return DeleteChildTaskAction.parse(action)
|
||||
} else if (action.type === 'DELETE_TIMELIMIT_RULE') {
|
||||
return DeleteTimeLimitRuleAction.parse(action)
|
||||
} else if (action.type === 'IGNORE_MANIPULATION') {
|
||||
@@ -139,6 +147,8 @@ export const parseParentAction = (action: SerializedParentAction): ParentAction
|
||||
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') {
|
||||
return SetCategoryExtraTimeAction.parse(action)
|
||||
} else if (action.type === 'SET_CATEGORY_FOR_UNASSIGNED_APPS') {
|
||||
@@ -179,6 +189,8 @@ export const parseParentAction = (action: SerializedParentAction): ParentAction
|
||||
return UpdateCategoryTimeWarningsAction.parse(action)
|
||||
} else if (action.type === 'UPDATE_CATEGORY_TITLE') {
|
||||
return UpdateCategoryTitleAction.parse(action)
|
||||
} else if (action.type === 'UPDATE_CHILD_TASK') {
|
||||
return UpdateChildTaskAction.parse(action)
|
||||
} else if (action.type === 'UPDATE_CATEGORY_TEMPORARILY_BLOCKED') {
|
||||
return UpdateCategoryTemporarilyBlockedAction.parse(action)
|
||||
} else if (action.type === 'UPDATE_DEVICE_NAME') {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 { maxExtraTime, maxTitleLength } from '../database/childtask'
|
||||
import { ParentAction } from './basetypes'
|
||||
import { InvalidActionParameterException } from './meta/exception'
|
||||
import { assertIdWithinFamily, assertSafeInteger, throwOutOfRange } from './meta/util'
|
||||
|
||||
const actionType = 'UpdateChildTaskAction'
|
||||
|
||||
export class UpdateChildTaskAction extends ParentAction {
|
||||
readonly isNew: boolean
|
||||
readonly taskId: string
|
||||
readonly categoryId: string
|
||||
readonly taskTitle: string
|
||||
readonly extraTimeDuration: number
|
||||
|
||||
constructor ({ isNew, taskId, categoryId, taskTitle, extraTimeDuration }: {
|
||||
isNew: boolean
|
||||
taskId: string
|
||||
categoryId: string
|
||||
taskTitle: string
|
||||
extraTimeDuration: number
|
||||
}) {
|
||||
super()
|
||||
|
||||
assertIdWithinFamily({ actionType, field: 'taskId', value: taskId })
|
||||
assertIdWithinFamily({ actionType, field: 'categoryId', value: categoryId })
|
||||
assertSafeInteger({ actionType, field: 'extraTimeDuration', value: extraTimeDuration })
|
||||
|
||||
if (taskTitle === '' || taskTitle.length > maxTitleLength) {
|
||||
throw new InvalidActionParameterException({ actionType, staticMessage: 'invalid title' })
|
||||
}
|
||||
|
||||
if (extraTimeDuration <= 0 || extraTimeDuration > maxExtraTime) {
|
||||
throwOutOfRange({ actionType, field: 'extraTimeDuration', value: extraTimeDuration })
|
||||
}
|
||||
|
||||
this.isNew = isNew
|
||||
this.taskId = taskId
|
||||
this.categoryId = categoryId
|
||||
this.taskTitle = taskTitle
|
||||
this.extraTimeDuration = extraTimeDuration
|
||||
}
|
||||
|
||||
static parse = ({ isNew, taskId, categoryId, taskTitle, extraTimeDuration }: SerializedUpdateChildTaskAction) => (
|
||||
new UpdateChildTaskAction({ isNew, taskId, categoryId, taskTitle, extraTimeDuration })
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedUpdateChildTaskAction {
|
||||
type: 'UPDATE_CHILD_TASK'
|
||||
isNew: boolean
|
||||
taskId: string
|
||||
categoryId: string
|
||||
taskTitle: string
|
||||
extraTimeDuration: number
|
||||
}
|
||||
@@ -84,6 +84,9 @@ const definitions = {
|
||||
},
|
||||
"usedTime": {
|
||||
"type": "string"
|
||||
},
|
||||
"tasks": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
@@ -357,6 +360,25 @@ const definitions = {
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"SerializedDeleteChildTaskAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"DELETE_CHILD_TASK"
|
||||
]
|
||||
},
|
||||
"taskId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"taskId",
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"SerializedDeleteTimeLimitRuleAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -566,6 +588,33 @@ const definitions = {
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"SerializedReviewChildTaskAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"REVIEW_CHILD_TASK"
|
||||
]
|
||||
},
|
||||
"taskId": {
|
||||
"type": "string"
|
||||
},
|
||||
"ok": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"time": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"ok",
|
||||
"taskId",
|
||||
"time",
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"SerializedSetCategoryExtraTimeAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1060,6 +1109,41 @@ const definitions = {
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"SerializedUpdateChildTaskAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"UPDATE_CHILD_TASK"
|
||||
]
|
||||
},
|
||||
"isNew": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"taskId": {
|
||||
"type": "string"
|
||||
},
|
||||
"categoryId": {
|
||||
"type": "string"
|
||||
},
|
||||
"taskTitle": {
|
||||
"type": "string"
|
||||
},
|
||||
"extraTimeDuration": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"categoryId",
|
||||
"extraTimeDuration",
|
||||
"isNew",
|
||||
"taskId",
|
||||
"taskTitle",
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"SerializedUpdateDeviceNameAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1484,6 +1568,25 @@ const definitions = {
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"SerializedMarkTaskPendingAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"MARK_TASK_PENDING"
|
||||
]
|
||||
},
|
||||
"taskId": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"taskId",
|
||||
"type"
|
||||
]
|
||||
},
|
||||
"SerializedRemoveInstalledAppsAction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -2178,6 +2281,57 @@ const definitions = {
|
||||
"start"
|
||||
]
|
||||
},
|
||||
"ServerUpdatedCategoryTasks": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"categoryId": {
|
||||
"type": "string"
|
||||
},
|
||||
"version": {
|
||||
"type": "string"
|
||||
},
|
||||
"tasks": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/ServerUpdatedCategoryTask"
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"categoryId",
|
||||
"tasks",
|
||||
"version"
|
||||
]
|
||||
},
|
||||
"ServerUpdatedCategoryTask": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"i": {
|
||||
"type": "string"
|
||||
},
|
||||
"t": {
|
||||
"type": "string"
|
||||
},
|
||||
"d": {
|
||||
"type": "number"
|
||||
},
|
||||
"p": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"l": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"d",
|
||||
"i",
|
||||
"l",
|
||||
"p",
|
||||
"t"
|
||||
]
|
||||
},
|
||||
"ServerUserList": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -2460,6 +2614,9 @@ export const isSerializedParentAction: (value: object) => value is SerializedPar
|
||||
{
|
||||
"$ref": "#/definitions/SerializedDeleteCategoryAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedDeleteChildTaskAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedDeleteTimeLimitRuleAction"
|
||||
},
|
||||
@@ -2484,6 +2641,9 @@ export const isSerializedParentAction: (value: object) => value is SerializedPar
|
||||
{
|
||||
"$ref": "#/definitions/SerializedResetParentBlockedTimesAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedReviewChildTaskAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedSetCategoryExtraTimeAction"
|
||||
},
|
||||
@@ -2547,6 +2707,9 @@ export const isSerializedParentAction: (value: object) => value is SerializedPar
|
||||
{
|
||||
"$ref": "#/definitions/SerializedUpdateCategoryTitleAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedUpdateChildTaskAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedUpdateDeviceNameAction"
|
||||
},
|
||||
@@ -2589,6 +2752,9 @@ export const isSerializedAppLogicAction: (value: object) => value is SerializedA
|
||||
{
|
||||
"$ref": "#/definitions/SerializedForceSyncAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedMarkTaskPendingAction"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/SerializedRemoveInstalledAppsAction"
|
||||
},
|
||||
|
||||
@@ -69,10 +69,14 @@ export interface CategoryAttributesVersion9 {
|
||||
disableLimitsUntil: string
|
||||
}
|
||||
|
||||
export interface CategoryAttributesVersion10 {
|
||||
taskListVersion: string
|
||||
}
|
||||
|
||||
export type CategoryAttributes = CategoryAttributesVersion1 & CategoryAttributesVersion2 &
|
||||
CategoryAttributesVersion3 & CategoryAttributesVersion4 & CategoryAttributesVersion5 &
|
||||
CategoryAttributesVersion6 & CategoryAttributesVersion7 & CategoryAttributesVersion8 &
|
||||
CategoryAttributesVersion9
|
||||
CategoryAttributesVersion9 & CategoryAttributesVersion10
|
||||
|
||||
export type CategoryModel = Sequelize.Model & CategoryAttributes
|
||||
export type CategoryModelStatic = typeof Sequelize.Model & {
|
||||
@@ -199,6 +203,13 @@ export const attributesVersion9: SequelizeAttributes<CategoryAttributesVersion9>
|
||||
}
|
||||
}
|
||||
|
||||
export const attributesVersion10: SequelizeAttributes<CategoryAttributesVersion10> = {
|
||||
taskListVersion: {
|
||||
...versionColumn,
|
||||
defaultValue: 'abcd'
|
||||
}
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<CategoryAttributes> = {
|
||||
...attributesVersion1,
|
||||
...attributesVersion2,
|
||||
@@ -208,7 +219,8 @@ export const attributes: SequelizeAttributes<CategoryAttributes> = {
|
||||
...attributesVersion6,
|
||||
...attributesVersion7,
|
||||
...attributesVersion8,
|
||||
...attributesVersion9
|
||||
...attributesVersion9,
|
||||
...attributesVersion10
|
||||
}
|
||||
|
||||
export const createCategoryModel = (sequelize: Sequelize.Sequelize): CategoryModelStatic => sequelize.define('Category', attributes) as CategoryModelStatic
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 * as Sequelize from 'sequelize'
|
||||
import { familyIdColumn, idWithinFamilyColumn, timestampColumn } from './columns'
|
||||
import { SequelizeAttributes } from './types'
|
||||
|
||||
export interface ChildTaskAttributes {
|
||||
familyId: string
|
||||
taskId: string
|
||||
// end of primary key
|
||||
categoryId: string
|
||||
taskTitle: string
|
||||
extraTimeDuration: number
|
||||
pendingRequest: number
|
||||
lastGrantTimestamp: string
|
||||
}
|
||||
|
||||
export const maxExtraTime = 1000 * 60 * 60 * 24
|
||||
export const maxTitleLength = 50
|
||||
|
||||
export type ChildTaskModel = Sequelize.Model & ChildTaskAttributes
|
||||
export type ChildTaskModelStatic = typeof Sequelize.Model & {
|
||||
new (values?: object, options?: Sequelize.BuildOptions): ChildTaskModel;
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<ChildTaskAttributes> = {
|
||||
familyId: {
|
||||
...familyIdColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
taskId: {
|
||||
...idWithinFamilyColumn,
|
||||
primaryKey: true
|
||||
},
|
||||
categoryId: { ...idWithinFamilyColumn },
|
||||
taskTitle: {
|
||||
type: Sequelize.STRING(maxTitleLength),
|
||||
allowNull: false
|
||||
},
|
||||
extraTimeDuration: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
validate: { min: 1, max: maxExtraTime }
|
||||
},
|
||||
pendingRequest: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false
|
||||
},
|
||||
lastGrantTimestamp: { ...timestampColumn }
|
||||
}
|
||||
|
||||
export const createChildTaskModel = (sequelize: Sequelize.Sequelize): ChildTaskModelStatic => sequelize.define('ChildTask', attributes) as ChildTaskModelStatic
|
||||
@@ -25,6 +25,7 @@ import { AuthTokenModelStatic, createAuthtokenModel } from './authtoken'
|
||||
import { CategoryModelStatic, createCategoryModel } from './category'
|
||||
import { CategoryAppModelStatic, createCategoryAppModel } from './categoryapp'
|
||||
import { CategoryNetworkIdModelStatic, createCategoryNetworkIdModel } from './categorynetworkid'
|
||||
import { ChildTaskModelStatic, createChildTaskModel } from './childtask'
|
||||
import { configItemIds, ConfigModelStatic, createConfigModel } from './config'
|
||||
import { createDeviceModel, DeviceModelStatic } from './device'
|
||||
import { createFamilyModel, FamilyModelStatic } from './family'
|
||||
@@ -48,6 +49,7 @@ export interface Database {
|
||||
category: CategoryModelStatic
|
||||
categoryApp: CategoryAppModelStatic
|
||||
categoryNetworkId: CategoryNetworkIdModelStatic
|
||||
childTask: ChildTaskModelStatic
|
||||
config: ConfigModelStatic
|
||||
device: DeviceModelStatic
|
||||
family: FamilyModelStatic
|
||||
@@ -70,6 +72,7 @@ const createDatabase = (sequelize: Sequelize.Sequelize): Database => ({
|
||||
appActivity: createAppActivityModel(sequelize),
|
||||
category: createCategoryModel(sequelize),
|
||||
categoryApp: createCategoryAppModel(sequelize),
|
||||
childTask: createChildTaskModel(sequelize),
|
||||
categoryNetworkId: createCategoryNetworkIdModel(sequelize),
|
||||
config: createConfigModel(sequelize),
|
||||
device: createDeviceModel(sequelize),
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 { QueryInterface, Sequelize, Transaction } from 'sequelize'
|
||||
import { attributesVersion10 as categoryAttributes } from '../../category'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await sequelize.query(
|
||||
'CREATE TABLE `ChildTasks` (' +
|
||||
'`familyId` VARCHAR(10) NOT NULL, `taskId` VARCHAR(6) NOT NULL,' +
|
||||
'`categoryId` VARCHAR(6) NOT NULL, `taskTitle` VARCHAR(50) NOT NULL,' +
|
||||
'`extraTimeDuration` INTEGER NOT NULL, `pendingRequest` INTEGER NOT NULL,' +
|
||||
'`lastGrantTimestamp` LONG NOT NULL,' +
|
||||
'PRIMARY KEY(`familyId`, `taskId`),' +
|
||||
'FOREIGN KEY(`familyId`, `categoryId`) REFERENCES `Categories`(`familyId`, `categoryId`) ' +
|
||||
'ON UPDATE CASCADE ON DELETE CASCADE' +
|
||||
')',
|
||||
{ transaction }
|
||||
)
|
||||
|
||||
await queryInterface.addColumn('Categories', 'taskListVersion', {
|
||||
...categoryAttributes.taskListVersion
|
||||
}, {
|
||||
transaction
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.dropTable('ChildTasks', { transaction })
|
||||
await queryInterface.removeColumn('Categories', 'taskListVersion', { transaction })
|
||||
})
|
||||
}
|
||||
@@ -37,6 +37,7 @@ export class Cache {
|
||||
categoriesWithModifiedBaseData = new Set<string>()
|
||||
categoriesWithModifiedTimeLimitRules = new Set<string>()
|
||||
categoriesWithModifiedUsedTimes = new Set<string>()
|
||||
categoriesWithModifiedTasks = new Set<string>()
|
||||
|
||||
devicesWithModifiedInstalledApps = new Set<string>()
|
||||
devicesWithModifiedShowDeviceConnected = new Map<string, boolean>()
|
||||
@@ -209,6 +210,22 @@ export class Cache {
|
||||
this.categoriesWithModifiedUsedTimes.clear()
|
||||
}
|
||||
|
||||
if (this.categoriesWithModifiedTasks.size > 0) {
|
||||
await database.category.update({
|
||||
taskListVersion: generateVersionId()
|
||||
}, {
|
||||
where: {
|
||||
familyId,
|
||||
categoryId: {
|
||||
[Sequelize.Op.in]: setToList(this.categoriesWithModifiedTasks)
|
||||
}
|
||||
},
|
||||
transaction
|
||||
})
|
||||
|
||||
this.categoriesWithModifiedUsedTimes.clear()
|
||||
}
|
||||
|
||||
if (this.devicesWithModifiedInstalledApps.size > 0) {
|
||||
await database.device.update({
|
||||
installedAppsVersion: generateVersionId()
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
AddUsedTimeActionVersion2,
|
||||
AppLogicAction,
|
||||
ForceSyncAction,
|
||||
MarkTaskPendingAction,
|
||||
RemoveInstalledAppsAction,
|
||||
SignOutAtDeviceAction,
|
||||
TriedDisablingDeviceAdminAction,
|
||||
@@ -34,6 +35,7 @@ import { dispatchAddInstalledApps } from './addinstalledapps'
|
||||
import { dispatchAddUsedTime } from './addusedtime'
|
||||
import { dispatchAddUsedTimeVersion2 } from './addusedtime2'
|
||||
import { dispatchForceSyncAction } from './forcesync'
|
||||
import { dispatchMarkTaskPendingAction } from './marktaskpendingaction'
|
||||
import { dispatchRemoveInstalledApps } from './removeinstalledapps'
|
||||
import { dispatchSignOutAtDevice } from './signoutatdevice'
|
||||
import { dispatchTriedDisablingDeviceAdmin } from './trieddisablingdeviceadmin'
|
||||
@@ -54,6 +56,8 @@ export const dispatchAppLogicAction = async ({ action, deviceId, cache, eventHan
|
||||
await dispatchAddUsedTimeVersion2({ deviceId, action, cache, eventHandler })
|
||||
} else if (action instanceof ForceSyncAction) {
|
||||
await dispatchForceSyncAction({ deviceId, action, cache })
|
||||
} else if (action instanceof MarkTaskPendingAction) {
|
||||
await dispatchMarkTaskPendingAction({ deviceId, action, cache })
|
||||
} else if (action instanceof RemoveInstalledAppsAction) {
|
||||
await dispatchRemoveInstalledApps({ deviceId, action, cache })
|
||||
} else if (action instanceof SignOutAtDeviceAction) {
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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 { MarkTaskPendingAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
import { IllegalStateException, SourceDeviceNotFoundException } from '../exception/illegal-state'
|
||||
import { MissingTaskException } from '../exception/missing-item'
|
||||
|
||||
export async function dispatchMarkTaskPendingAction ({ action, cache, deviceId }: {
|
||||
deviceId: string
|
||||
action: MarkTaskPendingAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const taskInfoUnsafe = await cache.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
attributes: ['categoryId', 'pendingRequest']
|
||||
})
|
||||
|
||||
if (taskInfoUnsafe === null) throw new MissingTaskException()
|
||||
|
||||
const taskInfo = {
|
||||
categoryId: taskInfoUnsafe.categoryId,
|
||||
pendingRequest: taskInfoUnsafe.pendingRequest
|
||||
}
|
||||
|
||||
if (taskInfo.pendingRequest !== 0) return // review already requested
|
||||
|
||||
const categoryInfoUnsafe = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
attributes: ['childId'],
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (categoryInfoUnsafe === null) {
|
||||
throw new IllegalStateException({ staticMessage: 'category referenced from task not found' })
|
||||
}
|
||||
|
||||
const categoryInfo = { childId: categoryInfoUnsafe.childId }
|
||||
|
||||
const deviceInfoUnsafe = await cache.database.device.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
attributes: ['currentUserId'],
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (deviceInfoUnsafe === null) throw new SourceDeviceNotFoundException()
|
||||
|
||||
const deviceInfo = { currentUserId: deviceInfoUnsafe.currentUserId }
|
||||
|
||||
if (categoryInfo.childId !== deviceInfo.currentUserId) {
|
||||
throw new IllegalStateException({ staticMessage: 'Can not mark task pending for other user than the current user' })
|
||||
}
|
||||
|
||||
await cache.database.childTask.update({ pendingRequest: true }, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
|
||||
}
|
||||
@@ -76,7 +76,8 @@ export async function dispatchCreateCategory ({ action, cache, fromChildSelfLimi
|
||||
blockAllNotifications: false,
|
||||
timeWarningFlags: 0,
|
||||
sort,
|
||||
disableLimitsUntil: 0
|
||||
disableLimitsUntil: 0,
|
||||
taskListVersion: generateVersionId()
|
||||
}, { transaction: cache.transaction })
|
||||
|
||||
// update the cache
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 { DeleteChildTaskAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
import { MissingTaskException } from '../exception/missing-item'
|
||||
|
||||
export async function dispatchDeleteChildTaskAction ({ action, cache }: {
|
||||
action: DeleteChildTaskAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const taskInfoUnsafe = await cache.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction,
|
||||
attributes: ['categoryId']
|
||||
})
|
||||
|
||||
if (taskInfoUnsafe === null) throw new MissingTaskException()
|
||||
|
||||
const taskInfo = { categoryId: taskInfoUnsafe.categoryId }
|
||||
|
||||
await cache.database.childTask.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
CreateCategoryAction,
|
||||
CreateTimeLimitRuleAction,
|
||||
DeleteCategoryAction,
|
||||
DeleteChildTaskAction,
|
||||
DeleteTimeLimitRuleAction,
|
||||
IgnoreManipulationAction,
|
||||
IncrementCategoryExtraTimeAction,
|
||||
@@ -32,6 +33,7 @@ import {
|
||||
RenameChildAction,
|
||||
ResetCategoryNetworkIdsAction,
|
||||
ResetParentBlockedTimesAction,
|
||||
ReviewChildTaskAction,
|
||||
SetCategoryExtraTimeAction,
|
||||
SetCategoryForUnassignedAppsAction,
|
||||
SetChildPasswordAction,
|
||||
@@ -53,6 +55,7 @@ import {
|
||||
UpdateCategoryTemporarilyBlockedAction,
|
||||
UpdateCategoryTimeWarningsAction,
|
||||
UpdateCategoryTitleAction,
|
||||
UpdateChildTaskAction,
|
||||
UpdateDeviceNameAction,
|
||||
UpdateEnableActivityLevelBlockingAction,
|
||||
UpdateNetworkTimeVerificationAction,
|
||||
@@ -72,6 +75,7 @@ import { dispatchChangeParentPassword } from './changeparentpassword'
|
||||
import { dispatchCreateCategory } from './createcategory'
|
||||
import { dispatchCreateTimeLimitRule } from './createtimelimitrule'
|
||||
import { dispatchDeleteCategory } from './deletecategory'
|
||||
import { dispatchDeleteChildTaskAction } from './deletechildtaskaction'
|
||||
import { dispatchDeleteTimeLimitRule } from './deletetimelimitrule'
|
||||
import { dispatchIgnoreManipulation } from './ignoremanipulation'
|
||||
import { dispatchIncrementCategoryExtraTime } from './incrementcategoryextratime'
|
||||
@@ -80,6 +84,7 @@ 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'
|
||||
import { dispatchSetChildPassword } from './setchildpassword'
|
||||
@@ -101,6 +106,7 @@ import { dispatchUpdateCategorySorting } from './updatecategorysorting'
|
||||
import { dispatchUpdateCategoryTemporarilyBlocked } from './updatecategorytemporarilyblocked'
|
||||
import { dispatchUpdateCategoryTimeWarnings } from './updatecategorytimewarnings'
|
||||
import { dispatchUpdateCategoryTitle } from './updatecategorytitle'
|
||||
import { dispatchUpdateChildTaskAction } from './updatechildtaskaction'
|
||||
import { dispatchUpdateDeviceName } from './updatedevicename'
|
||||
import { dispatchUpdateEnableActivityLevelBlocking } from './updateenableactivitylevelblocking'
|
||||
import { dispatchUpdateNetworkTimeVerification } from './updatenetworktimeverification'
|
||||
@@ -210,6 +216,12 @@ export const dispatchParentAction = async ({ action, cache, parentUserId, source
|
||||
return dispatchUpdateUserFlagsAction({ action, cache })
|
||||
} else if (action instanceof UpdateUserLimitLoginCategory) {
|
||||
return dispatchUpdateUserLimitLoginCategoryAction({ action, cache, parentUserId })
|
||||
} else if (action instanceof DeleteChildTaskAction) {
|
||||
await dispatchDeleteChildTaskAction({ action, cache })
|
||||
} else if (action instanceof ReviewChildTaskAction) {
|
||||
await dispatchReviewChildTaskAction({ action, cache })
|
||||
} else if (action instanceof UpdateChildTaskAction) {
|
||||
await dispatchUpdateChildTaskAction({ action, cache })
|
||||
} else {
|
||||
throw new ActionObjectTypeNotHandledException()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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 { ReviewChildTaskAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
import { IllegalStateException } from '../exception/illegal-state'
|
||||
import { MissingTaskException } from '../exception/missing-item'
|
||||
|
||||
export async function dispatchReviewChildTaskAction ({ action, cache }: {
|
||||
action: ReviewChildTaskAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const taskInfo = await cache.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (taskInfo === null) throw new MissingTaskException()
|
||||
|
||||
if (taskInfo.pendingRequest === 0) throw new IllegalStateException({ staticMessage: 'no task review pending' })
|
||||
|
||||
if (action.ok) {
|
||||
const categoryInfoUnsafe = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
attributes: ['extraTimeInMillis', 'extraTimeDay'],
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (categoryInfoUnsafe === null) {
|
||||
throw new IllegalStateException({ staticMessage: 'category referenced from task not found' })
|
||||
}
|
||||
|
||||
const categoryInfo = {
|
||||
extraTimeInMillis: categoryInfoUnsafe.extraTimeInMillis,
|
||||
extraTimeDay: categoryInfoUnsafe.extraTimeDay
|
||||
}
|
||||
|
||||
if (categoryInfo.extraTimeDay !== 0 && categoryInfo.extraTimeInMillis > 0) {
|
||||
// if the current time is daily, then extend the daily time only
|
||||
await cache.database.category.update({
|
||||
extraTimeInMillis: categoryInfo.extraTimeInMillis + taskInfo.extraTimeDuration
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
} else {
|
||||
await cache.database.category.update({
|
||||
extraTimeInMillis: categoryInfo.extraTimeInMillis + taskInfo.extraTimeDuration,
|
||||
extraTimeDay: -1
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: taskInfo.categoryId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
}
|
||||
|
||||
cache.categoriesWithModifiedBaseData.add(taskInfo.categoryId)
|
||||
|
||||
await cache.database.childTask.update({
|
||||
pendingRequest: 0,
|
||||
lastGrantTimestamp: action.time.toString(10)
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
} else {
|
||||
await cache.database.childTask.update({
|
||||
pendingRequest: 0
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
}
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 { UpdateChildTaskAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
import { IllegalStateException } from '../exception/illegal-state'
|
||||
import { MissingCategoryException, MissingTaskException } from '../exception/missing-item'
|
||||
|
||||
export async function dispatchUpdateChildTaskAction ({ action, cache }: {
|
||||
action: UpdateChildTaskAction
|
||||
cache: Cache
|
||||
}) {
|
||||
const categoryInfoUnsafe = await cache.database.category.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
categoryId: action.categoryId
|
||||
},
|
||||
attributes: ['childId'],
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
if (categoryInfoUnsafe === null) throw new MissingCategoryException()
|
||||
|
||||
const taskInfo = await cache.database.childTask.findOne({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
const notFound = taskInfo === null
|
||||
|
||||
if (notFound !== action.isNew) {
|
||||
if (action.isNew) {
|
||||
throw new IllegalStateException({
|
||||
staticMessage: 'can not create task which exists already'
|
||||
})
|
||||
} else {
|
||||
throw new MissingTaskException()
|
||||
}
|
||||
}
|
||||
|
||||
if (taskInfo === null) {
|
||||
await cache.database.childTask.create({
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId,
|
||||
categoryId: action.categoryId,
|
||||
taskTitle: action.taskTitle,
|
||||
extraTimeDuration: action.extraTimeDuration,
|
||||
pendingRequest: 0,
|
||||
lastGrantTimestamp: '0'
|
||||
}, {
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(action.categoryId)
|
||||
} else {
|
||||
await cache.database.childTask.update({
|
||||
taskTitle: action.taskTitle,
|
||||
categoryId: action.categoryId,
|
||||
extraTimeDuration: action.extraTimeDuration
|
||||
}, {
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
taskId: action.taskId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.categoriesWithModifiedTasks.add(taskInfo.categoryId)
|
||||
cache.categoriesWithModifiedTasks.add(action.categoryId)
|
||||
}
|
||||
}
|
||||
@@ -42,3 +42,9 @@ export class MissingDeviceException extends MissingItemException {
|
||||
super({ staticMessage: 'referenced device which does not exist' })
|
||||
}
|
||||
}
|
||||
|
||||
export class MissingTaskException extends MissingItemException {
|
||||
constructor () {
|
||||
super({ staticMessage: 'referenced task which does not exist' })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ export async function getCategoryDataToSync ({ database, transaction, familyEntr
|
||||
'baseVersion',
|
||||
'assignedAppsVersion',
|
||||
'timeLimitRulesVersion',
|
||||
'usedTimesVersion'
|
||||
'usedTimesVersion',
|
||||
'taskListVersion'
|
||||
],
|
||||
transaction
|
||||
})).map((item) => ({
|
||||
@@ -45,7 +46,8 @@ export async function getCategoryDataToSync ({ database, transaction, familyEntr
|
||||
baseVersion: item.baseVersion,
|
||||
assignedAppsVersion: item.assignedAppsVersion,
|
||||
timeLimitRulesVersion: item.timeLimitRulesVersion,
|
||||
usedTimesVersion: item.usedTimesVersion
|
||||
usedTimesVersion: item.usedTimesVersion,
|
||||
taskListVersion: item.taskListVersion
|
||||
}))
|
||||
|
||||
const serverCategoryIds = serverCategoriesVersions.map((item) => item.categoryId)
|
||||
@@ -60,6 +62,7 @@ export async function getCategoryDataToSync ({ database, transaction, familyEntr
|
||||
const categoryIdsToSyncAssignedApps = [...addedCategoryIds]
|
||||
const categoryIdsToSyncRules = [...addedCategoryIds]
|
||||
const categoryIdsToSyncUsedTimes = [...addedCategoryIds]
|
||||
const categoryIdsToSyncTasks = [...addedCategoryIds]
|
||||
|
||||
categoryIdsOfClientAndServer.forEach((categoryId) => {
|
||||
const serverEntry = serverCategoriesVersions.find((item) => item.categoryId === categoryId)
|
||||
@@ -84,6 +87,10 @@ export async function getCategoryDataToSync ({ database, transaction, familyEntr
|
||||
if (serverEntry.usedTimesVersion !== clientEntry.usedTime) {
|
||||
categoryIdsToSyncUsedTimes.push(categoryId)
|
||||
}
|
||||
|
||||
if (serverEntry.taskListVersion !== clientEntry.tasks) {
|
||||
categoryIdsToSyncTasks.push(categoryId)
|
||||
}
|
||||
})
|
||||
|
||||
const serverCategoriesVersionsMap = new Map<string, ServerCategoryVersion>()
|
||||
@@ -96,6 +103,7 @@ export async function getCategoryDataToSync ({ database, transaction, familyEntr
|
||||
categoryIdsToSyncAssignedApps,
|
||||
categoryIdsToSyncRules,
|
||||
categoryIdsToSyncUsedTimes,
|
||||
categoryIdsToSyncTasks,
|
||||
serverCategoriesVersions: {
|
||||
list: serverCategoriesVersions,
|
||||
requireByCategoryId: (categoryId) => {
|
||||
@@ -117,6 +125,7 @@ export interface GetCategoryDataToSyncResult {
|
||||
categoryIdsToSyncAssignedApps: Array<string>
|
||||
categoryIdsToSyncRules: Array<string>
|
||||
categoryIdsToSyncUsedTimes: Array<string>
|
||||
categoryIdsToSyncTasks: Array<string>
|
||||
serverCategoriesVersions: ServerCategoryVersions
|
||||
}
|
||||
|
||||
@@ -131,4 +140,5 @@ export interface ServerCategoryVersion {
|
||||
assignedAppsVersion: string
|
||||
timeLimitRulesVersion: string
|
||||
usedTimesVersion: string
|
||||
taskListVersion: string
|
||||
}
|
||||
|
||||
@@ -18,5 +18,6 @@
|
||||
export { getCategoryDataToSync } from './diff'
|
||||
export { getCategoryBaseDatas } from './base-data'
|
||||
export { getRules } from './rules'
|
||||
export { getTasks } from './tasks'
|
||||
export { getUsedTimes } from './used-times'
|
||||
export { getCategoryAssignedApps } from './assigned-apps'
|
||||
|
||||
@@ -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 * as Sequelize from 'sequelize'
|
||||
import { Database, Transaction } from '../../../../database'
|
||||
import { ServerUpdatedCategoryTask, ServerUpdatedCategoryTasks } from '../../../../object/serverdatastatus'
|
||||
import { FamilyEntry } from '../family-entry'
|
||||
import { ServerCategoryVersions } from './diff'
|
||||
|
||||
export async function getTasks ({
|
||||
database, transaction, categoryIdsToSyncTasks, familyEntry,
|
||||
serverCategoriesVersions
|
||||
}: {
|
||||
database: Database
|
||||
transaction: Transaction
|
||||
categoryIdsToSyncTasks: Array<string>
|
||||
familyEntry: FamilyEntry
|
||||
serverCategoriesVersions: ServerCategoryVersions
|
||||
}): Promise<Array<ServerUpdatedCategoryTasks>> {
|
||||
const dataToSync = (await database.childTask.findAll({
|
||||
where: {
|
||||
familyId: familyEntry.familyId,
|
||||
categoryId: {
|
||||
[Sequelize.Op.in]: categoryIdsToSyncTasks
|
||||
}
|
||||
},
|
||||
attributes: [
|
||||
'taskId',
|
||||
'categoryId',
|
||||
'taskTitle',
|
||||
'extraTimeDuration',
|
||||
'pendingRequest',
|
||||
'lastGrantTimestamp'
|
||||
],
|
||||
transaction
|
||||
})).map((item) => ({
|
||||
taskId: item.taskId,
|
||||
categoryId: item.categoryId,
|
||||
taskTitle: item.taskTitle,
|
||||
extraTimeDuration: item.extraTimeDuration,
|
||||
pendingRequest: item.pendingRequest,
|
||||
lastGrantTimestamp: item.lastGrantTimestamp
|
||||
}))
|
||||
|
||||
return categoryIdsToSyncTasks.map((categoryId) => ({
|
||||
categoryId,
|
||||
version: serverCategoriesVersions.requireByCategoryId(categoryId).taskListVersion,
|
||||
tasks: dataToSync.filter((item) => item.categoryId === categoryId).map((item): ServerUpdatedCategoryTask => ({
|
||||
i: item.taskId,
|
||||
t: item.taskTitle,
|
||||
d: item.extraTimeDuration,
|
||||
p: item.pendingRequest !== 0,
|
||||
l: parseInt(item.lastGrantTimestamp, 10)
|
||||
}))
|
||||
}))
|
||||
}
|
||||
@@ -23,7 +23,8 @@ import { ClientDataStatus } from '../../../object/clientdatastatus'
|
||||
import { ServerDataStatus } from '../../../object/serverdatastatus'
|
||||
import { getAppList } from './app-list'
|
||||
import {
|
||||
getCategoryAssignedApps, getCategoryBaseDatas, getCategoryDataToSync, getRules, getUsedTimes
|
||||
getCategoryAssignedApps, getCategoryBaseDatas, getCategoryDataToSync,
|
||||
getRules, getTasks, getUsedTimes
|
||||
} from './category'
|
||||
import { getDeviceList } from './device-list'
|
||||
import { getFamilyEntry } from './family-entry'
|
||||
@@ -36,6 +37,7 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI
|
||||
transaction: Sequelize.Transaction
|
||||
}): Promise<ServerDataStatus> => {
|
||||
const familyEntry = await getFamilyEntry({ database, familyId, transaction })
|
||||
const doesClientSupportTasks = clientStatus.clientLevel !== undefined && clientStatus.clientLevel >= 3
|
||||
|
||||
let result: ServerDataStatus = {
|
||||
fullVersion: config.alwaysPro ? 1 : (
|
||||
@@ -92,5 +94,13 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI
|
||||
})
|
||||
}
|
||||
|
||||
if (categoryDataToSync.categoryIdsToSyncTasks.length > 0 && doesClientSupportTasks) {
|
||||
result.tasks = await getTasks({
|
||||
database, transaction, familyEntry,
|
||||
serverCategoriesVersions: categoryDataToSync.serverCategoriesVersions,
|
||||
categoryIdsToSyncTasks: categoryDataToSync.categoryIdsToSyncTasks
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -31,4 +31,5 @@ export interface CategoryDataStatus {
|
||||
apps: string // assignedAppsVersion
|
||||
rules: string // timeLimitRulesVersion
|
||||
usedTime: string // usedTimeItemsVersion
|
||||
tasks?: string // taskListVersion
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ export interface ServerDataStatus {
|
||||
categoryApp?: Array<ServerUpdatedCategoryAssignedApps> // newCategoryAssignedApps
|
||||
usedTimes?: Array<ServerUpdatedCategoryUsedTimes> // newCategoryUsedTimes
|
||||
rules?: Array<ServerUpdatedTimeLimitRules> // newOrUpdatedTimeLimitRules
|
||||
tasks?: Array<ServerUpdatedCategoryTasks> // newOrUpdatedTasks
|
||||
users?: ServerUserList // newUserList
|
||||
fullVersion: number // fullVersionUntil
|
||||
message?: string
|
||||
@@ -188,6 +189,20 @@ export interface ServerTimeLimitRule {
|
||||
pause: number // session pause duration
|
||||
}
|
||||
|
||||
export interface ServerUpdatedCategoryTasks {
|
||||
categoryId: string
|
||||
version: string
|
||||
tasks: Array<ServerUpdatedCategoryTask>
|
||||
}
|
||||
|
||||
export interface ServerUpdatedCategoryTask {
|
||||
i: string // taskId
|
||||
t: string // taskTitle
|
||||
d: number // extraTimeDuration
|
||||
p: boolean // pendingRequest
|
||||
l: number // lastGrantTimestamp
|
||||
}
|
||||
|
||||
export interface ServerInstalledAppsData {
|
||||
deviceId: string
|
||||
version: string
|
||||
|
||||
Reference in New Issue
Block a user