Skip to content

Commit

Permalink
cleanup authenticated and added check for enabled moduler
Browse files Browse the repository at this point in the history
  • Loading branch information
ellman committed May 7, 2014
1 parent e4e8e46 commit 60569f3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion public/system/services/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ angular.module('mean.system').factory('Global', [

_this._data = {
user: window.user,
authenticated: window.authenticated.length
authenticated: window.user.roles
};
return _this._data;
}
Expand Down
19 changes: 7 additions & 12 deletions server/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@
var mean = require('meanio');

exports.render = function(req, res) {

var modules = [];
var roles = (req.user ? req.user.roles : []);

var enableAdmin = false;
// Preparing angular modules list with dependencies
for (var name in mean.modules) {

if (name === 'mean-admin' && roles.indexOf('admin') != -1) {
enableAdmin = true;
}

modules.push({
name: name,
module: 'mean.' + name,
Expand All @@ -28,10 +21,12 @@ exports.render = function(req, res) {
name: req.user.name,
_id: req.user._id,
username: req.user.username,
roles: roles
} : 'null',
roles: req.user.roles
} : {},
modules: modules,
enableAdmin:enableAdmin,
authenticated: roles
enabledAdmin: function(name) {
return (req.user.roles && req.user.roles.indexOf('admin') && mean.enabled(name));
}

});
};
1 change: 0 additions & 1 deletion server/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
<script type="text/javascript">
window.user = {{user|json|safe}};
window.modules = {{modules|json|safe}};
window.authenticated = {{authenticated|json|safe}};
</script>
{% endblock %}
2 changes: 1 addition & 1 deletion server/views/layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<body>
<div class="navbar navbar-inverse navbar-fixed-top" data-ng-include="'/public/system/views/header.html'" data-role="navigation"></div>
{% if enableAdmin %}
{% if enabledAdmin('mean-admin') %}
<section class="admin-menu">
<div data-ng-include="'/mean-admin/views/index.html'"></div>
</section>
Expand Down

0 comments on commit 60569f3

Please sign in to comment.