Add support for manipulationFlags

This commit is contained in:
Jonas Lochmann
2022-07-11 02:00:00 +02:00
parent 45f8a25b8b
commit acdec990ea
22 changed files with 306 additions and 19 deletions
+28 -4
View File
@@ -1,6 +1,6 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2020 Jonas Lochmann
* Copyright (C) 2019 - 2022 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
@@ -32,6 +32,11 @@ export const DeviceHadManipulationFlags = {
ALL: 1 | 2 | 4 | 8 | 16 | 32
}
export const DeviceManipulationFlags = {
USED_FGS_KILLER: 1,
ALL: 1
}
export interface DeviceAttributesVersion1 {
familyId: string
deviceId: string
@@ -102,10 +107,15 @@ export interface DeviceAttributesVersion11 {
hadManipulationFlags: number
}
export interface DeviceAttributesVersion12 {
manipulationFlags: number
}
export type DeviceAttributes = DeviceAttributesVersion1 & DeviceAttributesVersion2 &
DeviceAttributesVersion3 & DeviceAttributesVersion4 & DeviceAttributesVersion5 &
DeviceAttributesVersion6 & DeviceAttributesVersion7 & DeviceAttributesVersion8 &
DeviceAttributesVersion9 & DeviceAttributesVersion10 & DeviceAttributesVersion11
DeviceAttributesVersion9 & DeviceAttributesVersion10 & DeviceAttributesVersion11 &
DeviceAttributesVersion12
export type DeviceModel = Sequelize.Model<DeviceAttributes> & DeviceAttributes
export type DeviceModelStatic = typeof Sequelize.Model & {
@@ -259,6 +269,18 @@ export const attributesVersion11: SequelizeAttributes<DeviceAttributesVersion11>
}
}
export const attributesVersion12: SequelizeAttributes<DeviceAttributesVersion12> = {
manipulationFlags: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
validate: {
min: 0,
max: DeviceManipulationFlags.ALL
}
}
}
export const attributes: SequelizeAttributes<DeviceAttributes> = {
...attributesVersion1,
...attributesVersion2,
@@ -270,7 +292,8 @@ export const attributes: SequelizeAttributes<DeviceAttributes> = {
...attributesVersion8,
...attributesVersion9,
...attributesVersion10,
...attributesVersion11
...attributesVersion11,
...attributesVersion12
}
export const createDeviceModel = (sequelize: Sequelize.Sequelize): DeviceModelStatic => sequelize.define('Device', attributes) as DeviceModelStatic
@@ -291,7 +314,8 @@ export const hasDeviceManipulation = (device: DeviceAttributes) => {
manipulationOfOverlayPermission ||
manipulationOfAsPermission
const hasAnyManipulation = hasActiveManipulationWarning || device.hadManipulation
const hasAnyManipulation = hasActiveManipulationWarning || device.hadManipulation ||
device.manipulationFlags !== 0
return hasAnyManipulation
}
@@ -0,0 +1,39 @@
/*
* server component for the TimeLimit App
* Copyright (C) 2019 - 2022 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 { attributesVersion12 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', 'manipulationFlags', {
...deviceAttributes.manipulationFlags
}, {
transaction
})
})
}
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
await sequelize.transaction({
type: Transaction.TYPES.EXCLUSIVE
}, async (transaction) => {
await queryInterface.removeColumn('Devices', 'manipulationFlags', { transaction })
})
}