Add support for time limit rules that expire

This commit is contained in:
Jonas Lochmann
2025-11-10 01:00:00 +01:00
parent 93337e5e08
commit 1215c0c8a2
16 changed files with 244 additions and 22 deletions
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2022 Jonas Lochmann
* Copyright (C) 2019 - 2024 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
@@ -55,7 +55,8 @@ export async function dispatchCreateTimeLimitRule ({ action, cache, fromChildSel
endMinuteOfDay: action.rule.end,
sessionDurationMilliseconds: action.rule.sessionDurationMilliseconds,
sessionPauseMilliseconds: action.rule.sessionPauseMilliseconds,
perDay: action.rule.perDay ? 1 : 0
perDay: action.rule.perDay ? 1 : 0,
expiresAt: action.rule.expiresAt ? action.rule.expiresAt.toString() : null
}, { transaction: cache.transaction })
cache.categoriesWithModifiedTimeLimitRules.add(action.rule.categoryId)
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2022 Jonas Lochmann
* Copyright (C) 2019 - 2024 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
@@ -81,7 +81,8 @@ export async function dispatchUpdateTimelimitRule ({
action.sessionDurationMilliseconds <= ruleEntry.sessionDurationMilliseconds &&
action.sessionPauseMilliseconds >= ruleEntry.sessionPauseMilliseconds
)) &&
(!action.perDay || ruleEntry.perDay || countOldAffectedDays <= 1)
(!action.perDay || ruleEntry.perDay || countOldAffectedDays <= 1) &&
(action.expiresAt === undefined || (ruleEntry.expiresAt !== null && action.expiresAt >= parseInt(ruleEntry.expiresAt, 10)))
if (!isAtLeastAsStrictAsPreviously) {
throw new CanNotRelaxRestrictionsSelfLimitException()
@@ -96,6 +97,7 @@ export async function dispatchUpdateTimelimitRule ({
ruleEntry.sessionDurationMilliseconds = action.sessionDurationMilliseconds
ruleEntry.sessionPauseMilliseconds = action.sessionPauseMilliseconds
ruleEntry.perDay = action.perDay ? 1 : 0
ruleEntry.expiresAt = action.expiresAt ? action.expiresAt.toString() : null
await ruleEntry.save({ transaction: cache.transaction })
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 Jonas Lochmann
* Copyright (C) 2019 - 2024 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
@@ -45,7 +45,8 @@ export async function getRules ({ database, transaction, categoryIdsToSyncRules,
'endMinuteOfDay',
'sessionDurationMilliseconds',
'sessionPauseMilliseconds',
'perDay'
'perDay',
'expiresAt'
],
transaction
})).map((item) => ({
@@ -58,7 +59,8 @@ export async function getRules ({ database, transaction, categoryIdsToSyncRules,
endMinuteOfDay: item.endMinuteOfDay,
sessionDurationMilliseconds: item.sessionDurationMilliseconds,
sessionPauseMilliseconds: item.sessionPauseMilliseconds,
perDay: item.perDay
perDay: item.perDay,
expiresAt: item.expiresAt ? parseInt(item.expiresAt, 10) : undefined
}))
const getCategoryRulesVersion = (categoryId: string) => (
@@ -76,7 +78,8 @@ export async function getRules ({ database, transaction, categoryIdsToSyncRules,
end: item.endMinuteOfDay,
session: item.sessionDurationMilliseconds,
pause: item.sessionPauseMilliseconds,
perDay: item.perDay !== 0 ? true : false
perDay: item.perDay !== 0 ? true : false,
e: item.expiresAt
})),
version: getCategoryRulesVersion(categoryId)
}))
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2022 Jonas Lochmann
* Copyright (C) 2019 - 2024 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
@@ -58,7 +58,7 @@ export const generateServerDataStatus = async ({
familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0
),
message: await getStatusMessage({ database, transaction }) || undefined,
apiLevel: 7
apiLevel: 8
}
if (familyEntry.deviceListVersion !== clientStatus.devices) {