aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/users/me.ts1
-rw-r--r--server/helpers/custom-validators/users.ts9
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/initializers/migrations/0665-no-account-warning-modal.ts27
-rw-r--r--server/middlewares/validators/users.ts12
-rw-r--r--server/models/user/user.ts19
-rw-r--r--server/tests/api/check-params/users.ts27
-rw-r--r--server/tests/api/users/users.ts5
8 files changed, 71 insertions, 31 deletions
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index ac6faca9c..a98d79218 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -203,6 +203,7 @@ async function updateMe (req: express.Request, res: express.Response) {
203 'videoLanguages', 203 'videoLanguages',
204 'theme', 204 'theme',
205 'noInstanceConfigWarningModal', 205 'noInstanceConfigWarningModal',
206 'noAccountSetupWarningModal',
206 'noWelcomeModal' 207 'noWelcomeModal'
207 ] 208 ]
208 209
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts
index 5b21c3529..f52c60b60 100644
--- a/server/helpers/custom-validators/users.ts
+++ b/server/helpers/custom-validators/users.ts
@@ -81,11 +81,7 @@ function isUserAutoPlayNextVideoPlaylistValid (value: any) {
81 return isBooleanValid(value) 81 return isBooleanValid(value)
82} 82}
83 83
84function isNoInstanceConfigWarningModal (value: any) { 84function isUserNoModal (value: any) {
85 return isBooleanValid(value)
86}
87
88function isNoWelcomeModal (value: any) {
89 return isBooleanValid(value) 85 return isBooleanValid(value)
90} 86}
91 87
@@ -119,6 +115,5 @@ export {
119 isUserAutoPlayNextVideoPlaylistValid, 115 isUserAutoPlayNextVideoPlaylistValid,
120 isUserDisplayNameValid, 116 isUserDisplayNameValid,
121 isUserDescriptionValid, 117 isUserDescriptionValid,
122 isNoInstanceConfigWarningModal, 118 isUserNoModal
123 isNoWelcomeModal
124} 119}
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 8a1526ae8..2d8087f46 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -24,7 +24,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
24 24
25// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
26 26
27const LAST_MIGRATION_VERSION = 660 27const LAST_MIGRATION_VERSION = 665
28 28
29// --------------------------------------------------------------------------- 29// ---------------------------------------------------------------------------
30 30
diff --git a/server/initializers/migrations/0665-no-account-warning-modal.ts b/server/initializers/migrations/0665-no-account-warning-modal.ts
new file mode 100644
index 000000000..6718aed85
--- /dev/null
+++ b/server/initializers/migrations/0665-no-account-warning-modal.ts
@@ -0,0 +1,27 @@
1import * as Sequelize from 'sequelize'
2
3async function up (utils: {
4 transaction: Sequelize.Transaction
5 queryInterface: Sequelize.QueryInterface
6 sequelize: Sequelize.Sequelize
7 db: any
8}): Promise<void> {
9 {
10 const data = {
11 type: Sequelize.BOOLEAN,
12 allowNull: false,
13 defaultValue: false
14 }
15
16 await utils.queryInterface.addColumn('user', 'noAccountSetupWarningModal', data)
17 }
18}
19
20function down (options) {
21 throw new Error('Not implemented.')
22}
23
24export {
25 up,
26 down
27}
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index bc8607523..c6977fcd9 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -9,14 +9,13 @@ import { UserRegister } from '../../../shared/models/users/user-register.model'
9import { toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' 9import { toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
10import { isThemeNameValid } from '../../helpers/custom-validators/plugins' 10import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
11import { 11import {
12 isNoInstanceConfigWarningModal,
13 isNoWelcomeModal,
14 isUserAdminFlagsValid, 12 isUserAdminFlagsValid,
15 isUserAutoPlayNextVideoValid, 13 isUserAutoPlayNextVideoValid,
16 isUserAutoPlayVideoValid, 14 isUserAutoPlayVideoValid,
17 isUserBlockedReasonValid, 15 isUserBlockedReasonValid,
18 isUserDescriptionValid, 16 isUserDescriptionValid,
19 isUserDisplayNameValid, 17 isUserDisplayNameValid,
18 isUserNoModal,
20 isUserNSFWPolicyValid, 19 isUserNSFWPolicyValid,
21 isUserPasswordValid, 20 isUserPasswordValid,
22 isUserPasswordValidOrEmpty, 21 isUserPasswordValidOrEmpty,
@@ -251,12 +250,17 @@ const usersUpdateMeValidator = [
251 body('theme') 250 body('theme')
252 .optional() 251 .optional()
253 .custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'), 252 .custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'),
253
254 body('noInstanceConfigWarningModal') 254 body('noInstanceConfigWarningModal')
255 .optional() 255 .optional()
256 .custom(v => isNoInstanceConfigWarningModal(v)).withMessage('Should have a valid noInstanceConfigWarningModal boolean'), 256 .custom(v => isUserNoModal(v)).withMessage('Should have a valid noInstanceConfigWarningModal boolean'),
257 body('noWelcomeModal') 257 body('noWelcomeModal')
258 .optional() 258 .optional()
259 .custom(v => isNoWelcomeModal(v)).withMessage('Should have a valid noWelcomeModal boolean'), 259 .custom(v => isUserNoModal(v)).withMessage('Should have a valid noWelcomeModal boolean'),
260 body('noAccountSetupWarningModal')
261 .optional()
262 .custom(v => isUserNoModal(v)).withMessage('Should have a valid noAccountSetupWarningModal boolean'),
263
260 body('autoPlayNextVideo') 264 body('autoPlayNextVideo')
261 .optional() 265 .optional()
262 .custom(v => isUserAutoPlayNextVideoValid(v)).withMessage('Should have a valid autoPlayNextVideo boolean'), 266 .custom(v => isUserAutoPlayNextVideoValid(v)).withMessage('Should have a valid autoPlayNextVideo boolean'),
diff --git a/server/models/user/user.ts b/server/models/user/user.ts
index 069d7266e..ddce455a1 100644
--- a/server/models/user/user.ts
+++ b/server/models/user/user.ts
@@ -39,8 +39,6 @@ import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
39import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type' 39import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'
40import { isThemeNameValid } from '../../helpers/custom-validators/plugins' 40import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
41import { 41import {
42 isNoInstanceConfigWarningModal,
43 isNoWelcomeModal,
44 isUserAdminFlagsValid, 42 isUserAdminFlagsValid,
45 isUserAutoPlayNextVideoPlaylistValid, 43 isUserAutoPlayNextVideoPlaylistValid,
46 isUserAutoPlayNextVideoValid, 44 isUserAutoPlayNextVideoValid,
@@ -48,6 +46,7 @@ import {
48 isUserBlockedReasonValid, 46 isUserBlockedReasonValid,
49 isUserBlockedValid, 47 isUserBlockedValid,
50 isUserEmailVerifiedValid, 48 isUserEmailVerifiedValid,
49 isUserNoModal,
51 isUserNSFWPolicyValid, 50 isUserNSFWPolicyValid,
52 isUserPasswordValid, 51 isUserPasswordValid,
53 isUserRoleValid, 52 isUserRoleValid,
@@ -349,7 +348,7 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
349 @Default(false) 348 @Default(false)
350 @Is( 349 @Is(
351 'UserNoInstanceConfigWarningModal', 350 'UserNoInstanceConfigWarningModal',
352 value => throwIfNotValid(value, isNoInstanceConfigWarningModal, 'no instance config warning modal') 351 value => throwIfNotValid(value, isUserNoModal, 'no instance config warning modal')
353 ) 352 )
354 @Column 353 @Column
355 noInstanceConfigWarningModal: boolean 354 noInstanceConfigWarningModal: boolean
@@ -357,12 +356,21 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
357 @AllowNull(false) 356 @AllowNull(false)
358 @Default(false) 357 @Default(false)
359 @Is( 358 @Is(
360 'UserNoInstanceConfigWarningModal', 359 'UserNoWelcomeModal',
361 value => throwIfNotValid(value, isNoWelcomeModal, 'no welcome modal') 360 value => throwIfNotValid(value, isUserNoModal, 'no welcome modal')
362 ) 361 )
363 @Column 362 @Column
364 noWelcomeModal: boolean 363 noWelcomeModal: boolean
365 364
365 @AllowNull(false)
366 @Default(false)
367 @Is(
368 'UserNoAccountSetupWarningModal',
369 value => throwIfNotValid(value, isUserNoModal, 'no account setup warning modal')
370 )
371 @Column
372 noAccountSetupWarningModal: boolean
373
366 @AllowNull(true) 374 @AllowNull(true)
367 @Default(null) 375 @Default(null)
368 @Column 376 @Column
@@ -920,6 +928,7 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
920 928
921 noInstanceConfigWarningModal: this.noInstanceConfigWarningModal, 929 noInstanceConfigWarningModal: this.noInstanceConfigWarningModal,
922 noWelcomeModal: this.noWelcomeModal, 930 noWelcomeModal: this.noWelcomeModal,
931 noAccountSetupWarningModal: this.noAccountSetupWarningModal,
923 932
924 blocked: this.blocked, 933 blocked: this.blocked,
925 blockedReason: this.blockedReason, 934 blockedReason: this.blockedReason,
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 9d8f933db..58b360f92 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -491,20 +491,20 @@ describe('Test users API validators', function () {
491 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) 491 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
492 }) 492 })
493 493
494 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () { 494 it('Should fail with invalid no modal attributes', async function () {
495 const fields = { 495 const keys = [
496 noInstanceConfigWarningModal: -1 496 'noInstanceConfigWarningModal',
497 } 497 'noAccountSetupWarningModal',
498 498 'noWelcomeModal'
499 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields }) 499 ]
500 }) 500
501 for (const key of keys) {
502 const fields = {
503 [key]: -1
504 }
501 505
502 it('Should fail with an invalid noWelcomeModal attribute', async function () { 506 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
503 const fields = {
504 noWelcomeModal: -1
505 } 507 }
506
507 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
508 }) 508 })
509 509
510 it('Should succeed to change password with the correct params', async function () { 510 it('Should succeed to change password with the correct params', async function () {
@@ -516,7 +516,8 @@ describe('Test users API validators', function () {
516 email: 'super_email@example.com', 516 email: 'super_email@example.com',
517 theme: 'default', 517 theme: 'default',
518 noInstanceConfigWarningModal: true, 518 noInstanceConfigWarningModal: true,
519 noWelcomeModal: true 519 noWelcomeModal: true,
520 noAccountSetupWarningModal: true
520 } 521 }
521 522
522 await makePutBodyRequest({ 523 await makePutBodyRequest({
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 318ff832a..085d9d870 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -597,6 +597,7 @@ describe('Test users', function () {
597 expect(user.account.description).to.equal('my super description updated') 597 expect(user.account.description).to.equal('my super description updated')
598 expect(user.noWelcomeModal).to.be.false 598 expect(user.noWelcomeModal).to.be.false
599 expect(user.noInstanceConfigWarningModal).to.be.false 599 expect(user.noInstanceConfigWarningModal).to.be.false
600 expect(user.noAccountSetupWarningModal).to.be.false
600 }) 601 })
601 602
602 it('Should be able to update my theme', async function () { 603 it('Should be able to update my theme', async function () {
@@ -612,12 +613,14 @@ describe('Test users', function () {
612 await server.users.updateMe({ 613 await server.users.updateMe({
613 token: userToken, 614 token: userToken,
614 noInstanceConfigWarningModal: true, 615 noInstanceConfigWarningModal: true,
615 noWelcomeModal: true 616 noWelcomeModal: true,
617 noAccountSetupWarningModal: true
616 }) 618 })
617 619
618 const user = await server.users.getMyInfo({ token: userToken }) 620 const user = await server.users.getMyInfo({ token: userToken })
619 expect(user.noWelcomeModal).to.be.true 621 expect(user.noWelcomeModal).to.be.true
620 expect(user.noInstanceConfigWarningModal).to.be.true 622 expect(user.noInstanceConfigWarningModal).to.be.true
623 expect(user.noAccountSetupWarningModal).to.be.true
621 }) 624 })
622 }) 625 })
623 626