Add email to pods

This commit is contained in:
Chocobozzz 2017-02-16 19:19:56 +01:00
parent 3266ad7cf8
commit 4793c343fd
20 changed files with 75 additions and 21 deletions

View File

@ -35,6 +35,10 @@ export class FriendListComponent {
title: 'Host', title: 'Host',
sort: false sort: false
}, },
email: {
title: 'Email',
sort: false
},
score: { score: {
title: 'Score', title: 'Score',
sort: false sort: false

View File

@ -2,5 +2,6 @@ export interface Friend {
id: string; id: string;
host: string; host: string;
score: number; score: number;
email: string;
createdAt: Date; createdAt: Date;
} }

View File

@ -22,3 +22,6 @@ storage:
previews: 'previews/' previews: 'previews/'
thumbnails: 'thumbnails/' thumbnails: 'thumbnails/'
torrents: 'torrents/' torrents: 'torrents/'
admin:
email: 'admin@example.com'

View File

@ -23,3 +23,6 @@ storage:
previews: 'previews/' previews: 'previews/'
thumbnails: 'thumbnails/' thumbnails: 'thumbnails/'
torrents: 'torrents/' torrents: 'torrents/'
admin:
email: 'admin@example.com'

View File

@ -15,3 +15,6 @@ storage:
logs: 'test1/logs/' logs: 'test1/logs/'
thumbnails: 'test1/thumbnails/' thumbnails: 'test1/thumbnails/'
torrents: 'test1/torrents/' torrents: 'test1/torrents/'
admin:
email: 'admin1@example.com'

View File

@ -15,3 +15,6 @@ storage:
logs: 'test2/logs/' logs: 'test2/logs/'
thumbnails: 'test2/thumbnails/' thumbnails: 'test2/thumbnails/'
torrents: 'test2/torrents/' torrents: 'test2/torrents/'
admin:
email: 'admin2@example.com'

View File

@ -15,3 +15,6 @@ storage:
logs: 'test3/logs/' logs: 'test3/logs/'
thumbnails: 'test3/thumbnails/' thumbnails: 'test3/thumbnails/'
torrents: 'test3/torrents/' torrents: 'test3/torrents/'
admin:
email: 'admin3@example.com'

View File

@ -15,3 +15,6 @@ storage:
logs: 'test4/logs/' logs: 'test4/logs/'
thumbnails: 'test4/thumbnails/' thumbnails: 'test4/thumbnails/'
torrents: 'test4/torrents/' torrents: 'test4/torrents/'
admin:
email: 'admin4@example.com'

View File

@ -15,3 +15,6 @@ storage:
logs: 'test5/logs/' logs: 'test5/logs/'
thumbnails: 'test5/thumbnails/' thumbnails: 'test5/thumbnails/'
torrents: 'test5/torrents/' torrents: 'test5/torrents/'
admin:
email: 'admin5@example.com'

View File

@ -15,3 +15,6 @@ storage:
logs: 'test6/logs/' logs: 'test6/logs/'
thumbnails: 'test6/thumbnails/' thumbnails: 'test6/thumbnails/'
torrents: 'test6/torrents/' torrents: 'test6/torrents/'
admin:
email: 'admin6@example.com'

View File

@ -4,6 +4,7 @@ const express = require('express')
const waterfall = require('async/waterfall') const waterfall = require('async/waterfall')
const db = require('../../initializers/database') const db = require('../../initializers/database')
const constants = require('../../initializers/constants')
const logger = require('../../helpers/logger') const logger = require('../../helpers/logger')
const peertubeCrypto = require('../../helpers/peertube-crypto') const peertubeCrypto = require('../../helpers/peertube-crypto')
const utils = require('../../helpers/utils') const utils = require('../../helpers/utils')
@ -80,7 +81,7 @@ function addPods (req, res, next) {
], function (err, cert) { ], function (err, cert) {
if (err) return next(err) if (err) return next(err)
return res.json({ cert: cert }) return res.json({ cert: cert, email: constants.CONFIG.ADMIN.EMAIL })
}) })
} }

View File

@ -28,7 +28,8 @@ function checkMissedConfig () {
const required = [ 'listen.port', const required = [ 'listen.port',
'webserver.https', 'webserver.hostname', 'webserver.port', 'webserver.https', 'webserver.hostname', 'webserver.port',
'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', '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 = [] const miss = []

View File

@ -54,6 +54,9 @@ const CONFIG = {
WS: config.get('webserver.https') === true ? 'wss' : 'ws', WS: config.get('webserver.https') === true ? 'wss' : 'ws',
HOSTNAME: config.get('webserver.hostname'), HOSTNAME: config.get('webserver.hostname'),
PORT: config.get('webserver.port') PORT: config.get('webserver.port')
},
ADMIN: {
EMAIL: config.get('admin.email')
} }
} }
CONFIG.WEBSERVER.URL = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT 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
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -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.')
}

View File

@ -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.')
// }

View File

@ -64,7 +64,7 @@ function getMigrationScripts (callback) {
} }
function executeMigration (actualVersion, entity, callback) { function executeMigration (actualVersion, entity, callback) {
const versionScript = entity.version const versionScript = parseInt(entity.version)
// Do not execute old migration scripts // Do not execute old migration scripts
if (versionScript <= actualVersion) return callback(null) if (versionScript <= actualVersion) return callback(null)
@ -78,7 +78,12 @@ function executeMigration (actualVersion, entity, callback) {
db.sequelize.transaction().asCallback(function (err, t) { db.sequelize.transaction().asCallback(function (err, t) {
if (err) return callback(err) 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) { if (err) {
t.rollback() t.rollback()
return callback(err) return callback(err)

View File

@ -245,6 +245,7 @@ function makeRequestsToWinningPods (cert, podsList, callback) {
method: 'POST', method: 'POST',
json: { json: {
host: constants.CONFIG.WEBSERVER.HOST, host: constants.CONFIG.WEBSERVER.HOST,
email: constants.CONFIG.ADMIN.EMAIL,
publicKey: cert publicKey: cert
} }
} }
@ -257,7 +258,7 @@ function makeRequestsToWinningPods (cert, podsList, callback) {
} }
if (res.statusCode === 200) { 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) { podObj.save().asCallback(function (err, podCreated) {
if (err) { if (err) {
logger.error('Cannot add friend %s pod.', pod.host, { error: err }) logger.error('Cannot add friend %s pod.', pod.host, { error: err })

View File

@ -40,7 +40,8 @@ function makeFriends (req, res, next) {
} }
function podsAdd (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() req.checkBody('publicKey', 'Should have a public key').notEmpty()
logger.debug('Checking podsAdd parameters', { parameters: req.body }) logger.debug('Checking podsAdd parameters', { parameters: req.body })

View File

@ -32,6 +32,10 @@ module.exports = function (sequelize, DataTypes) {
isInt: true, isInt: true,
max: constants.FRIEND_SCORE.MAX max: constants.FRIEND_SCORE.MAX
} }
},
email: {
type: DataTypes.STRING(400),
allowNull: false
} }
}, },
{ {
@ -71,6 +75,7 @@ function toFormatedJSON () {
const json = { const json = {
id: this.id, id: this.id,
host: this.host, host: this.host,
email: this.email,
score: this.score, score: this.score,
createdAt: this.createdAt createdAt: this.createdAt
} }

View File

@ -96,6 +96,7 @@ describe('Test basic friends', function () {
const pod = result[0] const pod = result[0]
expect(pod.host).to.equal(servers[2].host) expect(pod.host).to.equal(servers[2].host)
expect(pod.email).to.equal('admin3@example.com')
expect(pod.score).to.equal(20) expect(pod.score).to.equal(20)
expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true
@ -113,6 +114,7 @@ describe('Test basic friends', function () {
const pod = result[0] const pod = result[0]
expect(pod.host).to.equal(servers[1].host) expect(pod.host).to.equal(servers[1].host)
expect(pod.email).to.equal('admin2@example.com')
expect(pod.score).to.equal(20) expect(pod.score).to.equal(20)
expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true