From 8ec0781859c84e1608be3e5dfeb454b12c241d92 Mon Sep 17 00:00:00 2001 From: Jonas Lochmann Date: Mon, 12 Jun 2023 02:00:00 +0200 Subject: [PATCH] Add platformLevel and platformType --- .../SerializedAppLogicAction.schema.json | 6 +++ docs/schema/ServerDataStatus.schema.json | 7 +++ ...cestatusaction-properties-platformlevel.md | 15 ++++++ ...icestatusaction-properties-platformtype.md | 15 ++++++ ...ions-serializedupdatedevicestatusaction.md | 38 +++++++++++++++ docs/schema/serializedapplogicaction.md | 38 +++++++++++++++ ...ions-serverdevicedata-properties-plevel.md | 15 ++++++ ...tions-serverdevicedata-properties-ptype.md | 15 ++++++ ...datastatus-definitions-serverdevicedata.md | 38 +++++++++++++++ docs/schema/serverdatastatus.md | 38 +++++++++++++++ src/action/updatedevicestatus.ts | 37 +++++++++++++-- src/api/validator.ts | 13 ++++++ src/database/device.ts | 39 ++++++++++++++-- .../migrations/20230612-add-platform-level.ts | 46 +++++++++++++++++++ src/function/device/prepare-device-entry.ts | 6 ++- .../updatedevicestatus.ts | 14 +++++- .../get-server-data-status/device-list.ts | 4 +- src/object/serverdatastatus.ts | 2 + 18 files changed, 375 insertions(+), 11 deletions(-) create mode 100644 docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformlevel.md create mode 100644 docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformtype.md create mode 100644 docs/schema/serverdatastatus-definitions-serverdevicedata-properties-plevel.md create mode 100644 docs/schema/serverdatastatus-definitions-serverdevicedata-properties-ptype.md create mode 100644 src/database/migration/migrations/20230612-add-platform-level.ts diff --git a/docs/schema/SerializedAppLogicAction.schema.json b/docs/schema/SerializedAppLogicAction.schema.json index 34db597..8950217 100644 --- a/docs/schema/SerializedAppLogicAction.schema.json +++ b/docs/schema/SerializedAppLogicAction.schema.json @@ -545,6 +545,12 @@ }, "addedManipulationFlags": { "type": "number" + }, + "platformType": { + "type": "string" + }, + "platformLevel": { + "type": "number" } }, "additionalProperties": false, diff --git a/docs/schema/ServerDataStatus.schema.json b/docs/schema/ServerDataStatus.schema.json index 97a781b..9c9e3b2 100644 --- a/docs/schema/ServerDataStatus.schema.json +++ b/docs/schema/ServerDataStatus.schema.json @@ -212,6 +212,12 @@ }, "pk": { "type": "string" + }, + "pType": { + "type": "string" + }, + "pLevel": { + "type": "number" } }, "additionalProperties": false, @@ -240,6 +246,7 @@ "model", "name", "networkTime", + "pLevel", "qOrLater", "reboot", "rebootIsManipulation", diff --git a/docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformlevel.md b/docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformlevel.md new file mode 100644 index 0000000..5f00bd3 --- /dev/null +++ b/docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformlevel.md @@ -0,0 +1,15 @@ +# Untitled number in SerializedAppLogicAction Schema + +```txt +https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/platformLevel +``` + + + +| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In | +| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :---------------------------------------------------------------------------------------------------- | +| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedAppLogicAction.schema.json\*](SerializedAppLogicAction.schema.json "open original schema") | + +## platformLevel Type + +`number` diff --git a/docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformtype.md b/docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformtype.md new file mode 100644 index 0000000..00e78ba --- /dev/null +++ b/docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformtype.md @@ -0,0 +1,15 @@ +# Untitled string in SerializedAppLogicAction Schema + +```txt +https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/platformType +``` + + + +| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In | +| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :---------------------------------------------------------------------------------------------------- | +| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [SerializedAppLogicAction.schema.json\*](SerializedAppLogicAction.schema.json "open original schema") | + +## platformType Type + +`string` diff --git a/docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction.md b/docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction.md index 604653b..8cf8305 100644 --- a/docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction.md +++ b/docs/schema/serializedapplogicaction-definitions-serializedupdatedevicestatusaction.md @@ -28,6 +28,8 @@ https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDevic | [didReboot](#didreboot) | `boolean` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-didreboot.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/didReboot") | | [isQOrLaterNow](#isqorlaternow) | `boolean` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-isqorlaternow.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/isQOrLaterNow") | | [addedManipulationFlags](#addedmanipulationflags) | `number` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-addedmanipulationflags.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/addedManipulationFlags") | +| [platformType](#platformtype) | `string` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformtype.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/platformType") | +| [platformLevel](#platformlevel) | `number` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformlevel.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/platformLevel") | ## type @@ -257,3 +259,39 @@ https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDevic ### addedManipulationFlags Type `number` + +## platformType + + + +`platformType` + +* is optional + +* Type: `string` + +* cannot be null + +* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformtype.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/platformType") + +### platformType Type + +`string` + +## platformLevel + + + +`platformLevel` + +* is optional + +* Type: `number` + +* cannot be null + +* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformlevel.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/platformLevel") + +### platformLevel Type + +`number` diff --git a/docs/schema/serializedapplogicaction.md b/docs/schema/serializedapplogicaction.md index 3dd9ff2..1050d9d 100644 --- a/docs/schema/serializedapplogicaction.md +++ b/docs/schema/serializedapplogicaction.md @@ -1240,6 +1240,8 @@ Reference this group by using | [didReboot](#didreboot) | `boolean` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-didreboot.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/didReboot") | | [isQOrLaterNow](#isqorlaternow) | `boolean` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-isqorlaternow.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/isQOrLaterNow") | | [addedManipulationFlags](#addedmanipulationflags) | `number` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-addedmanipulationflags.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/addedManipulationFlags") | +| [platformType](#platformtype) | `string` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformtype.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/platformType") | +| [platformLevel](#platformlevel) | `number` | Optional | cannot be null | [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformlevel.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/platformLevel") | ### type @@ -1470,6 +1472,42 @@ Reference this group by using `number` +### platformType + + + +`platformType` + +* is optional + +* Type: `string` + +* cannot be null + +* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformtype.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/platformType") + +#### platformType Type + +`string` + +### platformLevel + + + +`platformLevel` + +* is optional + +* Type: `number` + +* cannot be null + +* defined in: [SerializedAppLogicAction](serializedapplogicaction-definitions-serializedupdatedevicestatusaction-properties-platformlevel.md "https://timelimit.io/SerializedAppLogicAction#/definitions/SerializedUpdateDeviceStatusAction/properties/platformLevel") + +#### platformLevel Type + +`number` + ## Definitions group SerializedUploadDevicePublicKeyAction Reference this group by using diff --git a/docs/schema/serverdatastatus-definitions-serverdevicedata-properties-plevel.md b/docs/schema/serverdatastatus-definitions-serverdevicedata-properties-plevel.md new file mode 100644 index 0000000..e997957 --- /dev/null +++ b/docs/schema/serverdatastatus-definitions-serverdevicedata-properties-plevel.md @@ -0,0 +1,15 @@ +# Untitled number in ServerDataStatus Schema + +```txt +https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pLevel +``` + + + +| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In | +| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------ | +| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [ServerDataStatus.schema.json\*](ServerDataStatus.schema.json "open original schema") | + +## pLevel Type + +`number` diff --git a/docs/schema/serverdatastatus-definitions-serverdevicedata-properties-ptype.md b/docs/schema/serverdatastatus-definitions-serverdevicedata-properties-ptype.md new file mode 100644 index 0000000..fb873c5 --- /dev/null +++ b/docs/schema/serverdatastatus-definitions-serverdevicedata-properties-ptype.md @@ -0,0 +1,15 @@ +# Untitled string in ServerDataStatus Schema + +```txt +https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pType +``` + + + +| Abstract | Extensible | Status | Identifiable | Custom Properties | Additional Properties | Access Restrictions | Defined In | +| :------------------ | :--------- | :------------- | :---------------------- | :---------------- | :-------------------- | :------------------ | :------------------------------------------------------------------------------------ | +| Can be instantiated | No | Unknown status | Unknown identifiability | Forbidden | Allowed | none | [ServerDataStatus.schema.json\*](ServerDataStatus.schema.json "open original schema") | + +## pType Type + +`string` diff --git a/docs/schema/serverdatastatus-definitions-serverdevicedata.md b/docs/schema/serverdatastatus-definitions-serverdevicedata.md index ca29b31..23ca8c9 100644 --- a/docs/schema/serverdatastatus-definitions-serverdevicedata.md +++ b/docs/schema/serverdatastatus-definitions-serverdevicedata.md @@ -50,6 +50,8 @@ https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData | [qOrLater](#qorlater) | `boolean` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-qorlater.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/qOrLater") | | [mFlags](#mflags) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-mflags.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/mFlags") | | [pk](#pk) | `string` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-pk.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pk") | +| [pType](#ptype) | `string` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-ptype.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pType") | +| [pLevel](#plevel) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-plevel.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pLevel") | ## deviceId @@ -718,3 +720,39 @@ https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData ### pk Type `string` + +## pType + + + +`pType` + +* is optional + +* Type: `string` + +* cannot be null + +* defined in: [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-ptype.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pType") + +### pType Type + +`string` + +## pLevel + + + +`pLevel` + +* is required + +* Type: `number` + +* cannot be null + +* defined in: [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-plevel.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pLevel") + +### pLevel Type + +`number` diff --git a/docs/schema/serverdatastatus.md b/docs/schema/serverdatastatus.md index badb759..aed8191 100644 --- a/docs/schema/serverdatastatus.md +++ b/docs/schema/serverdatastatus.md @@ -435,6 +435,8 @@ Reference this group by using | [qOrLater](#qorlater) | `boolean` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-qorlater.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/qOrLater") | | [mFlags](#mflags) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-mflags.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/mFlags") | | [pk](#pk) | `string` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-pk.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pk") | +| [pType](#ptype) | `string` | Optional | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-ptype.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pType") | +| [pLevel](#plevel) | `number` | Required | cannot be null | [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-plevel.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pLevel") | ### deviceId @@ -1104,6 +1106,42 @@ Reference this group by using `string` +### pType + + + +`pType` + +* is optional + +* Type: `string` + +* cannot be null + +* defined in: [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-ptype.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pType") + +#### pType Type + +`string` + +### pLevel + + + +`pLevel` + +* is required + +* Type: `number` + +* cannot be null + +* defined in: [ServerDataStatus](serverdatastatus-definitions-serverdevicedata-properties-plevel.md "https://timelimit.io/ServerDataStatus#/definitions/ServerDeviceData/properties/pLevel") + +#### pLevel Type + +`number` + ## Definitions group ProtectionLevel Reference this group by using diff --git a/src/action/updatedevicestatus.ts b/src/action/updatedevicestatus.ts index e550f3c..d1ffcd8 100644 --- a/src/action/updatedevicestatus.ts +++ b/src/action/updatedevicestatus.ts @@ -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 . */ +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 } diff --git a/src/api/validator.ts b/src/api/validator.ts index 98f176c..408c934 100644 --- a/src/api/validator.ts +++ b/src/api/validator.ts @@ -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", diff --git a/src/database/device.ts b/src/database/device.ts index 9b9413c..974c4b2 100644 --- a/src/database/device.ts +++ b/src/database/device.ts @@ -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 export type DeviceModelStatic = typeof Sequelize.Model & { @@ -305,6 +317,26 @@ export const attributesVersion14: SequelizeAttributes } } +export const attributesVersion15: SequelizeAttributes = { + 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 = { ...attributesVersion1, ...attributesVersion2, @@ -319,7 +351,8 @@ export const attributes: SequelizeAttributes = { ...attributesVersion11, ...attributesVersion12, ...attributesVersion13, - ...attributesVersion14 + ...attributesVersion14, + ...attributesVersion15 } export const createDeviceModel = (sequelize: Sequelize.Sequelize): DeviceModelStatic => sequelize.define('Device', attributes) as DeviceModelStatic diff --git a/src/database/migration/migrations/20230612-add-platform-level.ts b/src/database/migration/migrations/20230612-add-platform-level.ts new file mode 100644 index 0000000..d614544 --- /dev/null +++ b/src/database/migration/migrations/20230612-add-platform-level.ts @@ -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 . + */ + +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 }) + }) +} diff --git a/src/function/device/prepare-device-entry.ts b/src/function/device/prepare-device-entry.ts index 32d2a7b..7198b32 100644 --- a/src/function/device/prepare-device-entry.ts +++ b/src/function/device/prepare-device-entry.ts @@ -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 }) diff --git a/src/function/sync/apply-actions/dispatch-app-logic-action/updatedevicestatus.ts b/src/function/sync/apply-actions/dispatch-app-logic-action/updatedevicestatus.ts index 1f9a601..070ac7c 100644 --- a/src/function/sync/apply-actions/dispatch-app-logic-action/updatedevicestatus.ts +++ b/src/function/sync/apply-actions/dispatch-app-logic-action/updatedevicestatus.ts @@ -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 diff --git a/src/function/sync/get-server-data-status/device-list.ts b/src/function/sync/get-server-data-status/device-list.ts index 0d56181..dbe2e16 100644 --- a/src/function/sync/get-server-data-status/device-list.ts +++ b/src/function/sync/get-server-data-status/device-list.ts @@ -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 })) } } diff --git a/src/object/serverdatastatus.ts b/src/object/serverdatastatus.ts index 73584d9..effc808 100644 --- a/src/object/serverdatastatus.ts +++ b/src/object/serverdatastatus.ts @@ -103,6 +103,8 @@ export interface ServerDeviceData { qOrLater: boolean mFlags: number // manipulation flags pk?: string // public key + pType?: string + pLevel: number } export interface ServerUpdatedCategoryBaseData {