diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/users.ts | 1 | ||||
-rw-r--r-- | server/helpers/custom-validators/users.ts | 5 | ||||
-rw-r--r-- | server/initializers/constants.ts | 3 | ||||
-rw-r--r-- | server/middlewares/validators/users.ts | 3 | ||||
-rw-r--r-- | server/tests/api/users/users-multiple-servers.ts | 20 | ||||
-rw-r--r-- | server/tests/api/users/users.ts | 23 | ||||
-rw-r--r-- | server/tests/utils/users/users.ts | 2 |
7 files changed, 54 insertions, 3 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index dcc4ef196..2342c23dd 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -303,6 +303,7 @@ async function updateMe (req: express.Request, res: express.Response, next: expr | |||
303 | await sequelizeTypescript.transaction(async t => { | 303 | await sequelizeTypescript.transaction(async t => { |
304 | await user.save({ transaction: t }) | 304 | await user.save({ transaction: t }) |
305 | 305 | ||
306 | if (body.displayName !== undefined) user.Account.name = body.displayName | ||
306 | if (body.description !== undefined) user.Account.description = body.description | 307 | if (body.description !== undefined) user.Account.description = body.description |
307 | await user.Account.save({ transaction: t }) | 308 | await user.Account.save({ transaction: t }) |
308 | 309 | ||
diff --git a/server/helpers/custom-validators/users.ts b/server/helpers/custom-validators/users.ts index c0acb8218..b59b766de 100644 --- a/server/helpers/custom-validators/users.ts +++ b/server/helpers/custom-validators/users.ts | |||
@@ -22,6 +22,10 @@ function isUserUsernameValid (value: string) { | |||
22 | return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`)) | 22 | return exists(value) && validator.matches(value, new RegExp(`^[a-z0-9._]{${min},${max}}$`)) |
23 | } | 23 | } |
24 | 24 | ||
25 | function isUserDisplayNameValid (value: string) { | ||
26 | return value === null || (exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.USERS.NAME)) | ||
27 | } | ||
28 | |||
25 | function isUserDescriptionValid (value: string) { | 29 | function isUserDescriptionValid (value: string) { |
26 | return value === null || (exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.USERS.DESCRIPTION)) | 30 | return value === null || (exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.USERS.DESCRIPTION)) |
27 | } | 31 | } |
@@ -60,6 +64,7 @@ export { | |||
60 | isUserUsernameValid, | 64 | isUserUsernameValid, |
61 | isUserNSFWPolicyValid, | 65 | isUserNSFWPolicyValid, |
62 | isUserAutoPlayVideoValid, | 66 | isUserAutoPlayVideoValid, |
67 | isUserDisplayNameValid, | ||
63 | isUserDescriptionValid, | 68 | isUserDescriptionValid, |
64 | isAvatarFile | 69 | isAvatarFile |
65 | } | 70 | } |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 9c9c3afc0..365b8617d 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -180,9 +180,10 @@ const CONFIG = { | |||
180 | 180 | ||
181 | const CONSTRAINTS_FIELDS = { | 181 | const CONSTRAINTS_FIELDS = { |
182 | USERS: { | 182 | USERS: { |
183 | NAME: { min: 3, max: 120 }, // Length | ||
184 | DESCRIPTION: { min: 3, max: 250 }, // Length | ||
183 | USERNAME: { min: 3, max: 20 }, // Length | 185 | USERNAME: { min: 3, max: 20 }, // Length |
184 | PASSWORD: { min: 6, max: 255 }, // Length | 186 | PASSWORD: { min: 6, max: 255 }, // Length |
185 | DESCRIPTION: { min: 3, max: 250 }, // Length | ||
186 | VIDEO_QUOTA: { min: -1 } | 187 | VIDEO_QUOTA: { min: -1 } |
187 | }, | 188 | }, |
188 | VIDEO_ABUSES: { | 189 | VIDEO_ABUSES: { |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 5dd8caa3f..247b704c4 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -7,7 +7,7 @@ import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | |||
7 | import { | 7 | import { |
8 | isAvatarFile, | 8 | isAvatarFile, |
9 | isUserAutoPlayVideoValid, | 9 | isUserAutoPlayVideoValid, |
10 | isUserDescriptionValid, | 10 | isUserDescriptionValid, isUserDisplayNameValid, |
11 | isUserNSFWPolicyValid, | 11 | isUserNSFWPolicyValid, |
12 | isUserPasswordValid, | 12 | isUserPasswordValid, |
13 | isUserRoleValid, | 13 | isUserRoleValid, |
@@ -98,6 +98,7 @@ const usersUpdateValidator = [ | |||
98 | ] | 98 | ] |
99 | 99 | ||
100 | const usersUpdateMeValidator = [ | 100 | const usersUpdateMeValidator = [ |
101 | body('displayName').optional().custom(isUserDisplayNameValid).withMessage('Should have a valid display name'), | ||
101 | body('description').optional().custom(isUserDescriptionValid).withMessage('Should have a valid description'), | 102 | body('description').optional().custom(isUserDescriptionValid).withMessage('Should have a valid description'), |
102 | body('password').optional().custom(isUserPasswordValid).withMessage('Should have a valid password'), | 103 | body('password').optional().custom(isUserPasswordValid).withMessage('Should have a valid password'), |
103 | body('email').optional().isEmail().withMessage('Should have a valid email attribute'), | 104 | body('email').optional().isEmail().withMessage('Should have a valid email attribute'), |
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index a7f3aa8d3..8b9b63348 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts | |||
@@ -76,6 +76,22 @@ describe('Test users with multiple servers', function () { | |||
76 | await wait(5000) | 76 | await wait(5000) |
77 | }) | 77 | }) |
78 | 78 | ||
79 | it('Should be able to update my display name', async function () { | ||
80 | this.timeout(10000) | ||
81 | |||
82 | await updateMyUser({ | ||
83 | url: servers[0].url, | ||
84 | accessToken: servers[0].accessToken, | ||
85 | displayName: 'my super display name' | ||
86 | }) | ||
87 | |||
88 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | ||
89 | user = res.body | ||
90 | expect(user.account.displayName).to.equal('my super display name') | ||
91 | |||
92 | await wait(5000) | ||
93 | }) | ||
94 | |||
79 | it('Should be able to update my description', async function () { | 95 | it('Should be able to update my description', async function () { |
80 | this.timeout(10000) | 96 | this.timeout(10000) |
81 | 97 | ||
@@ -87,6 +103,7 @@ describe('Test users with multiple servers', function () { | |||
87 | 103 | ||
88 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | 104 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) |
89 | user = res.body | 105 | user = res.body |
106 | expect(user.account.displayName).to.equal('my super display name') | ||
90 | expect(user.account.description).to.equal('my super description updated') | 107 | expect(user.account.description).to.equal('my super description updated') |
91 | 108 | ||
92 | await wait(5000) | 109 | await wait(5000) |
@@ -111,7 +128,7 @@ describe('Test users with multiple servers', function () { | |||
111 | await wait(5000) | 128 | await wait(5000) |
112 | }) | 129 | }) |
113 | 130 | ||
114 | it('Should have updated my avatar and my description on other servers too', async function () { | 131 | it('Should have updated my profile on other servers too', async function () { |
115 | for (const server of servers) { | 132 | for (const server of servers) { |
116 | const resAccounts = await getAccountsList(server.url, '-createdAt') | 133 | const resAccounts = await getAccountsList(server.url, '-createdAt') |
117 | 134 | ||
@@ -122,6 +139,7 @@ describe('Test users with multiple servers', function () { | |||
122 | const rootServer1Get = resAccount.body as Account | 139 | const rootServer1Get = resAccount.body as Account |
123 | expect(rootServer1Get.name).to.equal('root') | 140 | expect(rootServer1Get.name).to.equal('root') |
124 | expect(rootServer1Get.host).to.equal('localhost:9001') | 141 | expect(rootServer1Get.host).to.equal('localhost:9001') |
142 | expect(rootServer1Get.displayName).to.equal('my super display name') | ||
125 | expect(rootServer1Get.description).to.equal('my super description updated') | 143 | expect(rootServer1Get.description).to.equal('my super description updated') |
126 | 144 | ||
127 | await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png') | 145 | await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png') |
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 1192ef9e4..1ea599859 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -172,6 +172,7 @@ describe('Test users', function () { | |||
172 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | 172 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) |
173 | expect(user.roleLabel).to.equal('User') | 173 | expect(user.roleLabel).to.equal('User') |
174 | expect(user.id).to.be.a('number') | 174 | expect(user.id).to.be.a('number') |
175 | expect(user.account.displayName).to.equal('user_1') | ||
175 | expect(user.account.description).to.be.null | 176 | expect(user.account.description).to.be.null |
176 | }) | 177 | }) |
177 | 178 | ||
@@ -316,6 +317,7 @@ describe('Test users', function () { | |||
316 | expect(user.nsfwPolicy).to.equal('do_not_list') | 317 | expect(user.nsfwPolicy).to.equal('do_not_list') |
317 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | 318 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) |
318 | expect(user.id).to.be.a('number') | 319 | expect(user.id).to.be.a('number') |
320 | expect(user.account.displayName).to.equal('user_1') | ||
319 | expect(user.account.description).to.be.null | 321 | expect(user.account.description).to.be.null |
320 | }) | 322 | }) |
321 | 323 | ||
@@ -347,6 +349,7 @@ describe('Test users', function () { | |||
347 | expect(user.nsfwPolicy).to.equal('do_not_list') | 349 | expect(user.nsfwPolicy).to.equal('do_not_list') |
348 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | 350 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) |
349 | expect(user.id).to.be.a('number') | 351 | expect(user.id).to.be.a('number') |
352 | expect(user.account.displayName).to.equal('user_1') | ||
350 | expect(user.account.description).to.be.null | 353 | expect(user.account.description).to.be.null |
351 | }) | 354 | }) |
352 | 355 | ||
@@ -365,6 +368,25 @@ describe('Test users', function () { | |||
365 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') | 368 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') |
366 | }) | 369 | }) |
367 | 370 | ||
371 | it('Should be able to update my display name', async function () { | ||
372 | await updateMyUser({ | ||
373 | url: server.url, | ||
374 | accessToken: accessTokenUser, | ||
375 | displayName: 'new display name' | ||
376 | }) | ||
377 | |||
378 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
379 | const user = res.body | ||
380 | |||
381 | expect(user.username).to.equal('user_1') | ||
382 | expect(user.email).to.equal('updated@example.com') | ||
383 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
384 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
385 | expect(user.id).to.be.a('number') | ||
386 | expect(user.account.displayName).to.equal('new display name') | ||
387 | expect(user.account.description).to.be.null | ||
388 | }) | ||
389 | |||
368 | it('Should be able to update my description', async function () { | 390 | it('Should be able to update my description', async function () { |
369 | await updateMyUser({ | 391 | await updateMyUser({ |
370 | url: server.url, | 392 | url: server.url, |
@@ -380,6 +402,7 @@ describe('Test users', function () { | |||
380 | expect(user.nsfwPolicy).to.equal('do_not_list') | 402 | expect(user.nsfwPolicy).to.equal('do_not_list') |
381 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | 403 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) |
382 | expect(user.id).to.be.a('number') | 404 | expect(user.id).to.be.a('number') |
405 | expect(user.account.displayName).to.equal('new display name') | ||
383 | expect(user.account.description).to.equal('my super description updated') | 406 | expect(user.account.description).to.equal('my super description updated') |
384 | }) | 407 | }) |
385 | 408 | ||
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index fc6b26c50..d31e57a25 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts | |||
@@ -132,6 +132,7 @@ function updateMyUser (options: { | |||
132 | nsfwPolicy?: NSFWPolicyType, | 132 | nsfwPolicy?: NSFWPolicyType, |
133 | email?: string, | 133 | email?: string, |
134 | autoPlayVideo?: boolean | 134 | autoPlayVideo?: boolean |
135 | displayName?: string, | ||
135 | description?: string | 136 | description?: string |
136 | }) { | 137 | }) { |
137 | const path = '/api/v1/users/me' | 138 | const path = '/api/v1/users/me' |
@@ -142,6 +143,7 @@ function updateMyUser (options: { | |||
142 | if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend['autoPlayVideo'] = options.autoPlayVideo | 143 | if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend['autoPlayVideo'] = options.autoPlayVideo |
143 | if (options.email !== undefined && options.email !== null) toSend['email'] = options.email | 144 | if (options.email !== undefined && options.email !== null) toSend['email'] = options.email |
144 | if (options.description !== undefined && options.description !== null) toSend['description'] = options.description | 145 | if (options.description !== undefined && options.description !== null) toSend['description'] = options.description |
146 | if (options.displayName !== undefined && options.displayName !== null) toSend['displayName'] = options.displayName | ||
145 | 147 | ||
146 | return makePutBodyRequest({ | 148 | return makePutBodyRequest({ |
147 | url: options.url, | 149 | url: options.url, |