aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--client/src/app/admin/users/shared/user.service.ts2
-rw-r--r--client/src/app/admin/users/user-add/user-add.component.ts2
-rw-r--r--client/src/app/admin/users/user-list/user-list.component.ts4
-rw-r--r--client/src/app/shared/rest/rest-extractor.service.ts8
-rw-r--r--client/src/app/videos/video-list/video-list.component.ts2
-rw-r--r--client/src/app/videos/video-watch/video-watch.component.ts2
-rw-r--r--client/tsconfig.json7
-rw-r--r--server/middlewares/validators/users.js15
-rw-r--r--server/tests/api/check-params.js11
9 files changed, 36 insertions, 17 deletions
diff --git a/client/src/app/admin/users/shared/user.service.ts b/client/src/app/admin/users/shared/user.service.ts
index d96db4575..13be553c0 100644
--- a/client/src/app/admin/users/shared/user.service.ts
+++ b/client/src/app/admin/users/shared/user.service.ts
@@ -20,7 +20,7 @@ export class UserService {
20 20
21 return this.authHttp.post(UserService.BASE_USERS_URL, body) 21 return this.authHttp.post(UserService.BASE_USERS_URL, body)
22 .map(this.restExtractor.extractDataBool) 22 .map(this.restExtractor.extractDataBool)
23 .catch((res) => this.restExtractor.handleError(res)); 23 .catch(this.restExtractor.handleError);
24 } 24 }
25 25
26 getUsers() { 26 getUsers() {
diff --git a/client/src/app/admin/users/user-add/user-add.component.ts b/client/src/app/admin/users/user-add/user-add.component.ts
index b7efd3a80..8dd98cc5c 100644
--- a/client/src/app/admin/users/user-add/user-add.component.ts
+++ b/client/src/app/admin/users/user-add/user-add.component.ts
@@ -31,7 +31,7 @@ export class UserAddComponent implements OnInit {
31 this.userService.addUser(this.username, this.password).subscribe( 31 this.userService.addUser(this.username, this.password).subscribe(
32 ok => this.router.navigate([ '/admin/users/list' ]), 32 ok => this.router.navigate([ '/admin/users/list' ]),
33 33
34 err => this.error = err 34 err => this.error = err.text
35 ); 35 );
36 } 36 }
37} 37}
diff --git a/client/src/app/admin/users/user-list/user-list.component.ts b/client/src/app/admin/users/user-list/user-list.component.ts
index 598daa42a..c89a61bca 100644
--- a/client/src/app/admin/users/user-list/user-list.component.ts
+++ b/client/src/app/admin/users/user-list/user-list.component.ts
@@ -27,7 +27,7 @@ export class UserListComponent implements OnInit {
27 this.totalUsers = totalUsers; 27 this.totalUsers = totalUsers;
28 }, 28 },
29 29
30 err => alert(err) 30 err => alert(err.text)
31 ); 31 );
32 } 32 }
33 33
@@ -37,7 +37,7 @@ export class UserListComponent implements OnInit {
37 this.userService.removeUser(user).subscribe( 37 this.userService.removeUser(user).subscribe(
38 () => this.getUsers(), 38 () => this.getUsers(),
39 39
40 err => alert(err) 40 err => alert(err.text)
41 ); 41 );
42 } 42 }
43 } 43 }
diff --git a/client/src/app/shared/rest/rest-extractor.service.ts b/client/src/app/shared/rest/rest-extractor.service.ts
index aa44799af..fcb1598f4 100644
--- a/client/src/app/shared/rest/rest-extractor.service.ts
+++ b/client/src/app/shared/rest/rest-extractor.service.ts
@@ -34,13 +34,19 @@ export class RestExtractor {
34 handleError(res: Response) { 34 handleError(res: Response) {
35 let text = 'Server error: '; 35 let text = 'Server error: ';
36 text += res.text(); 36 text += res.text();
37 let json = res.json(); 37 let json = '';
38
39 try {
40 json = res.json();
41 } catch (err) { ; }
38 42
39 const error = { 43 const error = {
40 json, 44 json,
41 text 45 text
42 }; 46 };
43 47
48 console.error(error);
49
44 return Observable.throw(error); 50 return Observable.throw(error);
45 } 51 }
46} 52}
diff --git a/client/src/app/videos/video-list/video-list.component.ts b/client/src/app/videos/video-list/video-list.component.ts
index 1324a6214..9a9ffe29f 100644
--- a/client/src/app/videos/video-list/video-list.component.ts
+++ b/client/src/app/videos/video-list/video-list.component.ts
@@ -98,7 +98,7 @@ export class VideoListComponent implements OnInit, OnDestroy {
98 98
99 this.loading.next(false); 99 this.loading.next(false);
100 }, 100 },
101 error => alert(error) 101 error => alert(error.text)
102 ); 102 );
103 } 103 }
104 104
diff --git a/client/src/app/videos/video-watch/video-watch.component.ts b/client/src/app/videos/video-watch/video-watch.component.ts
index bc0e3157d..d260e55c7 100644
--- a/client/src/app/videos/video-watch/video-watch.component.ts
+++ b/client/src/app/videos/video-watch/video-watch.component.ts
@@ -86,7 +86,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
86 this.video = video; 86 this.video = video;
87 this.loadVideo(); 87 this.loadVideo();
88 }, 88 },
89 error => alert(error) 89 error => alert(error.text)
90 ); 90 );
91 }); 91 });
92 } 92 }
diff --git a/client/tsconfig.json b/client/tsconfig.json
index 60ca14221..263316c4f 100644
--- a/client/tsconfig.json
+++ b/client/tsconfig.json
@@ -69,14 +69,8 @@
69 "src/app/shared/form-validators/url.validator.ts", 69 "src/app/shared/form-validators/url.validator.ts",
70 "src/app/shared/index.ts", 70 "src/app/shared/index.ts",
71 "src/app/shared/rest/index.ts", 71 "src/app/shared/rest/index.ts",
72 "src/app/shared/rest/mock-rest-table.ts",
73 "src/app/shared/rest/rest-extractor.service.ts", 72 "src/app/shared/rest/rest-extractor.service.ts",
74 "src/app/shared/rest/rest-filter.model.ts",
75 "src/app/shared/rest/rest-pagination.ts", 73 "src/app/shared/rest/rest-pagination.ts",
76 "src/app/shared/rest/rest-sort.ts",
77 "src/app/shared/rest/rest-table-page.ts",
78 "src/app/shared/rest/rest-table.spec.ts",
79 "src/app/shared/rest/rest-table.ts",
80 "src/app/shared/rest/rest.service.ts", 74 "src/app/shared/rest/rest.service.ts",
81 "src/app/shared/search/index.ts", 75 "src/app/shared/search/index.ts",
82 "src/app/shared/search/search-field.type.ts", 76 "src/app/shared/search/search-field.type.ts",
@@ -89,7 +83,6 @@
89 "src/app/videos/shared/index.ts", 83 "src/app/videos/shared/index.ts",
90 "src/app/videos/shared/loader/index.ts", 84 "src/app/videos/shared/loader/index.ts",
91 "src/app/videos/shared/loader/loader.component.ts", 85 "src/app/videos/shared/loader/loader.component.ts",
92 "src/app/videos/shared/pagination.model.ts",
93 "src/app/videos/shared/sort-field.type.ts", 86 "src/app/videos/shared/sort-field.type.ts",
94 "src/app/videos/shared/video.model.ts", 87 "src/app/videos/shared/video.model.ts",
95 "src/app/videos/shared/video.service.ts", 88 "src/app/videos/shared/video.service.ts",
diff --git a/server/middlewares/validators/users.js b/server/middlewares/validators/users.js
index e540ab0d1..5defdf4e3 100644
--- a/server/middlewares/validators/users.js
+++ b/server/middlewares/validators/users.js
@@ -17,11 +17,20 @@ function usersAdd (req, res, next) {
17 req.checkBody('username', 'Should have a valid username').isUserUsernameValid() 17 req.checkBody('username', 'Should have a valid username').isUserUsernameValid()
18 req.checkBody('password', 'Should have a valid password').isUserPasswordValid() 18 req.checkBody('password', 'Should have a valid password').isUserPasswordValid()
19 19
20 // TODO: check we don't have already the same username
21
22 logger.debug('Checking usersAdd parameters', { parameters: req.body }) 20 logger.debug('Checking usersAdd parameters', { parameters: req.body })
23 21
24 checkErrors(req, res, next) 22 checkErrors(req, res, function () {
23 User.loadByUsername(req.body.username, function (err, user) {
24 if (err) {
25 logger.error('Error in usersAdd request validator.', { error: err })
26 return res.sendStatus(500)
27 }
28
29 if (user) return res.status(409).send('User already exists.')
30
31 next()
32 })
33 })
25} 34}
26 35
27function usersRemove (req, res, next) { 36function usersRemove (req, res, next) {
diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js
index 4f7b26561..e361147bb 100644
--- a/server/tests/api/check-params.js
+++ b/server/tests/api/check-params.js
@@ -590,6 +590,17 @@ describe('Test parameters validator', function () {
590 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204) 590 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204)
591 }) 591 })
592 592
593 it('Should fail if we add a user with the same username', function (done) {
594 it('Should succeed with the correct params', function (done) {
595 const data = {
596 username: 'user1',
597 password: 'my super password'
598 }
599
600 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409)
601 })
602 })
603
593 it('Should fail with a non admin user', function (done) { 604 it('Should fail with a non admin user', function (done) {
594 server.user = { 605 server.user = {
595 username: 'user1', 606 username: 'user1',