mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 18:52:05 +03:00
8a2d50b871
Closes #3083 Refs #3229 - Populates the dropdown list in the invite user menu with the list of roles a user is permitted to create. - Users API now checks the invite user request for allowed roles. - Change API response from 200 to 201 on successful invitation. - Change API response from 500 to 201 when the user was created but the email was not sent. The client will show a warning notification when it sees 'invite-pending' as the new user's status. - Add support for "?status=all" to the /users endpoint. - Refactor the route and controller for the /settings/users page so that there's only one network API call to load users instead of two.
66 lines
2.0 KiB
JavaScript
66 lines
2.0 KiB
JavaScript
var UserValidator = Ember.Object.create({
|
|
check: function (model) {
|
|
var validator = this.validators[model.get('status')];
|
|
|
|
if (typeof validator !== 'function') {
|
|
return [];
|
|
}
|
|
|
|
return validator(model);
|
|
},
|
|
|
|
validators: {
|
|
invited: function (model) {
|
|
var validationErrors = [],
|
|
email = model.get('email'),
|
|
roles = model.get('roles');
|
|
|
|
if (!validator.isEmail(email)) {
|
|
validationErrors.push({ message: 'Please supply a valid email address' });
|
|
}
|
|
|
|
if (roles.length < 1) {
|
|
validationErrors.push({ message: 'Please select a role' });
|
|
}
|
|
|
|
return validationErrors;
|
|
},
|
|
|
|
active: function (model) {
|
|
var validationErrors = [],
|
|
name = model.get('name'),
|
|
bio = model.get('bio'),
|
|
email = model.get('email'),
|
|
location = model.get('location'),
|
|
website = model.get('website');
|
|
|
|
if (!validator.isLength(name, 0, 150)) {
|
|
validationErrors.push({ message: 'Name is too long' });
|
|
}
|
|
|
|
if (!validator.isLength(bio, 0, 200)) {
|
|
validationErrors.push({ message: 'Bio is too long' });
|
|
}
|
|
|
|
if (!validator.isEmail(email)) {
|
|
validationErrors.push({ message: 'Please supply a valid email address' });
|
|
}
|
|
|
|
if (!validator.isLength(location, 0, 150)) {
|
|
validationErrors.push({ message: 'Location is too long' });
|
|
}
|
|
|
|
if (!_.isEmpty(website) &&
|
|
(!validator.isURL(website, { protocols: ['http', 'https'], require_protocol: true }) ||
|
|
!validator.isLength(website, 0, 2000))) {
|
|
|
|
validationErrors.push({ message: 'Website is not a valid url' });
|
|
}
|
|
|
|
return validationErrors;
|
|
}
|
|
}
|
|
});
|
|
|
|
export default UserValidator;
|