mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add support for time limit rules that expire
This commit is contained in:
@@ -410,6 +410,9 @@
|
|||||||
},
|
},
|
||||||
"perDay": {
|
"perDay": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"e": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
@@ -1458,6 +1461,9 @@
|
|||||||
},
|
},
|
||||||
"perDay": {
|
"perDay": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"e": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
# Untitled number in SerializedParentAction Schema
|
||||||
|
|
||||||
|
```txt
|
||||||
|
https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/e
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||||
|
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------------------ |
|
||||||
|
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedParentAction.schema.json\*](SerializedParentAction.schema.json "open original schema") |
|
||||||
|
|
||||||
|
## e Type
|
||||||
|
|
||||||
|
`number`
|
||||||
@@ -28,6 +28,7 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule
|
|||||||
| [dur](#dur) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/dur") |
|
| [dur](#dur) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/dur") |
|
||||||
| [pause](#pause) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/pause") |
|
| [pause](#pause) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/pause") |
|
||||||
| [perDay](#perday) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/perDay") |
|
| [perDay](#perday) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/perDay") |
|
||||||
|
| [e](#e) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/e") |
|
||||||
|
|
||||||
## ruleId
|
## ruleId
|
||||||
|
|
||||||
@@ -208,3 +209,21 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule
|
|||||||
### perDay Type
|
### perDay Type
|
||||||
|
|
||||||
`boolean`
|
`boolean`
|
||||||
|
|
||||||
|
## e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
`e`
|
||||||
|
|
||||||
|
* is optional
|
||||||
|
|
||||||
|
* Type: `number`
|
||||||
|
|
||||||
|
* cannot be null
|
||||||
|
|
||||||
|
* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/e")
|
||||||
|
|
||||||
|
### e Type
|
||||||
|
|
||||||
|
`number`
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
# Untitled number in SerializedParentAction Schema
|
||||||
|
|
||||||
|
```txt
|
||||||
|
https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/e
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||||
|
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------------------ |
|
||||||
|
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedParentAction.schema.json\*](SerializedParentAction.schema.json "open original schema") |
|
||||||
|
|
||||||
|
## e Type
|
||||||
|
|
||||||
|
`number`
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
# Untitled number in SerializedParentAction Schema
|
||||||
|
|
||||||
|
```txt
|
||||||
|
https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/expiresAt
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In |
|
||||||
|
| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------------------ |
|
||||||
|
| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedParentAction.schema.json\*](SerializedParentAction.schema.json "open original schema") |
|
||||||
|
|
||||||
|
## expiresAt Type
|
||||||
|
|
||||||
|
`number`
|
||||||
@@ -28,6 +28,7 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelim
|
|||||||
| [dur](#dur) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/dur") |
|
| [dur](#dur) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/dur") |
|
||||||
| [pause](#pause) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/pause") |
|
| [pause](#pause) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/pause") |
|
||||||
| [perDay](#perday) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/perDay") |
|
| [perDay](#perday) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/perDay") |
|
||||||
|
| [e](#e) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/e") |
|
||||||
|
|
||||||
## type
|
## type
|
||||||
|
|
||||||
@@ -216,3 +217,21 @@ https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelim
|
|||||||
### perDay Type
|
### perDay Type
|
||||||
|
|
||||||
`boolean`
|
`boolean`
|
||||||
|
|
||||||
|
## e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
`e`
|
||||||
|
|
||||||
|
* is optional
|
||||||
|
|
||||||
|
* Type: `number`
|
||||||
|
|
||||||
|
* cannot be null
|
||||||
|
|
||||||
|
* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/e")
|
||||||
|
|
||||||
|
### e Type
|
||||||
|
|
||||||
|
`number`
|
||||||
|
|||||||
@@ -899,6 +899,7 @@ Reference this group by using
|
|||||||
| [dur](#dur) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/dur") |
|
| [dur](#dur) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/dur") |
|
||||||
| [pause](#pause) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/pause") |
|
| [pause](#pause) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/pause") |
|
||||||
| [perDay](#perday) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/perDay") |
|
| [perDay](#perday) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/perDay") |
|
||||||
|
| [e](#e) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/e") |
|
||||||
|
|
||||||
### ruleId
|
### ruleId
|
||||||
|
|
||||||
@@ -1080,6 +1081,24 @@ Reference this group by using
|
|||||||
|
|
||||||
`boolean`
|
`boolean`
|
||||||
|
|
||||||
|
### e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
`e`
|
||||||
|
|
||||||
|
* is optional
|
||||||
|
|
||||||
|
* Type: `number`
|
||||||
|
|
||||||
|
* cannot be null
|
||||||
|
|
||||||
|
* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedtimelimitrule-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedTimeLimitRule/properties/e")
|
||||||
|
|
||||||
|
#### e Type
|
||||||
|
|
||||||
|
`number`
|
||||||
|
|
||||||
## Definitions group SerializedDeleteCategoryAction
|
## Definitions group SerializedDeleteCategoryAction
|
||||||
|
|
||||||
Reference this group by using
|
Reference this group by using
|
||||||
@@ -4397,6 +4416,7 @@ Reference this group by using
|
|||||||
| [dur](#dur-1) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/dur") |
|
| [dur](#dur-1) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-dur.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/dur") |
|
||||||
| [pause](#pause-1) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/pause") |
|
| [pause](#pause-1) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-pause.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/pause") |
|
||||||
| [perDay](#perday-1) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/perDay") |
|
| [perDay](#perday-1) | `boolean` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-perday.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/perDay") |
|
||||||
|
| [e](#e-1) | `number` | Optional | cannot be null | [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/e") |
|
||||||
|
|
||||||
### type
|
### type
|
||||||
|
|
||||||
@@ -4586,6 +4606,24 @@ Reference this group by using
|
|||||||
|
|
||||||
`boolean`
|
`boolean`
|
||||||
|
|
||||||
|
### e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
`e`
|
||||||
|
|
||||||
|
* is optional
|
||||||
|
|
||||||
|
* Type: `number`
|
||||||
|
|
||||||
|
* cannot be null
|
||||||
|
|
||||||
|
* defined in: [SerializedParentAction](serializedparentaction-definitions-serializedupdatetimelimitruleaction-properties-e.md "https://timelimit.io/SerializedParentAction#/definitions/SerializedUpdateTimelimitRuleAction/properties/e")
|
||||||
|
|
||||||
|
#### e Type
|
||||||
|
|
||||||
|
`number`
|
||||||
|
|
||||||
## Definitions group SerializedUpdateUserFlagsAction
|
## Definitions group SerializedUpdateUserFlagsAction
|
||||||
|
|
||||||
Reference this group by using
|
Reference this group by using
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -32,11 +32,12 @@ export class UpdateTimelimitRuleAction extends ParentAction {
|
|||||||
readonly sessionDurationMilliseconds: number
|
readonly sessionDurationMilliseconds: number
|
||||||
readonly sessionPauseMilliseconds: number
|
readonly sessionPauseMilliseconds: number
|
||||||
readonly perDay: boolean
|
readonly perDay: boolean
|
||||||
|
readonly expiresAt?: number
|
||||||
|
|
||||||
constructor ({
|
constructor ({
|
||||||
ruleId, maximumTimeInMillis, dayMask, applyToExtraTimeUsage,
|
ruleId, maximumTimeInMillis, dayMask, applyToExtraTimeUsage,
|
||||||
start, end, sessionDurationMilliseconds, sessionPauseMilliseconds,
|
start, end, sessionDurationMilliseconds, sessionPauseMilliseconds,
|
||||||
perDay
|
perDay, expiresAt
|
||||||
}: {
|
}: {
|
||||||
ruleId: string
|
ruleId: string
|
||||||
maximumTimeInMillis: number
|
maximumTimeInMillis: number
|
||||||
@@ -47,6 +48,7 @@ export class UpdateTimelimitRuleAction extends ParentAction {
|
|||||||
sessionDurationMilliseconds: number
|
sessionDurationMilliseconds: number
|
||||||
sessionPauseMilliseconds: number
|
sessionPauseMilliseconds: number
|
||||||
perDay: boolean
|
perDay: boolean
|
||||||
|
expiresAt?: number
|
||||||
}) {
|
}) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
@@ -59,6 +61,7 @@ export class UpdateTimelimitRuleAction extends ParentAction {
|
|||||||
this.sessionDurationMilliseconds = sessionDurationMilliseconds
|
this.sessionDurationMilliseconds = sessionDurationMilliseconds
|
||||||
this.sessionPauseMilliseconds = sessionPauseMilliseconds
|
this.sessionPauseMilliseconds = sessionPauseMilliseconds
|
||||||
this.perDay = perDay
|
this.perDay = perDay
|
||||||
|
this.expiresAt = expiresAt
|
||||||
|
|
||||||
assertIdWithinFamily({ actionType, field: 'ruleId', value: ruleId })
|
assertIdWithinFamily({ actionType, field: 'ruleId', value: ruleId })
|
||||||
|
|
||||||
@@ -92,9 +95,17 @@ export class UpdateTimelimitRuleAction extends ParentAction {
|
|||||||
staticMessage: 'session duration lesser than zero'
|
staticMessage: 'session duration lesser than zero'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (expiresAt !== undefined) {
|
||||||
|
assertSafeInteger({ actionType, field: 'expiresAt', value: expiresAt })
|
||||||
|
|
||||||
|
if (expiresAt <= 0) {
|
||||||
|
throwOutOfRange({ actionType, field: 'expiresAt', value: expiresAt })
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static parse = ({ ruleId, time, days, extraTime, start, end, dur, pause, perDay }: SerializedUpdateTimelimitRuleAction) => (
|
static parse = ({ ruleId, time, days, extraTime, start, end, dur, pause, perDay, e }: SerializedUpdateTimelimitRuleAction) => (
|
||||||
new UpdateTimelimitRuleAction({
|
new UpdateTimelimitRuleAction({
|
||||||
ruleId,
|
ruleId,
|
||||||
maximumTimeInMillis: time,
|
maximumTimeInMillis: time,
|
||||||
@@ -104,7 +115,8 @@ export class UpdateTimelimitRuleAction extends ParentAction {
|
|||||||
end: end ?? MinuteOfDay.MAX,
|
end: end ?? MinuteOfDay.MAX,
|
||||||
sessionDurationMilliseconds: dur ?? 0,
|
sessionDurationMilliseconds: dur ?? 0,
|
||||||
sessionPauseMilliseconds: pause ?? 0,
|
sessionPauseMilliseconds: pause ?? 0,
|
||||||
perDay: perDay ?? false
|
perDay: perDay ?? false,
|
||||||
|
expiresAt: e
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -120,4 +132,5 @@ export interface SerializedUpdateTimelimitRuleAction {
|
|||||||
dur?: number
|
dur?: number
|
||||||
pause?: number
|
pause?: number
|
||||||
perDay?: boolean
|
perDay?: boolean
|
||||||
|
e?: number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -409,6 +409,9 @@ const definitions = {
|
|||||||
},
|
},
|
||||||
"perDay": {
|
"perDay": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"e": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
@@ -1417,6 +1420,9 @@ const definitions = {
|
|||||||
},
|
},
|
||||||
"perDay": {
|
"perDay": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"e": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* server component for the TimeLimit App
|
||||||
|
* 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
|
||||||
|
* 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 { attributesVersion4 as ruleAttributes } from '../../timelimitrule'
|
||||||
|
|
||||||
|
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||||
|
await sequelize.transaction({
|
||||||
|
type: Transaction.TYPES.EXCLUSIVE
|
||||||
|
}, async (transaction) => {
|
||||||
|
await queryInterface.addColumn('TimelimitRules', 'expiresAt', {
|
||||||
|
...ruleAttributes.expiresAt
|
||||||
|
}, {
|
||||||
|
transaction
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||||
|
await sequelize.transaction({
|
||||||
|
type: Transaction.TYPES.EXCLUSIVE
|
||||||
|
}, async (transaction) => {
|
||||||
|
await queryInterface.removeColumn('TimelimitRules', 'expiresAt', { transaction })
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2021 Jonas Lochmann
|
* Copyright (C) 2019 - 2024 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -41,8 +41,13 @@ interface TimelimitRuleAttributesVersion3 {
|
|||||||
perDay: number
|
perDay: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TimelimitRuleAttributesVersion4 {
|
||||||
|
expiresAt: string | null
|
||||||
|
}
|
||||||
|
|
||||||
type TimelimitRuleAttributes = TimelimitRuleAttributesVersion1 &
|
type TimelimitRuleAttributes = TimelimitRuleAttributesVersion1 &
|
||||||
TimelimitRuleAttributesVersion2 & TimelimitRuleAttributesVersion3
|
TimelimitRuleAttributesVersion2 & TimelimitRuleAttributesVersion3 &
|
||||||
|
TimelimitRuleAttributesVersion4
|
||||||
|
|
||||||
export type TimelimitRuleModel = Sequelize.Model<TimelimitRuleAttributes> & TimelimitRuleAttributes
|
export type TimelimitRuleModel = Sequelize.Model<TimelimitRuleAttributes> & TimelimitRuleAttributes
|
||||||
export type TimelimitRuleModelStatic = typeof Sequelize.Model & {
|
export type TimelimitRuleModelStatic = typeof Sequelize.Model & {
|
||||||
@@ -137,10 +142,22 @@ export const attributesVersion3: SequelizeAttributes<TimelimitRuleAttributesVers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const attributesVersion4: SequelizeAttributes<TimelimitRuleAttributesVersion4> = {
|
||||||
|
expiresAt: {
|
||||||
|
type: Sequelize.BIGINT,
|
||||||
|
validate: {
|
||||||
|
min: 1
|
||||||
|
},
|
||||||
|
allowNull: true,
|
||||||
|
defaultValue: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const attributes: SequelizeAttributes<TimelimitRuleAttributes> = {
|
export const attributes: SequelizeAttributes<TimelimitRuleAttributes> = {
|
||||||
...attributesVersion1,
|
...attributesVersion1,
|
||||||
...attributesVersion2,
|
...attributesVersion2,
|
||||||
...attributesVersion3
|
...attributesVersion3,
|
||||||
|
...attributesVersion4
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createTimelimitRuleModel = (sequelize: Sequelize.Sequelize): TimelimitRuleModelStatic => sequelize.define('TimelimitRule', attributes) as TimelimitRuleModelStatic
|
export const createTimelimitRuleModel = (sequelize: Sequelize.Sequelize): TimelimitRuleModelStatic => sequelize.define('TimelimitRule', attributes) as TimelimitRuleModelStatic
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* 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,
|
endMinuteOfDay: action.rule.end,
|
||||||
sessionDurationMilliseconds: action.rule.sessionDurationMilliseconds,
|
sessionDurationMilliseconds: action.rule.sessionDurationMilliseconds,
|
||||||
sessionPauseMilliseconds: action.rule.sessionPauseMilliseconds,
|
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 })
|
}, { transaction: cache.transaction })
|
||||||
|
|
||||||
cache.categoriesWithModifiedTimeLimitRules.add(action.rule.categoryId)
|
cache.categoriesWithModifiedTimeLimitRules.add(action.rule.categoryId)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* 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.sessionDurationMilliseconds <= ruleEntry.sessionDurationMilliseconds &&
|
||||||
action.sessionPauseMilliseconds >= ruleEntry.sessionPauseMilliseconds
|
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) {
|
if (!isAtLeastAsStrictAsPreviously) {
|
||||||
throw new CanNotRelaxRestrictionsSelfLimitException()
|
throw new CanNotRelaxRestrictionsSelfLimitException()
|
||||||
@@ -96,6 +97,7 @@ export async function dispatchUpdateTimelimitRule ({
|
|||||||
ruleEntry.sessionDurationMilliseconds = action.sessionDurationMilliseconds
|
ruleEntry.sessionDurationMilliseconds = action.sessionDurationMilliseconds
|
||||||
ruleEntry.sessionPauseMilliseconds = action.sessionPauseMilliseconds
|
ruleEntry.sessionPauseMilliseconds = action.sessionPauseMilliseconds
|
||||||
ruleEntry.perDay = action.perDay ? 1 : 0
|
ruleEntry.perDay = action.perDay ? 1 : 0
|
||||||
|
ruleEntry.expiresAt = action.expiresAt ? action.expiresAt.toString() : null
|
||||||
|
|
||||||
await ruleEntry.save({ transaction: cache.transaction })
|
await ruleEntry.save({ transaction: cache.transaction })
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -45,7 +45,8 @@ export async function getRules ({ database, transaction, categoryIdsToSyncRules,
|
|||||||
'endMinuteOfDay',
|
'endMinuteOfDay',
|
||||||
'sessionDurationMilliseconds',
|
'sessionDurationMilliseconds',
|
||||||
'sessionPauseMilliseconds',
|
'sessionPauseMilliseconds',
|
||||||
'perDay'
|
'perDay',
|
||||||
|
'expiresAt'
|
||||||
],
|
],
|
||||||
transaction
|
transaction
|
||||||
})).map((item) => ({
|
})).map((item) => ({
|
||||||
@@ -58,7 +59,8 @@ export async function getRules ({ database, transaction, categoryIdsToSyncRules,
|
|||||||
endMinuteOfDay: item.endMinuteOfDay,
|
endMinuteOfDay: item.endMinuteOfDay,
|
||||||
sessionDurationMilliseconds: item.sessionDurationMilliseconds,
|
sessionDurationMilliseconds: item.sessionDurationMilliseconds,
|
||||||
sessionPauseMilliseconds: item.sessionPauseMilliseconds,
|
sessionPauseMilliseconds: item.sessionPauseMilliseconds,
|
||||||
perDay: item.perDay
|
perDay: item.perDay,
|
||||||
|
expiresAt: item.expiresAt ? parseInt(item.expiresAt, 10) : undefined
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const getCategoryRulesVersion = (categoryId: string) => (
|
const getCategoryRulesVersion = (categoryId: string) => (
|
||||||
@@ -76,7 +78,8 @@ export async function getRules ({ database, transaction, categoryIdsToSyncRules,
|
|||||||
end: item.endMinuteOfDay,
|
end: item.endMinuteOfDay,
|
||||||
session: item.sessionDurationMilliseconds,
|
session: item.sessionDurationMilliseconds,
|
||||||
pause: item.sessionPauseMilliseconds,
|
pause: item.sessionPauseMilliseconds,
|
||||||
perDay: item.perDay !== 0 ? true : false
|
perDay: item.perDay !== 0 ? true : false,
|
||||||
|
e: item.expiresAt
|
||||||
})),
|
})),
|
||||||
version: getCategoryRulesVersion(categoryId)
|
version: getCategoryRulesVersion(categoryId)
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* 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
|
familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0
|
||||||
),
|
),
|
||||||
message: await getStatusMessage({ database, transaction }) || undefined,
|
message: await getStatusMessage({ database, transaction }) || undefined,
|
||||||
apiLevel: 7
|
apiLevel: 8
|
||||||
}
|
}
|
||||||
|
|
||||||
if (familyEntry.deviceListVersion !== clientStatus.devices) {
|
if (familyEntry.deviceListVersion !== clientStatus.devices) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* 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
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -29,11 +29,12 @@ export class TimelimitRule {
|
|||||||
readonly sessionDurationMilliseconds: number
|
readonly sessionDurationMilliseconds: number
|
||||||
readonly sessionPauseMilliseconds: number
|
readonly sessionPauseMilliseconds: number
|
||||||
readonly perDay: boolean
|
readonly perDay: boolean
|
||||||
|
readonly expiresAt?: number
|
||||||
|
|
||||||
constructor ({
|
constructor ({
|
||||||
ruleId, categoryId, maxTimeInMillis, dayMask, applyToExtraTimeUsage,
|
ruleId, categoryId, maxTimeInMillis, dayMask, applyToExtraTimeUsage,
|
||||||
start, end, sessionDurationMilliseconds, sessionPauseMilliseconds,
|
start, end, sessionDurationMilliseconds, sessionPauseMilliseconds,
|
||||||
perDay
|
perDay, expiresAt
|
||||||
}: {
|
}: {
|
||||||
ruleId: string
|
ruleId: string
|
||||||
categoryId: string
|
categoryId: string
|
||||||
@@ -45,6 +46,7 @@ export class TimelimitRule {
|
|||||||
sessionDurationMilliseconds: number
|
sessionDurationMilliseconds: number
|
||||||
sessionPauseMilliseconds: number
|
sessionPauseMilliseconds: number
|
||||||
perDay: boolean
|
perDay: boolean
|
||||||
|
expiresAt?: number
|
||||||
}) {
|
}) {
|
||||||
this.ruleId = ruleId
|
this.ruleId = ruleId
|
||||||
this.categoryId = categoryId
|
this.categoryId = categoryId
|
||||||
@@ -56,6 +58,7 @@ export class TimelimitRule {
|
|||||||
this.sessionDurationMilliseconds = sessionDurationMilliseconds
|
this.sessionDurationMilliseconds = sessionDurationMilliseconds
|
||||||
this.sessionPauseMilliseconds = sessionPauseMilliseconds
|
this.sessionPauseMilliseconds = sessionPauseMilliseconds
|
||||||
this.perDay = perDay
|
this.perDay = perDay
|
||||||
|
this.expiresAt = expiresAt
|
||||||
|
|
||||||
assertIdWithinFamily(ruleId)
|
assertIdWithinFamily(ruleId)
|
||||||
assertIdWithinFamily(categoryId)
|
assertIdWithinFamily(categoryId)
|
||||||
@@ -88,6 +91,14 @@ export class TimelimitRule {
|
|||||||
if (sessionDurationMilliseconds < 0 || sessionPauseMilliseconds < 0) {
|
if (sessionDurationMilliseconds < 0 || sessionPauseMilliseconds < 0) {
|
||||||
throw new ParseTimeLimitRuleException()
|
throw new ParseTimeLimitRuleException()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (expiresAt !== undefined) {
|
||||||
|
if (!Number.isSafeInteger(expiresAt)) throw new ParseTimeLimitRuleException()
|
||||||
|
|
||||||
|
if (expiresAt <= 0) {
|
||||||
|
throw new ParseTimeLimitRuleException()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize = (): SerializedTimeLimitRule => ({
|
serialize = (): SerializedTimeLimitRule => ({
|
||||||
@@ -99,10 +110,11 @@ export class TimelimitRule {
|
|||||||
start: this.start,
|
start: this.start,
|
||||||
end: this.end,
|
end: this.end,
|
||||||
pause: this.sessionPauseMilliseconds,
|
pause: this.sessionPauseMilliseconds,
|
||||||
dur: this.sessionDurationMilliseconds
|
dur: this.sessionDurationMilliseconds,
|
||||||
|
e: this.expiresAt
|
||||||
})
|
})
|
||||||
|
|
||||||
static parse = ({ ruleId, categoryId, time, days, extraTime, start, end, dur, pause, perDay }: SerializedTimeLimitRule) => (
|
static parse = ({ ruleId, categoryId, time, days, extraTime, start, end, dur, pause, perDay, e }: SerializedTimeLimitRule) => (
|
||||||
new TimelimitRule({
|
new TimelimitRule({
|
||||||
ruleId,
|
ruleId,
|
||||||
categoryId,
|
categoryId,
|
||||||
@@ -113,7 +125,8 @@ export class TimelimitRule {
|
|||||||
end: end ?? MinuteOfDay.MAX,
|
end: end ?? MinuteOfDay.MAX,
|
||||||
sessionDurationMilliseconds: dur ?? 0,
|
sessionDurationMilliseconds: dur ?? 0,
|
||||||
sessionPauseMilliseconds: pause ?? 0,
|
sessionPauseMilliseconds: pause ?? 0,
|
||||||
perDay: perDay ?? false
|
perDay: perDay ?? false,
|
||||||
|
expiresAt: e
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -129,6 +142,7 @@ export interface SerializedTimeLimitRule {
|
|||||||
dur?: number
|
dur?: number
|
||||||
pause?: number
|
pause?: number
|
||||||
perDay?: boolean
|
perDay?: boolean
|
||||||
|
e?: number // expiresAt
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ParseTimeLimitRuleException extends Error {}
|
export class ParseTimeLimitRuleException extends Error {}
|
||||||
|
|||||||
Reference in New Issue
Block a user