forked from morbidick/loc3
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented roles and added permission page for admins
- Loading branch information
morbidick
committed
Dec 21, 2014
1 parent
cda2ecd
commit 9c1c6bb
Showing
10 changed files
with
119 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
UI.registerHelper('contains', function(value,list,options) { | ||
if(_.contains(list, value)) { | ||
return this; | ||
} else { | ||
return null; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<template name="settingsPage"> | ||
<h3>Settings</h3> | ||
{{#if isInRole 'admin'}} | ||
<h4>Permissions</h4> | ||
<table class="table table-condensed table-hover table-bordered"> | ||
<thead> | ||
<tr> | ||
<td>name</td> | ||
{{#each roles}} | ||
<td> {{this.name}} </td> | ||
{{/each}} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{{#each users}} | ||
<tr> | ||
<td>{{this.username}}</td> | ||
{{#each roles}} | ||
<td> | ||
<input type="checkbox" class="permission-toggle" role="{{this.name}}" userId="{{../_id}}" checked={{contains this.name ../roles }} /> | ||
</td> | ||
{{/each}} | ||
</tr> | ||
{{/each}} | ||
</tbody> | ||
</table> | ||
{{/if}} | ||
</template> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Template.settingsPage.helpers({ | ||
"roles": function () { | ||
return Roles.getAllRoles(); | ||
}, | ||
"users": function() { | ||
return Meteor.users.find({}, {fields: {_id: 1, username: 1, roles:1}}); | ||
} | ||
}) | ||
Template.settingsPage.events({ | ||
"change .permission-toggle": function (event, template) { | ||
if(event.target.checked) { | ||
Meteor.call("addUserToRole", $(event.target).attr("userId"), $(event.target).attr("role"), function(error,data) { | ||
if(error) { | ||
Flash.danger(error); | ||
event.target.checked = !event.target.checked; | ||
} | ||
}); | ||
} else { | ||
Meteor.call("remUserFromRole", $(event.target).attr("userId"), $(event.target).attr("role"), function(error,data) { | ||
if(error) { | ||
Flash.danger(error); | ||
event.target.checked = !event.target.checked; | ||
} | ||
}); | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
if(Meteor.isServer && (Roles.getAllRoles().fetch().length !== Meteor.settings.roles.length)) { | ||
Meteor.startup(function () { | ||
Meteor.roles.remove({}); | ||
_.each(Meteor.settings.roles, | ||
function(role) { | ||
Roles.createRole(role); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
Meteor.methods({ | ||
"addUserToRole": function (user_id, role) { | ||
validate.authorized(Meteor.user(), "admin"); | ||
var user = Meteor.users.findOne(user_id); | ||
Roles.addUsersToRoles(user, role) | ||
}, | ||
"remUserFromRole": function (user_id, role) { | ||
validate.authorized(Meteor.user(), "admin"); | ||
var user = Meteor.users.findOne(user_id); | ||
Roles.removeUsersFromRoles(user,role) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters