mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add platformLevel and platformType
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2023 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
|
||||
@@ -15,6 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { minPlatformLevel, maxPlatformLevel, minPlatformTypeLength, maxPlatformTypeLength } from '../database/device'
|
||||
import { NewPermissionStatus } from '../model/newpermissionstatus'
|
||||
import { ProtectionLevel } from '../model/protectionlevel'
|
||||
import { RuntimePermissionStatus } from '../model/runtimepermissionstatus'
|
||||
@@ -33,6 +34,8 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
readonly didReboot: boolean
|
||||
readonly isQOrLaterNow: boolean
|
||||
readonly addedManipulationFlags: number
|
||||
readonly platformType?: string
|
||||
readonly platformLevel?: number
|
||||
|
||||
constructor ({
|
||||
newProtetionLevel,
|
||||
@@ -43,7 +46,9 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
newAppVersion,
|
||||
didReboot,
|
||||
isQOrLaterNow,
|
||||
addedManipulationFlags
|
||||
addedManipulationFlags,
|
||||
platformType,
|
||||
platformLevel
|
||||
}: {
|
||||
newProtetionLevel?: ProtectionLevel
|
||||
newUsageStatsPermissionStatus?: RuntimePermissionStatus
|
||||
@@ -54,6 +59,8 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
didReboot: boolean
|
||||
isQOrLaterNow: boolean
|
||||
addedManipulationFlags: number
|
||||
platformType?: string
|
||||
platformLevel?: number
|
||||
}) {
|
||||
super()
|
||||
|
||||
@@ -67,6 +74,20 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
|
||||
assertSafeInteger({ actionType, field: 'addedManipulationFlags', value: addedManipulationFlags })
|
||||
|
||||
if (platformType !== undefined) {
|
||||
if (platformType.length < minPlatformTypeLength || platformType.length > maxPlatformTypeLength) {
|
||||
throwOutOfRange({ actionType, field: 'platformType.length', value: platformType.length })
|
||||
}
|
||||
}
|
||||
|
||||
if (platformLevel !== undefined) {
|
||||
assertSafeInteger({ actionType, field: 'platformLevel', value: platformLevel })
|
||||
|
||||
if (platformLevel < minPlatformLevel || platformLevel > maxPlatformLevel) {
|
||||
throwOutOfRange({ actionType, field: 'platformLevel', value: platformLevel })
|
||||
}
|
||||
}
|
||||
|
||||
this.newProtetionLevel = newProtetionLevel
|
||||
this.newUsageStatsPermissionStatus = newUsageStatsPermissionStatus
|
||||
this.newNotificationAccessPermission = newNotificationAccessPermission
|
||||
@@ -76,6 +97,8 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
this.didReboot = didReboot
|
||||
this.isQOrLaterNow = isQOrLaterNow
|
||||
this.addedManipulationFlags = addedManipulationFlags
|
||||
this.platformType = platformType
|
||||
this.platformLevel = platformLevel
|
||||
}
|
||||
|
||||
static parse = ({
|
||||
@@ -87,7 +110,9 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
appVersion,
|
||||
didReboot,
|
||||
isQOrLaterNow,
|
||||
addedManipulationFlags
|
||||
addedManipulationFlags,
|
||||
platformType,
|
||||
platformLevel
|
||||
}: SerializedUpdateDeviceStatusAction) => (
|
||||
new UpdateDeviceStatusAction({
|
||||
newProtetionLevel: protectionLevel,
|
||||
@@ -98,7 +123,9 @@ export class UpdateDeviceStatusAction extends AppLogicAction {
|
||||
newAppVersion: appVersion,
|
||||
didReboot: !!didReboot,
|
||||
isQOrLaterNow: !!isQOrLaterNow,
|
||||
addedManipulationFlags: addedManipulationFlags || 0
|
||||
addedManipulationFlags: addedManipulationFlags || 0,
|
||||
platformType: platformType,
|
||||
platformLevel: platformLevel
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -114,4 +141,6 @@ export interface SerializedUpdateDeviceStatusAction {
|
||||
didReboot?: boolean
|
||||
isQOrLaterNow?: boolean
|
||||
addedManipulationFlags?: number
|
||||
platformType?: string
|
||||
platformLevel?: number
|
||||
}
|
||||
|
||||
@@ -1982,6 +1982,12 @@ const definitions = {
|
||||
},
|
||||
"addedManipulationFlags": {
|
||||
"type": "number"
|
||||
},
|
||||
"platformType": {
|
||||
"type": "string"
|
||||
},
|
||||
"platformLevel": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
@@ -2164,6 +2170,12 @@ const definitions = {
|
||||
},
|
||||
"pk": {
|
||||
"type": "string"
|
||||
},
|
||||
"pType": {
|
||||
"type": "string"
|
||||
},
|
||||
"pLevel": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
@@ -2192,6 +2204,7 @@ const definitions = {
|
||||
"model",
|
||||
"name",
|
||||
"networkTime",
|
||||
"pLevel",
|
||||
"qOrLater",
|
||||
"reboot",
|
||||
"rebootIsManipulation",
|
||||
|
||||
+36
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2023 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -37,6 +37,12 @@ export const DeviceManipulationFlags = {
|
||||
ALL: 1
|
||||
}
|
||||
|
||||
export const minPlatformTypeLength = 1
|
||||
export const maxPlatformTypeLength = 8
|
||||
|
||||
export const minPlatformLevel = 0
|
||||
export const maxPlatformLevel = 128
|
||||
|
||||
export interface DeviceAttributesVersion1 {
|
||||
familyId: string
|
||||
deviceId: string
|
||||
@@ -119,11 +125,17 @@ export interface DeviceAttributesVersion14 {
|
||||
nextKeyReplySequenceNumber: string
|
||||
}
|
||||
|
||||
export interface DeviceAttributesVersion15 {
|
||||
platformType: string | null
|
||||
platformLevel: number
|
||||
}
|
||||
|
||||
export type DeviceAttributes = DeviceAttributesVersion1 & DeviceAttributesVersion2 &
|
||||
DeviceAttributesVersion3 & DeviceAttributesVersion4 & DeviceAttributesVersion5 &
|
||||
DeviceAttributesVersion6 & DeviceAttributesVersion7 & DeviceAttributesVersion8 &
|
||||
DeviceAttributesVersion9 & DeviceAttributesVersion10 & DeviceAttributesVersion11 &
|
||||
DeviceAttributesVersion12 & DeviceAttributesVersion13 & DeviceAttributesVersion14
|
||||
DeviceAttributesVersion12 & DeviceAttributesVersion13 & DeviceAttributesVersion14 &
|
||||
DeviceAttributesVersion15
|
||||
|
||||
export type DeviceModel = Sequelize.Model<DeviceAttributes> & DeviceAttributes
|
||||
export type DeviceModelStatic = typeof Sequelize.Model & {
|
||||
@@ -305,6 +317,26 @@ export const attributesVersion14: SequelizeAttributes<DeviceAttributesVersion14>
|
||||
}
|
||||
}
|
||||
|
||||
export const attributesVersion15: SequelizeAttributes<DeviceAttributesVersion15> = {
|
||||
platformType: {
|
||||
type: Sequelize.STRING(maxPlatformTypeLength),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
validate: {
|
||||
len: [minPlatformTypeLength, maxPlatformTypeLength]
|
||||
}
|
||||
},
|
||||
platformLevel: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: minPlatformLevel,
|
||||
validate: {
|
||||
min: minPlatformLevel,
|
||||
max: maxPlatformLevel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<DeviceAttributes> = {
|
||||
...attributesVersion1,
|
||||
...attributesVersion2,
|
||||
@@ -319,7 +351,8 @@ export const attributes: SequelizeAttributes<DeviceAttributes> = {
|
||||
...attributesVersion11,
|
||||
...attributesVersion12,
|
||||
...attributesVersion13,
|
||||
...attributesVersion14
|
||||
...attributesVersion14,
|
||||
...attributesVersion15
|
||||
}
|
||||
|
||||
export const createDeviceModel = (sequelize: Sequelize.Sequelize): DeviceModelStatic => sequelize.define('Device', attributes) as DeviceModelStatic
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2023 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 { attributesVersion15 as deviceAttributes } from '../../device'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.addColumn('Devices', 'platformType', {
|
||||
...deviceAttributes.platformType
|
||||
}, {
|
||||
transaction
|
||||
})
|
||||
|
||||
await queryInterface.addColumn('Devices', 'platformLevel', {
|
||||
...deviceAttributes.platformLevel
|
||||
}, {
|
||||
transaction
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.removeColumn('Devices', 'platformLevel', { transaction })
|
||||
await queryInterface.removeColumn('Devices', 'platformType', { transaction })
|
||||
})
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2023 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
|
||||
@@ -66,5 +66,7 @@ export const prepareDeviceEntry = ({ familyId, userId, deviceAuthToken, deviceId
|
||||
isQorLater: false,
|
||||
manipulationFlags: 0,
|
||||
publicKey: null,
|
||||
nextKeyReplySequenceNumber: '1'
|
||||
nextKeyReplySequenceNumber: '1',
|
||||
platformType: null,
|
||||
platformLevel: 0
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2023 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
|
||||
@@ -155,6 +155,18 @@ export async function dispatchUpdateDeviceStatus ({ deviceId, action, cache }: {
|
||||
}
|
||||
}
|
||||
|
||||
if (action.platformType !== undefined) {
|
||||
if (action.platformType !== deviceEntry.platformType) {
|
||||
deviceEntry.platformType = action.platformType
|
||||
}
|
||||
}
|
||||
|
||||
if (action.platformLevel !== undefined) {
|
||||
if (action.platformLevel !== deviceEntry.platformLevel) {
|
||||
deviceEntry.platformLevel = action.platformLevel
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const effectiveManipulationFlags = action.addedManipulationFlags & DeviceManipulationFlags.ALL
|
||||
|
||||
|
||||
@@ -66,7 +66,9 @@ export async function getDeviceList ({ database, transaction, familyEntry }: {
|
||||
activityLevelBlocking: item.activityLevelBlocking,
|
||||
qOrLater: item.isQorLater,
|
||||
mFlags: item.manipulationFlags,
|
||||
pk: item.publicKey ? item.publicKey.toString('base64') : undefined
|
||||
pk: item.publicKey ? item.publicKey.toString('base64') : undefined,
|
||||
pType: item.platformType || undefined,
|
||||
pLevel: item.platformLevel
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,8 @@ export interface ServerDeviceData {
|
||||
qOrLater: boolean
|
||||
mFlags: number // manipulation flags
|
||||
pk?: string // public key
|
||||
pType?: string
|
||||
pLevel: number
|
||||
}
|
||||
|
||||
export interface ServerUpdatedCategoryBaseData {
|
||||
|
||||
Reference in New Issue
Block a user