Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.build*
.idea
18 changes: 17 additions & 1 deletion client/accounts_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
</div>
</div>
<table class='table table-striped'>
<caption style="text-align: center;">
<h2>Users and Roles</h2>
</caption>
<thead>
<tr>
<th></th>
<th>Username</th>
<th>Name</th>
<th>Email</th>
<th>Roles</th>
Expand All @@ -29,12 +33,24 @@
<span data-toggle="modal" href="#infoaccount" class="glyphicon glyphicon-info-sign clickable"></span>
{{/unless}}
</td>
<td>
{{#if username}}
{{username}}
{{else}}
{{#if profile.name}}
{{profile.name}}
{{else}}
{{email}}
{{/if}}
{{/if}}
</td>
<td>
{{#if profile.name}}
{{profile.name}}
{{else}}
{{email}}
{{username}}
{{/if}}

</td>
<td>{{email}}</td>
<td>{{roles}}</td>
Expand Down
1 change: 1 addition & 0 deletions client/accounts_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Template.accountsAdmin.events({
},

'click .glyphicon-pencil': function(event, template) {
$("div.modal .modal-header div.alert").remove();
Session.set('userInScope', this);
}
});
Expand Down
15 changes: 14 additions & 1 deletion client/info_account_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@ <h4>Account Info</h4>
{{#with userInScope}}
<div class="modal-body">
<ul class="list-group">
<li class="list-group-item"><strong>Username</strong>
<span class="pull-right">
{{#if username}}
{{username}}
{{else}}
{{#if profile.name}}
{{profile.name}}
{{else}}
{{email}}
{{/if}}
{{/if}}
</span>
</li>
<li class="list-group-item"><strong>Name</strong>
<span class="pull-right">
{{#if profile.name}}
{{profile.name}}
{{else}}
{{email}}
{{username}}
{{/if}}
</span>
</li>
Expand Down
13 changes: 8 additions & 5 deletions client/info_account_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ Template.infoAccountModalInner.helpers({
pairs.push({key: 'Roles', value: 'None'});

for (var role in this.roles) {
var r = this.roles[role];
if (role === '0') {
pairs.push({key: 'Roles', value: r});
} else {
pairs.push({key: '-', value: r});
if (this.roles.hasOwnProperty(role) ) {
// excludes any Array prototype extensions
var r = this.roles[role];
if (role === '0') {
pairs.push({key: 'Roles', value: r});
} else {
pairs.push({key: '-', value: r});
}
}
}
return pairs;
Expand Down
58 changes: 31 additions & 27 deletions client/update_account_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,48 @@
<template name="updateAccountModalInner">
{{#with userInScope}}
<div class="modal-header">
<h4>Update {{email}}</h4>
<h3>Update User</h3>
</div>
<div class="modal-body">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">Name</span>
<input data-user-id="{{_id}}" class="form-control admin-user-info" name="profile.name" value="{{profile.name}}" placeholder="{{email}}">
</div>
</div>
<div class="modal-body">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">Username</span>
<input data-user-id="{{_id}}" class="form-control admin-user-info" name="username" value="{{username}}" placeholder="{{email}}">
</div>
<div class="input-group">
<span class="input-group-addon">Name</span>
<input data-user-id="{{_id}}" class="form-control admin-user-info" name="profile.name" value="{{profile.name}}" placeholder="{{username}}">
</div>
</div>
{{#if roles}}
<ul class="list-group">
<ul class="list-group">
{{#each roles}}
<li class="list-group-item">
<button data-user-id="{{../_id}}" class="btn btn-danger btn-xs remove-role" type="button">Remove</button>
<span class="pull-right">{{this}}</span>
</li>
<li class="list-group-item">
<button data-user-id="{{../_id}}" class="btn btn-danger btn-xs remove-role" type="button">Remove</button>
<span class="pull-right">{{this}}</span>
</li>
{{/each}}
</ul>
</ul>
{{else}}
This account has no roles.
This account has no roles.
{{/if}}
{{#if unsetRoles}}
<div class="btn-group clearfix full-width">
<button type="button" class="btn btn-success dropdown-toggle pull-right" data-toggle="dropdown">
<span class="glyphicon glyphicon-plus"></span> Add Role
</button>
<ul class="dropdown-menu pull-right" role="menu">
{{#each unsetRoles}}
<li><a href="#" class="add-role" data-user-id="{{../_id}}">{{this}}</a></li>
{{/each}}
</ul>
</div>
<div class="btn-group clearfix full-width">
<button type="button" class="btn btn-success dropdown-toggle pull-right" data-toggle="dropdown">
<span class="glyphicon glyphicon-plus"></span> Add Role
</button>
<ul class="dropdown-menu pull-right" role="menu">
{{#each unsetRoles}}
<li><a href="#" class="add-role" data-user-id="{{../_id}}">{{this}}</a></li>
{{/each}}
</ul>
</div>
{{else}}
<em>All roles already set.</em>
<em>All roles already set.</em>
{{/if}}
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-primary">Done</button>
</div>
</div>
{{/with}}
</template>
8 changes: 5 additions & 3 deletions client/update_account_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Template.updateAccountModalInner.helpers({
//Iterate through services
for (var serviceName in this.services) {
var serviceObject = this.services[serviceName];
//If an 'id' isset then assume valid service
//If an 'id' is set then assume valid service
if (serviceObject.id) {
if (serviceObject.email) {
return serviceObject.email;
Expand Down Expand Up @@ -76,10 +76,12 @@ Template.updateAccountModalInner.events({
Meteor.call('updateUserInfo', userId, ele.name, ele.value, function(error) {
if (error)
{
if (typeof Errors === "undefined") Log.error('Error: ' + error.reason);
else Errors.throw(error.reason);
Log.error('Error calling updateUserInfo: ' + error.error);
var me = $("div.modal.in .modal-header").append("<div class='alert alert-danger' role='alert'>")
$("div.alert",me).html(error.error)
return;
}
$("div.modal.in .modal-header div.alert").remove();
Session.set('userInScope', Meteor.users.findOne(userId));
});
}
Expand Down
1 change: 1 addition & 0 deletions libs/user_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ filteredUserQuery = function(userId, filter) {
// TODO: passing to regex directly could be dangerous
users = Meteor.users.find({
$or: [
{'username': {$regex: filter, $options: 'i'}},
{'profile.name': {$regex: filter, $options: 'i'}},
{'emails.address': {$regex: filter, $options: 'i'}}
]
Expand Down
5 changes: 3 additions & 2 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Package.describe({
name: "accounts-admin",
summary: "A roles based account management system using bootstrap 3",
version: "0.2.7",
version: "0.2.8",
git: "https://github.com/hharnisc/meteor-accounts-admin-ui-bootstrap-3.git"
});

Expand Down Expand Up @@ -28,4 +29,4 @@ Package.on_use(function (api, where) {
api.add_files('server/startup.js', 'server');
api.add_files('server/publish.js', 'server');
api.add_files('server/methods.js', 'server');
});
});
11 changes: 7 additions & 4 deletions server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Meteor.methods({
throw new Meteor.Error(422, 'Cannot delete role admin');

// remove the role from all users who currently have the role
// if successfull remove the role
// if successful remove the role
Meteor.users.update(
{roles: role },
{$pull: {roles: role }},
Expand All @@ -95,9 +95,12 @@ Meteor.methods({
if (!user || !Roles.userIsInRole(user, ['admin']))
throw new Meteor.Error(401, "You need to be an admin to update a user.");

if (property !== 'profile.name')
throw new Meteor.Error(422, "Only 'name' is supported.");

if (['username','profile.name'].indexOf(property) === -1)
throw new Meteor.Error(422, "Programming error: Only 'username' or 'profile.name' is supported.");
if (property === 'username') {
if (Meteor.users.find({_id:{$ne:id},username:value}).count())
throw new Meteor.Error("username <b>" + value + "</b> already in use")
}
obj = {};
obj[property] = value;
Meteor.users.update({_id: id}, {$set: obj});
Expand Down
Loading