Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #858 from mleanos/admin-users-require-role
Browse files Browse the repository at this point in the history
Admin users require role
  • Loading branch information
lirantal committed Aug 30, 2015
2 parents 6af137d + 263adcc commit 8335aa7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
11 changes: 7 additions & 4 deletions modules/users/client/views/admin/edit-user.client.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ <h1>User <span ng-bind="user.username"></span></h1>
<fieldset>
<div class="form-group" show-errors>
<label for="firstName">First Name</label>
<input type="text" id="firstName" name="firstName" class="form-control" ng-model="user.firstName" placeholder="First Name" required>
<input type="text" id="firstName" name="firstName" class="form-control" ng-model="user.firstName" placeholder="First Name" required />
<div ng-messages="userForm.firstName.$error" role="alert">
<p class="help-block error-text" ng-message="required">First name is required.</p>
</div>
</div>
<div class="form-group" show-errors>
<label for="lastName">Last Name</label>
<input type="text" id="lastName" name="lastName" class="form-control" ng-model="user.lastName" placeholder="Last Name" required>
<input type="text" id="lastName" name="lastName" class="form-control" ng-model="user.lastName" placeholder="Last Name" required />
<div ng-messages="userForm.lastName.$error" role="alert">
<p class="help-block error-text" ng-message="required">Last name is required.</p>
</div>
</div>
<div class="form-group">
<div class="form-group" show-errors>
<label class="control-label" for="roles">Roles</label>
<div class="controls">
<input class="form-control" type="text" name="roles" ng-model="user.roles" id="roles" ng-list />
<input class="form-control" type="text" name="roles" ng-model="user.roles" id="roles" ng-list required />
<div ng-messages="userForm.roles.$error" role="alert">
<p class="help-block error-text" ng-message="required">At least one role is required.</p>
</div>
</div>
</div>
<div class="form-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Users</h1>
<div class="list-group">
<a ng-repeat="user in pagedItems" ui-sref="admin.user({userId: user._id})" class="list-group-item">
<h4 class="list-group-item-heading" ng-bind="user.username"></h4>
<p class="list-group-item-text pull-right small" ng-bind="user.roles"></p>
<p class="list-group-item-text" ng-bind="user.email"></p>
</a>
</div>
Expand Down
3 changes: 2 additions & 1 deletion modules/users/server/models/user.server.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ var UserSchema = new Schema({
type: String,
enum: ['user', 'admin']
}],
default: ['user']
default: ['user'],
required: 'Please provide at least one role'
},
updated: {
type: Date
Expand Down
48 changes: 48 additions & 0 deletions modules/users/tests/server/user.server.model.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,54 @@ describe('User Model Unit Tests:', function () {
});
});

it('should be able to update an existing user with valid roles without problems', function (done) {
var _user = new User(user);

_user.save(function (err) {
should.not.exist(err);
_user.roles = ['user', 'admin'];
_user.save(function (err) {
should.not.exist(err);
_user.remove(function (err) {
should.not.exist(err);
done();
});
});
});
});

it('should be able to show an error when trying to update an existing user without a role', function (done) {
var _user = new User(user);

_user.save(function (err) {
should.not.exist(err);
_user.roles = [];
_user.save(function (err) {
should.exist(err);
_user.remove(function (err) {
should.not.exist(err);
done();
});
});
});
});

it('should be able to show an error when trying to update an existing user with a invalid role', function (done) {
var _user = new User(user);

_user.save(function (err) {
should.not.exist(err);
_user.roles = ['invalid-user-role-enum'];
_user.save(function (err) {
should.exist(err);
_user.remove(function (err) {
should.not.exist(err);
done();
});
});
});
});

it('should confirm that saving user model doesnt change the password', function (done) {
var _user1 = new User(user1);

Expand Down

0 comments on commit 8335aa7

Please sign in to comment.