From 4793c343fd3cde3c6282ed0fb38e039b4276de0e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Feb 2017 19:19:56 +0100 Subject: Add email to pods --- .../friends/friend-list/friend-list.component.ts | 4 ++++ client/src/app/+admin/friends/shared/friend.model.ts | 1 + config/default.yaml | 3 +++ config/production.yaml.example | 3 +++ config/test-1.yaml | 3 +++ config/test-2.yaml | 3 +++ config/test-3.yaml | 3 +++ config/test-4.yaml | 3 +++ config/test-5.yaml | 3 +++ config/test-6.yaml | 3 +++ server/controllers/api/pods.js | 3 ++- server/initializers/checker.js | 3 ++- server/initializers/constants.js | 5 ++++- server/initializers/migrations/0005-email-pod.js | 20 ++++++++++++++++++++ server/initializers/migrations/0005-example.js | 14 -------------- server/initializers/migrator.js | 9 +++++++-- server/lib/friends.js | 3 ++- server/middlewares/validators/pods.js | 3 ++- server/models/pod.js | 5 +++++ server/tests/api/friends-basic.js | 2 ++ 20 files changed, 75 insertions(+), 21 deletions(-) create mode 100644 server/initializers/migrations/0005-email-pod.js delete mode 100644 server/initializers/migrations/0005-example.js diff --git a/client/src/app/+admin/friends/friend-list/friend-list.component.ts b/client/src/app/+admin/friends/friend-list/friend-list.component.ts index 9783adf16..525a9fbc3 100644 --- a/client/src/app/+admin/friends/friend-list/friend-list.component.ts +++ b/client/src/app/+admin/friends/friend-list/friend-list.component.ts @@ -35,6 +35,10 @@ export class FriendListComponent { title: 'Host', sort: false }, + email: { + title: 'Email', + sort: false + }, score: { title: 'Score', sort: false diff --git a/client/src/app/+admin/friends/shared/friend.model.ts b/client/src/app/+admin/friends/shared/friend.model.ts index 462cc82ed..f72156d05 100644 --- a/client/src/app/+admin/friends/shared/friend.model.ts +++ b/client/src/app/+admin/friends/shared/friend.model.ts @@ -2,5 +2,6 @@ export interface Friend { id: string; host: string; score: number; + email: string; createdAt: Date; } diff --git a/config/default.yaml b/config/default.yaml index ad87191fd..172bbef1e 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -22,3 +22,6 @@ storage: previews: 'previews/' thumbnails: 'thumbnails/' torrents: 'torrents/' + +admin: + email: 'admin@example.com' diff --git a/config/production.yaml.example b/config/production.yaml.example index ba7ff8f2e..cbfb0f46c 100644 --- a/config/production.yaml.example +++ b/config/production.yaml.example @@ -23,3 +23,6 @@ storage: previews: 'previews/' thumbnails: 'thumbnails/' torrents: 'torrents/' + +admin: + email: 'admin@example.com' diff --git a/config/test-1.yaml b/config/test-1.yaml index b2a0a5422..dbe408a8c 100644 --- a/config/test-1.yaml +++ b/config/test-1.yaml @@ -15,3 +15,6 @@ storage: logs: 'test1/logs/' thumbnails: 'test1/thumbnails/' torrents: 'test1/torrents/' + +admin: + email: 'admin1@example.com' diff --git a/config/test-2.yaml b/config/test-2.yaml index 7285f3394..13e09ff4c 100644 --- a/config/test-2.yaml +++ b/config/test-2.yaml @@ -15,3 +15,6 @@ storage: logs: 'test2/logs/' thumbnails: 'test2/thumbnails/' torrents: 'test2/torrents/' + +admin: + email: 'admin2@example.com' diff --git a/config/test-3.yaml b/config/test-3.yaml index 138a2cd53..2eb984692 100644 --- a/config/test-3.yaml +++ b/config/test-3.yaml @@ -15,3 +15,6 @@ storage: logs: 'test3/logs/' thumbnails: 'test3/thumbnails/' torrents: 'test3/torrents/' + +admin: + email: 'admin3@example.com' diff --git a/config/test-4.yaml b/config/test-4.yaml index 7425f4af7..a0a9bde21 100644 --- a/config/test-4.yaml +++ b/config/test-4.yaml @@ -15,3 +15,6 @@ storage: logs: 'test4/logs/' thumbnails: 'test4/thumbnails/' torrents: 'test4/torrents/' + +admin: + email: 'admin4@example.com' diff --git a/config/test-5.yaml b/config/test-5.yaml index 1bf0de658..af8654e14 100644 --- a/config/test-5.yaml +++ b/config/test-5.yaml @@ -15,3 +15,6 @@ storage: logs: 'test5/logs/' thumbnails: 'test5/thumbnails/' torrents: 'test5/torrents/' + +admin: + email: 'admin5@example.com' diff --git a/config/test-6.yaml b/config/test-6.yaml index 7303a08fc..d74d3b052 100644 --- a/config/test-6.yaml +++ b/config/test-6.yaml @@ -15,3 +15,6 @@ storage: logs: 'test6/logs/' thumbnails: 'test6/thumbnails/' torrents: 'test6/torrents/' + +admin: + email: 'admin6@example.com' diff --git a/server/controllers/api/pods.js b/server/controllers/api/pods.js index da991f8d9..1c3eefcc1 100644 --- a/server/controllers/api/pods.js +++ b/server/controllers/api/pods.js @@ -4,6 +4,7 @@ const express = require('express') const waterfall = require('async/waterfall') const db = require('../../initializers/database') +const constants = require('../../initializers/constants') const logger = require('../../helpers/logger') const peertubeCrypto = require('../../helpers/peertube-crypto') const utils = require('../../helpers/utils') @@ -80,7 +81,7 @@ function addPods (req, res, next) { ], function (err, cert) { if (err) return next(err) - return res.json({ cert: cert }) + return res.json({ cert: cert, email: constants.CONFIG.ADMIN.EMAIL }) }) } diff --git a/server/initializers/checker.js b/server/initializers/checker.js index 6471bb4f1..7adbbb37a 100644 --- a/server/initializers/checker.js +++ b/server/initializers/checker.js @@ -28,7 +28,8 @@ function checkMissedConfig () { const required = [ 'listen.port', 'webserver.https', 'webserver.hostname', 'webserver.port', 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', - 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews' + 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', + 'admin.email' ] const miss = [] diff --git a/server/initializers/constants.js b/server/initializers/constants.js index ad7cf4f4d..eb0509efe 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -54,6 +54,9 @@ const CONFIG = { WS: config.get('webserver.https') === true ? 'wss' : 'ws', HOSTNAME: config.get('webserver.hostname'), PORT: config.get('webserver.port') + }, + ADMIN: { + EMAIL: config.get('admin.email') } } CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT @@ -92,7 +95,7 @@ const FRIEND_SCORE = { // --------------------------------------------------------------------------- -const LAST_MIGRATION_VERSION = 0 +const LAST_MIGRATION_VERSION = 5 // --------------------------------------------------------------------------- diff --git a/server/initializers/migrations/0005-email-pod.js b/server/initializers/migrations/0005-email-pod.js new file mode 100644 index 000000000..d90b674a1 --- /dev/null +++ b/server/initializers/migrations/0005-email-pod.js @@ -0,0 +1,20 @@ +/* + This is just an example. +*/ + +// utils = { transaction, queryInterface } +exports.up = function (utils, callback) { + const q = utils.queryInterface + const Sequelize = utils.Sequelize + + const data = { + type: Sequelize.STRING(400), + allowNull: false + } + + q.addColumn('Pods', 'email', data, { transaction: utils.transaction }).asCallback(callback) +} + +exports.down = function (options, callback) { + throw new Error('Not implemented.') +} diff --git a/server/initializers/migrations/0005-example.js b/server/initializers/migrations/0005-example.js deleted file mode 100644 index cedc42919..000000000 --- a/server/initializers/migrations/0005-example.js +++ /dev/null @@ -1,14 +0,0 @@ -// /* -// This is just an example. -// */ - -// const db = require('../database') - -// // options contains the transaction -// exports.up = function (options, callback) { -// db.Application.create({ migrationVersion: 42 }, { transaction: options.transaction }).asCallback(callback) -// } - -// exports.down = function (options, callback) { -// throw new Error('Not implemented.') -// } diff --git a/server/initializers/migrator.js b/server/initializers/migrator.js index e5288b615..233ee2bdd 100644 --- a/server/initializers/migrator.js +++ b/server/initializers/migrator.js @@ -64,7 +64,7 @@ function getMigrationScripts (callback) { } function executeMigration (actualVersion, entity, callback) { - const versionScript = entity.version + const versionScript = parseInt(entity.version) // Do not execute old migration scripts if (versionScript <= actualVersion) return callback(null) @@ -78,7 +78,12 @@ function executeMigration (actualVersion, entity, callback) { db.sequelize.transaction().asCallback(function (err, t) { if (err) return callback(err) - migrationScript.up({ transaction: t }, function (err) { + const options = { + transaction: t, + queryInterface: db.sequelize.getQueryInterface(), + Sequelize: db.Sequelize + } + migrationScript.up(options, function (err) { if (err) { t.rollback() return callback(err) diff --git a/server/lib/friends.js b/server/lib/friends.js index 2ea837c99..9b38693c7 100644 --- a/server/lib/friends.js +++ b/server/lib/friends.js @@ -245,6 +245,7 @@ function makeRequestsToWinningPods (cert, podsList, callback) { method: 'POST', json: { host: constants.CONFIG.WEBSERVER.HOST, + email: constants.CONFIG.ADMIN.EMAIL, publicKey: cert } } @@ -257,7 +258,7 @@ function makeRequestsToWinningPods (cert, podsList, callback) { } if (res.statusCode === 200) { - const podObj = db.Pod.build({ host: pod.host, publicKey: body.cert }) + const podObj = db.Pod.build({ host: pod.host, publicKey: body.cert, email: body.email }) podObj.save().asCallback(function (err, podCreated) { if (err) { logger.error('Cannot add friend %s pod.', pod.host, { error: err }) diff --git a/server/middlewares/validators/pods.js b/server/middlewares/validators/pods.js index b9b30e7a1..0bf4b1844 100644 --- a/server/middlewares/validators/pods.js +++ b/server/middlewares/validators/pods.js @@ -40,7 +40,8 @@ function makeFriends (req, res, next) { } function podsAdd (req, res, next) { - req.checkBody('host', 'Should have an host').isHostValid() + req.checkBody('host', 'Should have a host').isHostValid() + req.checkBody('email', 'Should have an email').isEmail() req.checkBody('publicKey', 'Should have a public key').notEmpty() logger.debug('Checking podsAdd parameters', { parameters: req.body }) diff --git a/server/models/pod.js b/server/models/pod.js index b3c6db8e8..6ae4b0999 100644 --- a/server/models/pod.js +++ b/server/models/pod.js @@ -32,6 +32,10 @@ module.exports = function (sequelize, DataTypes) { isInt: true, max: constants.FRIEND_SCORE.MAX } + }, + email: { + type: DataTypes.STRING(400), + allowNull: false } }, { @@ -71,6 +75,7 @@ function toFormatedJSON () { const json = { id: this.id, host: this.host, + email: this.email, score: this.score, createdAt: this.createdAt } diff --git a/server/tests/api/friends-basic.js b/server/tests/api/friends-basic.js index 6f37ff291..62c40df7b 100644 --- a/server/tests/api/friends-basic.js +++ b/server/tests/api/friends-basic.js @@ -96,6 +96,7 @@ describe('Test basic friends', function () { const pod = result[0] expect(pod.host).to.equal(servers[2].host) + expect(pod.email).to.equal('admin3@example.com') expect(pod.score).to.equal(20) expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true @@ -113,6 +114,7 @@ describe('Test basic friends', function () { const pod = result[0] expect(pod.host).to.equal(servers[1].host) + expect(pod.email).to.equal('admin2@example.com') expect(pod.score).to.equal(20) expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true -- cgit v1.2.3