mirror of
https://github.com/wassname/talk.git
synced 2026-07-23 13:10:20 +08:00
Switching displayname edit after facebook auth to account endpoint.
This commit is contained in:
@@ -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}`)));
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user