diff options
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/constants.ts | 13 | ||||
-rw-r--r-- | server/initializers/installer.ts | 5 | ||||
-rw-r--r-- | server/initializers/migrations/0085-user-role.ts | 39 |
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' | |||
5 | import { root, isTestInstance } from '../helpers/core-utils' | 5 | import { root, isTestInstance } from '../helpers/core-utils' |
6 | 6 | ||
7 | import { | 7 | import { |
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 | ||
19 | const LAST_MIGRATION_VERSION = 80 | 18 | const 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 |
285 | const JOBS_FETCH_LIMIT_PER_CYCLE = 10 | 284 | const JOBS_FETCH_LIMIT_PER_CYCLE = 10 |
286 | const JOBS_CONCURRENCY = 1 | ||
287 | // 1 minutes | 285 | // 1 minutes |
288 | let JOBS_FETCHING_INTERVAL = 60000 | 286 | let JOBS_FETCHING_INTERVAL = 60000 |
289 | 287 | ||
@@ -334,13 +332,6 @@ const CACHE = { | |||
334 | 332 | ||
335 | // --------------------------------------------------------------------------- | 333 | // --------------------------------------------------------------------------- |
336 | 334 | ||
337 | const USER_ROLES: { [ id: string ]: UserRole } = { | ||
338 | ADMIN: 'admin', | ||
339 | USER: 'user' | ||
340 | } | ||
341 | |||
342 | // --------------------------------------------------------------------------- | ||
343 | |||
344 | const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->' | 335 | const 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' | |||
2 | import * as Bluebird from 'bluebird' | 2 | import * as Bluebird from 'bluebird' |
3 | 3 | ||
4 | import { database as db } from './database' | 4 | import { database as db } from './database' |
5 | import { USER_ROLES, CONFIG, LAST_MIGRATION_VERSION, CACHE } from './constants' | 5 | import { CONFIG, LAST_MIGRATION_VERSION, CACHE } from './constants' |
6 | import { clientsExist, usersExist } from './checker' | 6 | import { clientsExist, usersExist } from './checker' |
7 | import { logger, createCertsIfNotExist, mkdirpPromise, rimrafPromise } from '../helpers' | 7 | import { logger, createCertsIfNotExist, mkdirpPromise, rimrafPromise } from '../helpers' |
8 | import { createUserAuthorAndChannel } from '../lib' | 8 | import { createUserAuthorAndChannel } from '../lib' |
9 | import { UserRole } from '../../shared' | ||
9 | 10 | ||
10 | async function installApplication () { | 11 | async 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 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import * as uuidv4 from 'uuid/v4' | ||
3 | |||
4 | async 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 | |||
32 | function down (options) { | ||
33 | throw new Error('Not implemented.') | ||
34 | } | ||
35 | |||
36 | export { | ||
37 | up, | ||
38 | down | ||
39 | } | ||