diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index edd04de12..3c23bd5bc 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -19,11 +19,11 @@ export const updateDisplayName = displayName => ({type: actions.UPDATE_DISPLAYNA export const createDisplayName = (userId, formData) => dispatch => { dispatch(createDisplayNameRequest()); - coralApi(`/users/${userId}/displayname`, {method: 'POST', body: formData}) - .then((user) => { + coralApi('account/displayname', {method: 'PUT', body: formData}) + .then(() => { dispatch(createDisplayNameSuccess()); dispatch(hideCreateDisplayNameDialog()); - dispatch(updateDisplayName(user)); + dispatch(updateDisplayName(formData)); }) .catch(error => { dispatch(createDisplayNameFailure(lang.t(`error.${error.message}`))); diff --git a/routes/api/users/index.js b/routes/api/users/index.js index 93c1062d2..6f40e5fb5 100644 --- a/routes/api/users/index.js +++ b/routes/api/users/index.js @@ -65,17 +65,11 @@ router.post('/:user_id/username-enable', authorization.needed('ADMIN'), (req, re .toggleNameEdit(req.params.user_id, true) .then(() => { res.status(204).end(); - -router.post('/:user_id/displayname', authorization.needed(), (req, res, next) => { - UsersService.setDisplayName(req.params.user_id, req.body.displayName) - .then((user) => { - res.status(201).json(user); - }) - .catch(next); + }); }); router.post('/:user_id/email', authorization.needed('ADMIN'), (req, res, next) => { - + UsersService.findById(req.params.user_id) .then(user => { let localProfile = user.profiles.find((profile) => profile.provider === 'local'); diff --git a/services/users.js b/services/users.js index 2b7d5f718..b5c3a8885 100644 --- a/services/users.js +++ b/services/users.js @@ -349,7 +349,7 @@ module.exports = class UsersService { // User status is not supported! Error out here. return Promise.reject(new Error(`status ${status} is not supported`)); } - + return UserModel.findOne({id}) .then((user) => { if (user.status === 'APPROVED' && status === 'PENDING') { @@ -360,25 +360,6 @@ module.exports = class UsersService { }); } - /** - * Set the display name of a user. - * @param {String} id id of a user - * @param {String} displayName display name to set - * @param {Function} done callback after the operation is complete - */ - static setDisplayName(id, displayName) { - - return UsersService.isValidDisplayName(displayName) - .then(() => { // displayName is valid - return UserModel.update( - {id}, - {$set: {'displayName': displayName}}) - .then(() => { - return UserModel.findOne({'id': id}); - }); - }); - } - /** * Finds a user with the id. * @param {String} id user id (uuid) diff --git a/test/services/users.js b/test/services/users.js index 581b6f06e..5774d45ae 100644 --- a/test/services/users.js +++ b/test/services/users.js @@ -178,25 +178,6 @@ describe('services.UsersService', () => { }); }); - describe('#setDisplayName', () => { - it('should set the display name to a new unique one', () => { - return UsersService - .setDisplayName(mockUsers[0].id, 'maria') - .then(() => UsersService.findById(mockUsers[0].id)) - .then((user) => { - expect(user).to.have.property('displayName', 'maria'); - }); - }); - - it('should return an error when the displayName is not unique', () => { - return UsersService - .setDisplayName(mockUsers[0].id, 'marvel') - .catch((error) => { - expect(error).to.not.be.null; - }); - }); - }); - describe('#ban', () => { it('should set the status to banned', () => { return UsersService