Watch perms in client (closes #1855)

This commit is contained in:
FinnStutzenstein 2017-01-23 16:19:50 +01:00
parent df60700612
commit 35903cbe97
11 changed files with 67 additions and 10 deletions

View File

@ -40,6 +40,7 @@ Core:
- New csv import layout. - New csv import layout.
- Replaced angular-csv-import through Papa Parse for csv parsing. - Replaced angular-csv-import through Papa Parse for csv parsing.
- Added smooth projector scroll. - Added smooth projector scroll.
- Added watching permissions in client and change the view immediately on changes.
Motions: Motions:
- Added adjustable line numbering mode (outside, inside, none) for each - Added adjustable line numbering mode (outside, inside, none) for each

View File

@ -34,6 +34,7 @@ angular.module('OpenSlidesApp.agenda.site', [
template: "<ui-view/>", template: "<ui-view/>",
data: { data: {
title: gettext('Agenda'), title: gettext('Agenda'),
basePerm: 'agenda.can_see',
}, },
}) })
.state('agenda.item', { .state('agenda.item', {

View File

@ -34,6 +34,7 @@ angular.module('OpenSlidesApp.assignments.site', [
template: "<ui-view/>", template: "<ui-view/>",
data: { data: {
title: gettext('Elections'), title: gettext('Elections'),
basePerm: 'assignments.can_see',
}, },
}) })
.state('assignments.assignment', { .state('assignments.assignment', {

View File

@ -123,10 +123,8 @@ angular.module('OpenSlidesApp.core', [
setUser: function(user_id, user_data) { setUser: function(user_id, user_data) {
if (user_id && user_data) { if (user_id && user_data) {
operator.user = User.inject(user_data); operator.user = User.inject(user_data);
operator.perms = operator.user.getPerms();
} else { } else {
operator.user = null; operator.user = null;
operator.perms = Group.get(1).permissions;
} }
}, },
// Returns true if the operator has at least one perm of the perms-list. // Returns true if the operator has at least one perm of the perms-list.
@ -136,6 +134,14 @@ angular.module('OpenSlidesApp.core', [
} }
return _.intersection(perms, operator.perms).length > 0; return _.intersection(perms, operator.perms).length > 0;
}, },
reloadPerms: function () {
if (operator.user) {
operator.perms = operator.user.getPerms();
} else {
var defaultGroup = Group.get(1);
operator.perms = defaultGroup ? defaultGroup.permissions : [];
}
},
// Returns true if the operator is a member of group. // Returns true if the operator is a member of group.
isInGroup: function(group) { isInGroup: function(group) {
return _.indexOf(operator.user.groups_id, group.id) > -1; return _.indexOf(operator.user.groups_id, group.id) > -1;

View File

@ -115,10 +115,18 @@ angular.module('OpenSlidesApp.core.site', [
.run([ .run([
'$rootScope', '$rootScope',
'gettextCatalog', 'gettextCatalog',
function ($rootScope, gettextCatalog) { 'operator',
function ($rootScope, gettextCatalog, operator) {
$rootScope.activeAppTitle = ''; $rootScope.activeAppTitle = '';
$rootScope.$on('$stateChangeSuccess', function(evt, toState) { $rootScope.$on('$stateChangeSuccess', function(event, toState) {
$rootScope.activeAppTitle = toState.data ? toState.data.title : ''; if (toState.data) {
$rootScope.activeAppTitle = toState.data.title || '';
$rootScope.baseViewPermissionsGranted = toState.data.basePerm ?
operator.hasPerms(toState.data.basePerm) : true;
} else {
$rootScope.activeAppTitle = '';
$rootScope.baseViewPermissionsGranted = true;
}
}); });
} }
]) ])
@ -263,6 +271,7 @@ angular.module('OpenSlidesApp.core.site', [
templateUrl: 'static/templates/home.html', templateUrl: 'static/templates/home.html',
data: { data: {
title: gettext('Home'), title: gettext('Home'),
basePerm: 'core.can_see_frontpage',
}, },
}) })
.state('projector', { .state('projector', {
@ -287,6 +296,7 @@ angular.module('OpenSlidesApp.core.site', [
controller: 'ManageProjectorsCtrl', controller: 'ManageProjectorsCtrl',
data: { data: {
title: gettext('Manage projectors'), title: gettext('Manage projectors'),
basePerm: 'core.can_manage_projector',
}, },
}) })
.state('core', { .state('core', {
@ -315,6 +325,7 @@ angular.module('OpenSlidesApp.core.site', [
}, },
data: { data: {
title: gettext('Settings'), title: gettext('Settings'),
basePerm: 'core.can_manage_config',
}, },
}) })
@ -335,6 +346,7 @@ angular.module('OpenSlidesApp.core.site', [
template: "<ui-view/>", template: "<ui-view/>",
data: { data: {
title: gettext('Tags'), title: gettext('Tags'),
basePerm: 'core.can_manage_tags',
}, },
}) })
.state('core.tag.list', {}) .state('core.tag.list', {})

View File

@ -30,6 +30,39 @@ angular.module('OpenSlidesApp.core.start', [])
} }
}); });
} }
])
.run([
'$rootScope',
'$state',
'operator',
'User',
'Group',
'mainMenu',
function ($rootScope, $state, operator, User, Group, mainMenu) {
var permissionChangeCallback = function () {
operator.reloadPerms();
mainMenu.updateMainMenu();
var stateData = $state.current.data;
var basePerm = stateData ? stateData.basePerm : '';
$rootScope.baseViewPermissionsGranted = basePerm ?
operator.hasPerms(basePerm) : true;
};
$rootScope.$watch(function () {
return Group.lastModified();
}, function () {
if (Group.getAll().length) {
permissionChangeCallback();
}
});
$rootScope.$watch(function () {
return operator.user ? User.lastModified(operator.user.id) : true;
}, function () {
permissionChangeCallback();
});
}
]); ]);
}()); }());

View File

@ -36,8 +36,8 @@
</div> </div>
</div> </div>
<div class="details"> <div class="details" os-perms="core.can_manage_projector">
<div class="projectorContainer" os-perms="core.can_manage_projector"> <div class="projectorContainer">
<div ng-repeat="projector in projectors | orderBy: 'id'"> <div ng-repeat="projector in projectors | orderBy: 'id'">
<div> <div>

View File

@ -174,9 +174,9 @@
<!-- Content --> <!-- Content -->
<div id="content" ng-controller="ProjectorSidebarCtrl"> <div id="content" ng-controller="ProjectorSidebarCtrl">
<div class="containerOS"> <div class="containerOS">
<div class="col1" ng-class="isProjectorSidebar ? 'min' : 'max'"> <div class="col1" ng-class="(isProjectorSidebar && operator.hasPerms('core.can_see_projector')) ? 'min' : 'max'">
<!-- dynamic views --> <!-- dynamic views -->
<div ui-view ng-if="openslidesBootstrapDone"></div> <div ui-view ng-if="openslidesBootstrapDone && baseViewPermissionsGranted"></div>
<!-- footer --> <!-- footer -->
<div id="footer"> <div id="footer">
&copy; Copyright by <a href="http://www.openslides.org" target="_blank">OpenSlides</a> | &copy; Copyright by <a href="http://www.openslides.org" target="_blank">OpenSlides</a> |
@ -184,7 +184,7 @@
</div><!--end footer--> </div><!--end footer-->
</div> </div>
<div id="sidebar" class="col2" os-perms="core.can_see_projector" <div id="sidebar" class="col2" os-perms="core.can_see_projector"
ng-class="isProjectorSidebar ? 'max' : 'min'" ng-class="(isProjectorSidebar && operator.hasPerms('core.can_see_projector')) ? 'max' : 'min'"
ng-init="initSidebar()"> ng-init="initSidebar()">
<!-- sidebar maximized --> <!-- sidebar maximized -->
<div class="projector_full" ng-if="isProjectorSidebar"> <div class="projector_full" ng-if="isProjectorSidebar">

View File

@ -33,6 +33,7 @@ angular.module('OpenSlidesApp.mediafiles.states', [
template: "<ui-view/>", template: "<ui-view/>",
data: { data: {
title: gettext('Files'), title: gettext('Files'),
basePerm: 'mediafiles.can_see',
}, },
}) })
.state('mediafiles.mediafile', { .state('mediafiles.mediafile', {

View File

@ -37,6 +37,7 @@ angular.module('OpenSlidesApp.motions.site', [
template: "<ui-view/>", template: "<ui-view/>",
data: { data: {
title: gettext('Motions'), title: gettext('Motions'),
basePerm: 'motions.can_see',
}, },
}) })
.state('motions.motion', { .state('motions.motion', {

View File

@ -34,6 +34,7 @@ angular.module('OpenSlidesApp.users.site', [
template: "<ui-view/>", template: "<ui-view/>",
data: { data: {
title: gettext('Participants'), title: gettext('Participants'),
basePerm: 'users.can_see_name',
}, },
}) })
.state('users.user', { .state('users.user', {