From a73af1338e6e4bffc734dfef5d55cd4043da3c1c Mon Sep 17 00:00:00 2001 From: Jonas Lochmann Date: Mon, 3 Aug 2020 02:00:00 +0200 Subject: [PATCH] Add option to always unlock the premium version --- docs/api/parent.md | 5 +++-- docs/usage/configuration.md | 4 +++- docs/usage/docker.md | 2 ++ src/api/parent.ts | 3 ++- src/config.ts | 6 ++++-- src/function/child/set-primary-device.ts | 5 +++-- src/function/sync/apply-actions/cache.ts | 5 +++-- src/function/sync/get-server-data-status.ts | 5 ++++- 8 files changed, 24 insertions(+), 11 deletions(-) diff --git a/docs/api/parent.md b/docs/api/parent.md index 6ca6278..71e3a5e 100644 --- a/docs/api/parent.md +++ b/docs/api/parent.md @@ -20,12 +20,13 @@ On a invalid request body: HTTP status code 400 Bad Request If the mail auth token is invalid/ expired: HTTP status code 401 Unauthorized -On success: a object with the properties ``status`` (string), ``mail`` (string) and -``canCreateFamily`` (boolean) +On success: a object with the properties ``status`` (string), ``mail`` (string), +``canCreateFamily`` (boolean) and ``alwaysPro`` (boolean) - ``status`` is ``with family`` or ``without family`` - ``mail`` is the mail address for which the auth token was created - ``canCreateFamily`` is false if the sign up of new families was disabled and otherwise true +- ``alwaysPro`` is true if the premium version is always unlocked ## POST /parent/create-family diff --git a/docs/usage/configuration.md b/docs/usage/configuration.md index 876a1e4..a1081b5 100644 --- a/docs/usage/configuration.md +++ b/docs/usage/configuration.md @@ -48,7 +48,9 @@ - DISABLE_SIGNUP - ``yes`` or ``no`` (default: no) - disables creating new families if ``yes`` is selected - - the default value is ``no`` +- ALWAYS_PRO + - ``yes`` or ``no`` (default: ``no``) + - if ``yes``, then the features of the premium version are unlocked for all users - PING_INTERVAL_SEC - ping interval at the websocket in seconds - the default value is ``25`` diff --git a/docs/usage/docker.md b/docs/usage/docker.md index c1ed317..f81765f 100644 --- a/docs/usage/docker.md +++ b/docs/usage/docker.md @@ -23,6 +23,7 @@ services: PORT: 8080 MAIL_SENDER: me@my.timelimit.server MAIL_TRANSPORT: '{"host": "localhost", "port": 25}' + ALWAYS_PRO: yes # put additional config variables here ports: - "8080:8080" @@ -68,6 +69,7 @@ services: PORT: 8080 MAIL_SENDER: me@my.timelimit.server MAIL_TRANSPORT: '{"host": "localhost", "port": 25}' + ALWAYS_PRO: yes # put additional config variables here restart: always # you can enable logging during testing by commenting this out, diff --git a/src/api/parent.ts b/src/api/parent.ts index 04ea3aa..0f28552 100644 --- a/src/api/parent.ts +++ b/src/api/parent.ts @@ -51,7 +51,8 @@ export const createParentRouter = ({ database, websocket }: {database: Database, res.json({ status, mail, - canCreateFamily: !config.disableSignup + canCreateFamily: !config.disableSignup, + alwaysPro: config.alwaysPro }) } catch (ex) { next(ex) diff --git a/src/config.ts b/src/config.ts index 58d7f46..316a913 100644 --- a/src/config.ts +++ b/src/config.ts @@ -20,6 +20,7 @@ interface Config { mailWhitelist: Array disableSignup: boolean pingInterval: number + alwaysPro: boolean } function parseYesNo (value: string) { @@ -28,12 +29,13 @@ function parseYesNo (value: string) { } else if (value === 'no') { return false } else { - throw new Error('invalid value "' + value + '", expected "" or "no"') + throw new Error('invalid value "' + value + '", expected "yes" or "no"') } } export const config: Config = { mailWhitelist: (process.env.MAIL_WHITELIST || '').split(',').map((item) => item.trim()).filter((item) => item.length > 0), disableSignup: parseYesNo(process.env.DISABLE_SIGNUP || 'no'), - pingInterval: parseInt(process.env.PING_INTERVAL_SEC || '25', 10) * 1000 + pingInterval: parseInt(process.env.PING_INTERVAL_SEC || '25', 10) * 1000, + alwaysPro: process.env.ALWAYS_PRO ? parseYesNo(process.env.ALWAYS_PRO) : false } diff --git a/src/function/child/set-primary-device.ts b/src/function/child/set-primary-device.ts index 53e6866..9877079 100644 --- a/src/function/child/set-primary-device.ts +++ b/src/function/child/set-primary-device.ts @@ -1,6 +1,6 @@ /* * server component for the TimeLimit App - * Copyright (C) 2019 Jonas Lochmann + * 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 @@ -17,6 +17,7 @@ import { Conflict, Unauthorized } from 'http-errors' import * as Sequelize from 'sequelize' +import { config } from '../../config' import { Database } from '../../database' import { generateVersionId } from '../../util/token' import { WebsocketApi } from '../../websocket' @@ -104,7 +105,7 @@ export const setPrimaryDevice = async ({ database, websocket, deviceAuthToken, c hasFullVersion: familyEntryUnsafe.hasFullVersion } - if (!familyEntry.hasFullVersion) { + if (!(familyEntry.hasFullVersion || config.alwaysPro)) { return { response: 'requires full version', sourceDeviceId: deviceEntry.deviceId, diff --git a/src/function/sync/apply-actions/cache.ts b/src/function/sync/apply-actions/cache.ts index f9ae4d9..cea35d7 100644 --- a/src/function/sync/apply-actions/cache.ts +++ b/src/function/sync/apply-actions/cache.ts @@ -1,6 +1,6 @@ /* * server component for the TimeLimit App - * Copyright (C) 2019 Jonas Lochmann + * 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 @@ -17,6 +17,7 @@ import { memoize, uniq } from 'lodash' import * as Sequelize from 'sequelize' +import { config } from '../../../config' import { VisibleConnectedDevicesManager } from '../../../connected-devices' import { Database } from '../../../database' import { generateVersionId } from '../../../util/token' @@ -49,7 +50,7 @@ export class Cache { connectedDevicesManager: VisibleConnectedDevicesManager }) { this.familyId = familyId - this.hasFullVersion = hasFullVersion + this.hasFullVersion = hasFullVersion || config.alwaysPro this.database = database this.transaction = transaction this.connectedDevicesManager = connectedDevicesManager diff --git a/src/function/sync/get-server-data-status.ts b/src/function/sync/get-server-data-status.ts index 44699ea..4ce6ae8 100644 --- a/src/function/sync/get-server-data-status.ts +++ b/src/function/sync/get-server-data-status.ts @@ -17,6 +17,7 @@ import { difference, filter, intersection } from 'lodash' import * as Sequelize from 'sequelize' +import { config } from '../../config' import { Database } from '../../database' import { getStatusMessage } from '../../function/statusmessage' import { ClientDataStatus } from '../../object/clientdatastatus' @@ -58,7 +59,9 @@ export const generateServerDataStatus = async ({ database, clientStatus, familyI } let result: ServerDataStatus = { - fullVersion: familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0, + fullVersion: config.alwaysPro ? 1 : ( + familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0 + ), message: await getStatusMessage({ database, transaction }) || undefined }