aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/constants.ts13
-rw-r--r--server/initializers/installer.ts5
-rw-r--r--server/initializers/migrations/0085-user-role.ts39
3 files changed, 43 insertions, 14 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 1581a3195..6dc9737d2 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -5,7 +5,6 @@ import { join } from 'path'
5import { root, isTestInstance } from '../helpers/core-utils' 5import { root, isTestInstance } from '../helpers/core-utils'
6 6
7import { 7import {
8 UserRole,
9 VideoRateType, 8 VideoRateType,
10 RequestEndpoint, 9 RequestEndpoint,
11 RequestVideoEventType, 10 RequestVideoEventType,
@@ -16,7 +15,7 @@ import {
16 15
17// --------------------------------------------------------------------------- 16// ---------------------------------------------------------------------------
18 17
19const LAST_MIGRATION_VERSION = 80 18const LAST_MIGRATION_VERSION = 85
20 19
21// --------------------------------------------------------------------------- 20// ---------------------------------------------------------------------------
22 21
@@ -283,7 +282,6 @@ const JOB_STATES: { [ id: string ]: JobState } = {
283} 282}
284// How many maximum jobs we fetch from the database per cycle 283// How many maximum jobs we fetch from the database per cycle
285const JOBS_FETCH_LIMIT_PER_CYCLE = 10 284const JOBS_FETCH_LIMIT_PER_CYCLE = 10
286const JOBS_CONCURRENCY = 1
287// 1 minutes 285// 1 minutes
288let JOBS_FETCHING_INTERVAL = 60000 286let JOBS_FETCHING_INTERVAL = 60000
289 287
@@ -334,13 +332,6 @@ const CACHE = {
334 332
335// --------------------------------------------------------------------------- 333// ---------------------------------------------------------------------------
336 334
337const USER_ROLES: { [ id: string ]: UserRole } = {
338 ADMIN: 'admin',
339 USER: 'user'
340}
341
342// ---------------------------------------------------------------------------
343
344const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->' 335const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->'
345 336
346// --------------------------------------------------------------------------- 337// ---------------------------------------------------------------------------
@@ -367,7 +358,6 @@ export {
367 EMBED_SIZE, 358 EMBED_SIZE,
368 FRIEND_SCORE, 359 FRIEND_SCORE,
369 JOB_STATES, 360 JOB_STATES,
370 JOBS_CONCURRENCY,
371 JOBS_FETCH_LIMIT_PER_CYCLE, 361 JOBS_FETCH_LIMIT_PER_CYCLE,
372 JOBS_FETCHING_INTERVAL, 362 JOBS_FETCHING_INTERVAL,
373 LAST_MIGRATION_VERSION, 363 LAST_MIGRATION_VERSION,
@@ -401,7 +391,6 @@ export {
401 STATIC_MAX_AGE, 391 STATIC_MAX_AGE,
402 STATIC_PATHS, 392 STATIC_PATHS,
403 THUMBNAILS_SIZE, 393 THUMBNAILS_SIZE,
404 USER_ROLES,
405 VIDEO_CATEGORIES, 394 VIDEO_CATEGORIES,
406 VIDEO_LANGUAGES, 395 VIDEO_LANGUAGES,
407 VIDEO_LICENCES, 396 VIDEO_LICENCES,
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts
index 4c04290fc..077472341 100644
--- a/server/initializers/installer.ts
+++ b/server/initializers/installer.ts
@@ -2,10 +2,11 @@ import * as passwordGenerator from 'password-generator'
2import * as Bluebird from 'bluebird' 2import * as Bluebird from 'bluebird'
3 3
4import { database as db } from './database' 4import { database as db } from './database'
5import { USER_ROLES, CONFIG, LAST_MIGRATION_VERSION, CACHE } from './constants' 5import { CONFIG, LAST_MIGRATION_VERSION, CACHE } from './constants'
6import { clientsExist, usersExist } from './checker' 6import { clientsExist, usersExist } from './checker'
7import { logger, createCertsIfNotExist, mkdirpPromise, rimrafPromise } from '../helpers' 7import { logger, createCertsIfNotExist, mkdirpPromise, rimrafPromise } from '../helpers'
8import { createUserAuthorAndChannel } from '../lib' 8import { createUserAuthorAndChannel } from '../lib'
9import { UserRole } from '../../shared'
9 10
10async function installApplication () { 11async function installApplication () {
11 await db.sequelize.sync() 12 await db.sequelize.sync()
@@ -88,7 +89,7 @@ async function createOAuthAdminIfNotExist () {
88 logger.info('Creating the administrator.') 89 logger.info('Creating the administrator.')
89 90
90 const username = 'root' 91 const username = 'root'
91 const role = USER_ROLES.ADMIN 92 const role = UserRole.ADMINISTRATOR
92 const email = CONFIG.ADMIN.EMAIL 93 const email = CONFIG.ADMIN.EMAIL
93 let validatePassword = true 94 let validatePassword = true
94 let password = '' 95 let password = ''
diff --git a/server/initializers/migrations/0085-user-role.ts b/server/initializers/migrations/0085-user-role.ts
new file mode 100644
index 000000000..e67c5ca24
--- /dev/null
+++ b/server/initializers/migrations/0085-user-role.ts
@@ -0,0 +1,39 @@
1import * as Sequelize from 'sequelize'
2import * as uuidv4 from 'uuid/v4'
3
4async function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize,
8 db: any
9}): Promise<void> {
10 const q = utils.queryInterface
11
12 await q.renameColumn('Users', 'role', 'oldRole')
13
14 const data = {
15 type: Sequelize.INTEGER,
16 allowNull: true
17 }
18 await q.addColumn('Users', 'role', data)
19
20 let query = 'UPDATE "Users" SET "role" = 0 WHERE "oldRole" = \'admin\''
21 await utils.sequelize.query(query)
22
23 query = 'UPDATE "Users" SET "role" = 2 WHERE "oldRole" = \'user\''
24 await utils.sequelize.query(query)
25
26 data.allowNull = false
27 await q.changeColumn('Users', 'role', data)
28
29 await q.removeColumn('Users', 'oldRole')
30}
31
32function down (options) {
33 throw new Error('Not implemented.')
34}
35
36export {
37 up,
38 down
39}