front-end side privileges

This commit is contained in:
Davide Alberani 2016-05-29 11:59:09 +02:00
parent 98c745014c
commit 495f1a6b57
3 changed files with 25 additions and 7 deletions

View file

@ -52,7 +52,7 @@
<div ng-if="logo.imgURL" class="navbar-brand"><a ng-if="logo.link" href="{{logo.link}}" target="_blank"><img src="{{logo.imgURL}}" /></a></div>
<ul class="nav navbar-nav">
<li ng-class="{active: isActive('/events') || isActive('/event')}"><a ui-sref="events">{{'Events' | translate}}</a></li>
<li ng-class="{active: isActive('/persons') || isActive('/person') || isActive('/import/persons')}"><a ui-sref="persons">{{'Persons' | translate}}</a></li>
<li ng-if="requires('admin')" ng-class="{active: isActive('/persons') || isActive('/person') || isActive('/import/persons')}"><a ui-sref="persons">{{'Persons' | translate}}</a></li>
</ul>
</div>
<div class="collapse navbar-collapse">

26
angular_app/js/app.js vendored
View file

@ -28,8 +28,8 @@ var eventManApp = angular.module('eventManApp', [
/* Add some utilities to the global scope. */
eventManApp.run(['$rootScope', '$state', '$stateParams', '$log',
function($rootScope, $state, $stateParams, $log) {
eventManApp.run(['$rootScope', '$state', '$stateParams', '$log', 'Info',
function($rootScope, $state, $stateParams, $log, Info) {
$rootScope.app_uuid = guid();
$log.debug('App UUID: ' + $rootScope.app_uuid);
$rootScope.$state = $state;
@ -37,6 +37,10 @@ eventManApp.run(['$rootScope', '$state', '$stateParams', '$log',
$rootScope.error = {error: false};
Info.get({}, function(data) {
$rootScope.info = data || {};
});
$rootScope.errorHandler = function(response) {
$log.debug('Handling error message:');
$log.debug(response);
@ -52,6 +56,24 @@ eventManApp.run(['$rootScope', '$state', '$stateParams', '$log',
$rootScope.error.error = false;
}
};
/* Check GUI privileges. */
$rootScope.requires = function(permission) {
if (!($rootScope.info && $rootScope.info.user &&
$rootScope.info.user.username && $rootScope.info.user.privileges)) {
return false;
}
var accepted = false;
angular.forEach($rootScope.info.user.privileges || [],
function(value, idx) {
if (value === permission) {
accepted = true;
return;
}
}
);
return accepted;
};
}]
);

View file

@ -21,10 +21,6 @@ eventManControllers.controller('NavigationCtrl', ['$scope', '$rootScope', '$loca
}
});
Info.get({}, function(data) {
$rootScope.info = data || {};
});
$scope.isActive = function(view) {
if (view === $location.path()) {
return true;