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

Commit

Permalink
Admin Users require role
Browse files Browse the repository at this point in the history
These changes make the role field required in the User model. Changes to
the Admin user edit view were added to provide validation for the role
field.

As an added enhancement, the user's roles are displayed in the Admin
user list view.
  • Loading branch information
mleanos committed Aug 29, 2015
1 parent 85d2a1a commit bbbe877
Show file tree
Hide file tree
Showing 3 changed files with 10 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

0 comments on commit bbbe877

Please sign in to comment.