mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add preblocking
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 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 { attributesVersion2 as limitLoginCategoryAttributes } from '../../userlimitlogincategory'
|
||||
|
||||
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
// timelimit rule table
|
||||
await queryInterface.addColumn('UserLimitLoginCategories', 'preBlockDuration', {
|
||||
...limitLoginCategoryAttributes.preBlockDuration
|
||||
}, { transaction })
|
||||
})
|
||||
}
|
||||
|
||||
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||
await sequelize.transaction({
|
||||
type: Transaction.TYPES.EXCLUSIVE
|
||||
}, async (transaction) => {
|
||||
await queryInterface.removeColumn('UserLimitLoginCategories', 'preBlockDuration', { transaction })
|
||||
})
|
||||
}
|
||||
@@ -19,21 +19,46 @@ import * as Sequelize from 'sequelize'
|
||||
import { familyIdColumn, idWithinFamilyColumn } from './columns'
|
||||
import { SequelizeAttributes } from './types'
|
||||
|
||||
export interface UserLimitLoginCategoryAttributes {
|
||||
export const maxPreBlockDuration = 1000 * 60 * 60 * 24 // 1 day
|
||||
|
||||
export interface UserLimitLoginCategoryAttributesVersion1 {
|
||||
familyId: string
|
||||
userId: string
|
||||
categoryId: string
|
||||
}
|
||||
|
||||
export interface UserLimitLoginCategoryAttributesVersion2 {
|
||||
preBlockDuration: number
|
||||
}
|
||||
|
||||
export type UserLimitLoginCategoryAttributes = UserLimitLoginCategoryAttributesVersion1 & UserLimitLoginCategoryAttributesVersion2
|
||||
|
||||
export type UserLimitLoginCategoryModel = Sequelize.Model & UserLimitLoginCategoryAttributes
|
||||
export type UserLimitLoginCategoryModelStatic = typeof Sequelize.Model & {
|
||||
new (values?: object, options?: Sequelize.BuildOptions): UserLimitLoginCategoryModel;
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<UserLimitLoginCategoryAttributes> = {
|
||||
export const attributesVersion1: SequelizeAttributes<UserLimitLoginCategoryAttributesVersion1> = {
|
||||
familyId: { ...familyIdColumn, primaryKey: true },
|
||||
userId: { ...idWithinFamilyColumn, primaryKey: true },
|
||||
categoryId: { ...idWithinFamilyColumn }
|
||||
}
|
||||
|
||||
export const attributesVersion2: SequelizeAttributes<UserLimitLoginCategoryAttributesVersion2> = {
|
||||
preBlockDuration: {
|
||||
type: Sequelize.INTEGER,
|
||||
validate: {
|
||||
min: 0,
|
||||
max: maxPreBlockDuration
|
||||
},
|
||||
allowNull: false,
|
||||
defaultValue: 0
|
||||
}
|
||||
}
|
||||
|
||||
export const attributes: SequelizeAttributes<UserLimitLoginCategoryAttributes> = {
|
||||
...attributesVersion1,
|
||||
...attributesVersion2
|
||||
}
|
||||
|
||||
export const createUserLimitLoginCategoryModel = (sequelize: Sequelize.Sequelize): UserLimitLoginCategoryModelStatic => sequelize.define('UserLimitLoginCategory', attributes) as UserLimitLoginCategoryModelStatic
|
||||
|
||||
Reference in New Issue
Block a user