From 1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 15 Apr 2019 10:49:46 +0200 Subject: Add user adminFlags --- server/helpers/custom-jsonld-signature.ts | 68 ++++++++++++++++++++++++++++++- server/helpers/custom-validators/users.ts | 8 +++- 2 files changed, 73 insertions(+), 3 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/custom-jsonld-signature.ts b/server/helpers/custom-jsonld-signature.ts index 27a187db1..a3bceb047 100644 --- a/server/helpers/custom-jsonld-signature.ts +++ b/server/helpers/custom-jsonld-signature.ts @@ -1,13 +1,77 @@ import * as AsyncLRU from 'async-lru' import * as jsonld from 'jsonld' import * as jsig from 'jsonld-signatures' +import { logger } from './logger' + +const CACHE = { + 'https://w3id.org/security/v1': { + '@context': { + 'id': '@id', + 'type': '@type', + + 'dc': 'http://purl.org/dc/terms/', + 'sec': 'https://w3id.org/security#', + 'xsd': 'http://www.w3.org/2001/XMLSchema#', + + 'EcdsaKoblitzSignature2016': 'sec:EcdsaKoblitzSignature2016', + 'Ed25519Signature2018': 'sec:Ed25519Signature2018', + 'EncryptedMessage': 'sec:EncryptedMessage', + 'GraphSignature2012': 'sec:GraphSignature2012', + 'LinkedDataSignature2015': 'sec:LinkedDataSignature2015', + 'LinkedDataSignature2016': 'sec:LinkedDataSignature2016', + 'CryptographicKey': 'sec:Key', + + 'authenticationTag': 'sec:authenticationTag', + 'canonicalizationAlgorithm': 'sec:canonicalizationAlgorithm', + 'cipherAlgorithm': 'sec:cipherAlgorithm', + 'cipherData': 'sec:cipherData', + 'cipherKey': 'sec:cipherKey', + 'created': { '@id': 'dc:created', '@type': 'xsd:dateTime' }, + 'creator': { '@id': 'dc:creator', '@type': '@id' }, + 'digestAlgorithm': 'sec:digestAlgorithm', + 'digestValue': 'sec:digestValue', + 'domain': 'sec:domain', + 'encryptionKey': 'sec:encryptionKey', + 'expiration': { '@id': 'sec:expiration', '@type': 'xsd:dateTime' }, + 'expires': { '@id': 'sec:expiration', '@type': 'xsd:dateTime' }, + 'initializationVector': 'sec:initializationVector', + 'iterationCount': 'sec:iterationCount', + 'nonce': 'sec:nonce', + 'normalizationAlgorithm': 'sec:normalizationAlgorithm', + 'owner': { '@id': 'sec:owner', '@type': '@id' }, + 'password': 'sec:password', + 'privateKey': { '@id': 'sec:privateKey', '@type': '@id' }, + 'privateKeyPem': 'sec:privateKeyPem', + 'publicKey': { '@id': 'sec:publicKey', '@type': '@id' }, + 'publicKeyBase58': 'sec:publicKeyBase58', + 'publicKeyPem': 'sec:publicKeyPem', + 'publicKeyWif': 'sec:publicKeyWif', + 'publicKeyService': { '@id': 'sec:publicKeyService', '@type': '@id' }, + 'revoked': { '@id': 'sec:revoked', '@type': 'xsd:dateTime' }, + 'salt': 'sec:salt', + 'signature': 'sec:signature', + 'signatureAlgorithm': 'sec:signingAlgorithm', + 'signatureValue': 'sec:signatureValue' + } + } +} const nodeDocumentLoader = jsonld.documentLoaders.node() const lru = new AsyncLRU({ max: 10, - load: (key, cb) => { - nodeDocumentLoader(key, cb) + load: (url, cb) => { + if (CACHE[ url ] !== undefined) { + logger.debug('Using cache for JSON-LD %s.', url) + + return cb(null, { + contextUrl: null, + document: CACHE[ url ], + documentUrl: url + }) + } + + nodeDocumentLoader(url, cb) } }) diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index 70af5f1f0..e3ad9102a 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts @@ -1,9 +1,10 @@ import 'express-validator' import * as validator from 'validator' -import { UserRole } from '../../../shared' +import { UserNotificationSettingValue, UserRole } from '../../../shared' import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants' import { exists, isFileValid, isBooleanValid } from './misc' import { values } from 'lodash' +import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS @@ -54,6 +55,10 @@ function isUserAutoPlayVideoValid (value: any) { return isBooleanValid(value) } +function isUserAdminFlagsValid (value: any) { + return exists(value) && validator.isInt('' + value) +} + function isUserBlockedValid (value: any) { return isBooleanValid(value) } @@ -85,6 +90,7 @@ export { isUserVideoQuotaValid, isUserVideoQuotaDailyValid, isUserUsernameValid, + isUserAdminFlagsValid, isUserEmailVerifiedValid, isUserNSFWPolicyValid, isUserWebTorrentEnabledValid, -- cgit v1.2.3