diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-02-16 19:19:56 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-02-16 19:19:56 +0100 |
commit | 4793c343fd3cde3c6282ed0fb38e039b4276de0e (patch) | |
tree | 566856a8d0bee0ee06e60c5e3bf6b998135a078a /server | |
parent | 3266ad7cf8ff10d0fdae456196eff1653cc7ac21 (diff) | |
download | PeerTube-4793c343fd3cde3c6282ed0fb38e039b4276de0e.tar.gz PeerTube-4793c343fd3cde3c6282ed0fb38e039b4276de0e.tar.zst PeerTube-4793c343fd3cde3c6282ed0fb38e039b4276de0e.zip |
Add email to pods
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/pods.js | 3 | ||||
-rw-r--r-- | server/initializers/checker.js | 3 | ||||
-rw-r--r-- | server/initializers/constants.js | 5 | ||||
-rw-r--r-- | server/initializers/migrations/0005-email-pod.js | 20 | ||||
-rw-r--r-- | server/initializers/migrations/0005-example.js | 14 | ||||
-rw-r--r-- | server/initializers/migrator.js | 9 | ||||
-rw-r--r-- | server/lib/friends.js | 3 | ||||
-rw-r--r-- | server/middlewares/validators/pods.js | 3 | ||||
-rw-r--r-- | server/models/pod.js | 5 | ||||
-rw-r--r-- | server/tests/api/friends-basic.js | 2 |
10 files changed, 46 insertions, 21 deletions
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') | |||
4 | const waterfall = require('async/waterfall') | 4 | const waterfall = require('async/waterfall') |
5 | 5 | ||
6 | const db = require('../../initializers/database') | 6 | const db = require('../../initializers/database') |
7 | const constants = require('../../initializers/constants') | ||
7 | const logger = require('../../helpers/logger') | 8 | const logger = require('../../helpers/logger') |
8 | const peertubeCrypto = require('../../helpers/peertube-crypto') | 9 | const peertubeCrypto = require('../../helpers/peertube-crypto') |
9 | const utils = require('../../helpers/utils') | 10 | const utils = require('../../helpers/utils') |
@@ -80,7 +81,7 @@ function addPods (req, res, next) { | |||
80 | ], function (err, cert) { | 81 | ], function (err, cert) { |
81 | if (err) return next(err) | 82 | if (err) return next(err) |
82 | 83 | ||
83 | return res.json({ cert: cert }) | 84 | return res.json({ cert: cert, email: constants.CONFIG.ADMIN.EMAIL }) |
84 | }) | 85 | }) |
85 | } | 86 | } |
86 | 87 | ||
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 () { | |||
28 | const required = [ 'listen.port', | 28 | const required = [ 'listen.port', |
29 | 'webserver.https', 'webserver.hostname', 'webserver.port', | 29 | 'webserver.https', 'webserver.hostname', 'webserver.port', |
30 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', | 30 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', |
31 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews' | 31 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', |
32 | 'admin.email' | ||
32 | ] | 33 | ] |
33 | const miss = [] | 34 | const miss = [] |
34 | 35 | ||
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 = { | |||
54 | WS: config.get('webserver.https') === true ? 'wss' : 'ws', | 54 | WS: config.get('webserver.https') === true ? 'wss' : 'ws', |
55 | HOSTNAME: config.get('webserver.hostname'), | 55 | HOSTNAME: config.get('webserver.hostname'), |
56 | PORT: config.get('webserver.port') | 56 | PORT: config.get('webserver.port') |
57 | }, | ||
58 | ADMIN: { | ||
59 | EMAIL: config.get('admin.email') | ||
57 | } | 60 | } |
58 | } | 61 | } |
59 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT | 62 | CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT |
@@ -92,7 +95,7 @@ const FRIEND_SCORE = { | |||
92 | 95 | ||
93 | // --------------------------------------------------------------------------- | 96 | // --------------------------------------------------------------------------- |
94 | 97 | ||
95 | const LAST_MIGRATION_VERSION = 0 | 98 | const LAST_MIGRATION_VERSION = 5 |
96 | 99 | ||
97 | // --------------------------------------------------------------------------- | 100 | // --------------------------------------------------------------------------- |
98 | 101 | ||
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 @@ | |||
1 | /* | ||
2 | This is just an example. | ||
3 | */ | ||
4 | |||
5 | // utils = { transaction, queryInterface } | ||
6 | exports.up = function (utils, callback) { | ||
7 | const q = utils.queryInterface | ||
8 | const Sequelize = utils.Sequelize | ||
9 | |||
10 | const data = { | ||
11 | type: Sequelize.STRING(400), | ||
12 | allowNull: false | ||
13 | } | ||
14 | |||
15 | q.addColumn('Pods', 'email', data, { transaction: utils.transaction }).asCallback(callback) | ||
16 | } | ||
17 | |||
18 | exports.down = function (options, callback) { | ||
19 | throw new Error('Not implemented.') | ||
20 | } | ||
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 @@ | |||
1 | // /* | ||
2 | // This is just an example. | ||
3 | // */ | ||
4 | |||
5 | // const db = require('../database') | ||
6 | |||
7 | // // options contains the transaction | ||
8 | // exports.up = function (options, callback) { | ||
9 | // db.Application.create({ migrationVersion: 42 }, { transaction: options.transaction }).asCallback(callback) | ||
10 | // } | ||
11 | |||
12 | // exports.down = function (options, callback) { | ||
13 | // throw new Error('Not implemented.') | ||
14 | // } | ||
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) { | |||
64 | } | 64 | } |
65 | 65 | ||
66 | function executeMigration (actualVersion, entity, callback) { | 66 | function executeMigration (actualVersion, entity, callback) { |
67 | const versionScript = entity.version | 67 | const versionScript = parseInt(entity.version) |
68 | 68 | ||
69 | // Do not execute old migration scripts | 69 | // Do not execute old migration scripts |
70 | if (versionScript <= actualVersion) return callback(null) | 70 | if (versionScript <= actualVersion) return callback(null) |
@@ -78,7 +78,12 @@ function executeMigration (actualVersion, entity, callback) { | |||
78 | db.sequelize.transaction().asCallback(function (err, t) { | 78 | db.sequelize.transaction().asCallback(function (err, t) { |
79 | if (err) return callback(err) | 79 | if (err) return callback(err) |
80 | 80 | ||
81 | migrationScript.up({ transaction: t }, function (err) { | 81 | const options = { |
82 | transaction: t, | ||
83 | queryInterface: db.sequelize.getQueryInterface(), | ||
84 | Sequelize: db.Sequelize | ||
85 | } | ||
86 | migrationScript.up(options, function (err) { | ||
82 | if (err) { | 87 | if (err) { |
83 | t.rollback() | 88 | t.rollback() |
84 | return callback(err) | 89 | 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) { | |||
245 | method: 'POST', | 245 | method: 'POST', |
246 | json: { | 246 | json: { |
247 | host: constants.CONFIG.WEBSERVER.HOST, | 247 | host: constants.CONFIG.WEBSERVER.HOST, |
248 | email: constants.CONFIG.ADMIN.EMAIL, | ||
248 | publicKey: cert | 249 | publicKey: cert |
249 | } | 250 | } |
250 | } | 251 | } |
@@ -257,7 +258,7 @@ function makeRequestsToWinningPods (cert, podsList, callback) { | |||
257 | } | 258 | } |
258 | 259 | ||
259 | if (res.statusCode === 200) { | 260 | if (res.statusCode === 200) { |
260 | const podObj = db.Pod.build({ host: pod.host, publicKey: body.cert }) | 261 | const podObj = db.Pod.build({ host: pod.host, publicKey: body.cert, email: body.email }) |
261 | podObj.save().asCallback(function (err, podCreated) { | 262 | podObj.save().asCallback(function (err, podCreated) { |
262 | if (err) { | 263 | if (err) { |
263 | logger.error('Cannot add friend %s pod.', pod.host, { error: err }) | 264 | 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) { | |||
40 | } | 40 | } |
41 | 41 | ||
42 | function podsAdd (req, res, next) { | 42 | function podsAdd (req, res, next) { |
43 | req.checkBody('host', 'Should have an host').isHostValid() | 43 | req.checkBody('host', 'Should have a host').isHostValid() |
44 | req.checkBody('email', 'Should have an email').isEmail() | ||
44 | req.checkBody('publicKey', 'Should have a public key').notEmpty() | 45 | req.checkBody('publicKey', 'Should have a public key').notEmpty() |
45 | logger.debug('Checking podsAdd parameters', { parameters: req.body }) | 46 | logger.debug('Checking podsAdd parameters', { parameters: req.body }) |
46 | 47 | ||
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) { | |||
32 | isInt: true, | 32 | isInt: true, |
33 | max: constants.FRIEND_SCORE.MAX | 33 | max: constants.FRIEND_SCORE.MAX |
34 | } | 34 | } |
35 | }, | ||
36 | email: { | ||
37 | type: DataTypes.STRING(400), | ||
38 | allowNull: false | ||
35 | } | 39 | } |
36 | }, | 40 | }, |
37 | { | 41 | { |
@@ -71,6 +75,7 @@ function toFormatedJSON () { | |||
71 | const json = { | 75 | const json = { |
72 | id: this.id, | 76 | id: this.id, |
73 | host: this.host, | 77 | host: this.host, |
78 | email: this.email, | ||
74 | score: this.score, | 79 | score: this.score, |
75 | createdAt: this.createdAt | 80 | createdAt: this.createdAt |
76 | } | 81 | } |
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 () { | |||
96 | 96 | ||
97 | const pod = result[0] | 97 | const pod = result[0] |
98 | expect(pod.host).to.equal(servers[2].host) | 98 | expect(pod.host).to.equal(servers[2].host) |
99 | expect(pod.email).to.equal('admin3@example.com') | ||
99 | expect(pod.score).to.equal(20) | 100 | expect(pod.score).to.equal(20) |
100 | expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true | 101 | expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true |
101 | 102 | ||
@@ -113,6 +114,7 @@ describe('Test basic friends', function () { | |||
113 | 114 | ||
114 | const pod = result[0] | 115 | const pod = result[0] |
115 | expect(pod.host).to.equal(servers[1].host) | 116 | expect(pod.host).to.equal(servers[1].host) |
117 | expect(pod.email).to.equal('admin2@example.com') | ||
116 | expect(pod.score).to.equal(20) | 118 | expect(pod.score).to.equal(20) |
117 | expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true | 119 | expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true |
118 | 120 | ||