Switching displayname edit after facebook auth to account endpoint.

This commit is contained in:
David Jay
2017-02-06 11:07:35 -08:00
parent cb78e8d563
commit 1901592780
4 changed files with 6 additions and 50 deletions
+3 -3
View File
@@ -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}`)));
+2 -8
View File
@@ -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');
+1 -20
View File
@@ -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)
-19
View File
@@ -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