WIP refactoring AuthService

pull/1505/head
Richard 11 years ago
parent 6e313d8a26
commit 9b92a383bb
  1. 4
      app/assets/javascripts/angular/controllers/dialogs/save.js
  2. 5
      app/assets/javascripts/angular/controllers/dialogs/settings.js
  3. 4
      app/assets/javascripts/angular/controllers/dialogs/share.js
  4. 14
      app/assets/javascripts/angular/directives/work_packages/options-dropdown-directive.js
  5. 17
      app/assets/javascripts/angular/services/authorisation-service.js
  6. 4
      app/assets/javascripts/angular/work_packages/controllers/work-packages-list-controller.js
  7. 1
      app/controllers/api/experimental/work_packages_controller.rb
  8. 12
      public/templates/work_packages.list.html
  9. 4
      public/templates/work_packages/modals/share.html

@ -40,8 +40,9 @@ angular.module('openproject.workPackages.controllers')
'$scope',
'saveModal',
'QueryService',
'AuthorisationService',
'$state',
function($scope, saveModal, QueryService, $state) {
function($scope, saveModal, QueryService, AuthorisationService, $state) {
this.name = 'Save';
this.closeMe = saveModal.deactivate;
@ -52,6 +53,7 @@ angular.module('openproject.workPackages.controllers')
// push query id to URL without reinitializing work-packages-list-controller
if (data.query) {
$state.go('work-packages.list', { query_id: data.query.id }, { notify: false });
AuthorisationService.initModelAuth(data.query._links, "query");
}
saveModal.deactivate();

@ -36,8 +36,8 @@ angular.module('openproject.workPackages.controllers')
});
}])
.controller('SettingsModalController', ['$scope', 'settingsModal', 'QueryService',
function($scope, settingsModal, QueryService) {
.controller('SettingsModalController', ['$scope', 'settingsModal', 'QueryService', 'AuthorisationService',
function($scope, settingsModal, QueryService, AuthorisationService) {
var query = QueryService.getQuery();
@ -51,6 +51,7 @@ angular.module('openproject.workPackages.controllers')
.then(function(data){
settingsModal.deactivate();
$scope.$emit('flashMessage', data.status);
AuthorisationService.initModelAuth(data.query._links, "query");
});
};
}]);

@ -63,7 +63,6 @@ angular.module('openproject.workPackages.controllers')
var messageObject;
QueryService.saveQuery()
.then(function(data){
messageObject = data.status;
})
.then(function(data){
@ -76,6 +75,9 @@ angular.module('openproject.workPackages.controllers')
} else {
closeAndReport(messageObject);
}
})
.then(function(data){
AuthorisationService.initModelAuth(data.query._links, "query");
});
};
}]);

@ -95,7 +95,9 @@ angular.module('openproject.workPackages.directives')
};
scope.showExportModal = function(){
showModal.call(exportModal);
if( allowWorkPackageAction(event, 'export') ) {
showModal.call(exportModal);
}
};
scope.showColumnsModal = function(){
@ -137,7 +139,15 @@ angular.module('openproject.workPackages.directives')
}
function allowQueryAction(event, action) {
if(AuthorisationService.can(scope.query, action)){
return allowAction(event, 'query', action);
}
function allowWorkPackageAction(event, action) {
return allowAction(event, 'work_package', action);
}
function allowAction(event, modelName, action) {
if(AuthorisationService.can(modelName, action)){
return true;
} else {
event.preventDefault();

@ -29,17 +29,22 @@
angular.module('openproject.services')
.service('AuthorisationService', function(){
var links = {};
var AuthorisationService = {
can: function(model, action){
// Authorised if there is a link to that action
return !!(model && model.links && (action in model.links));
initModelAuth: function(modelLinks, modelName) {
links[modelName] = modelLinks;
},
can: function(modelName, action) {
return links[modelName] && (action in links[modelName]);
},
cannot: function(model, action) {
return !AuthorisationService.can(model, action);
cannot: function(modelName, action) {
return !AuthorisationService.can(modelName, action);
}
}
};
return AuthorisationService;
});

@ -143,7 +143,8 @@ angular.module('openproject.workPackages.controllers')
$scope.updateBackUrl();
// Authorisation
$scope.disableNewWorkPackage = AuthorisationService.cannot({ links: meta._links }, "create");
AuthorisationService.initModelAuth(meta._links, "work_package");
AuthorisationService.initModelAuth(meta.query._links, "query");
}
function initAvailableColumns() {
@ -189,6 +190,7 @@ angular.module('openproject.workPackages.controllers')
initialSetup();
// Just to keep the templates a bit cleaner
$scope.can = AuthorisationService.can;
$scope.cannot = AuthorisationService.cannot;

@ -183,6 +183,7 @@ module Api
def work_packages_links
links = {}
links[:create] = api_experimental_query_path(@project) if User.current.allowed_to?(:add_work_packages, @project)
links[:export] = api_experimental_query_path(@project) if User.current.allowed_to?(:export_work_packages, @project)
links
end

@ -9,7 +9,7 @@
<button class="button_highlight"
with-dropdown
dropdown-id="tasksDropdown"
ng-disabled="disableNewWorkPackage">
ng-disabled="AuthorisationService.cannot('work_package', 'create')">
<i class="icon-add icon4"></i>
{{ I18n.t('js.toolbar.unselected_title') }}
<i class="icon-pulldown-arrow1 icon-dropdown"></i>
@ -64,22 +64,22 @@
<li><a href ng-click="toggleDisplaySums()"><i ng-if="query.displaySums" class="icon-action-menu icon-yes"></i><i ng-if="!query.displaySums" class="icon-action-menu no-icon"></i>{{ I18n.t('js.toolbar.settings.display_sums') }}</a></li>
<li class="dropdown-divider"></li>
<li><a href ng-click="saveQuery($event)"
ng-class="{'inactive': (!query.isNew() && cannot(query, 'update')) || (query.isNew() && cannot(query, 'create'))}">
ng-class="{'inactive': (!query.isNew() && cannot('query', 'update')) || (query.isNew() && cannot('query', 'create'))}">
<i class="icon-action-menu icon-save1"></i>{{ I18n.t('js.toolbar.settings.save') }}</a>
</li>
<li><a href ng-click="showSaveAsModal($event)" ng-class="{'inactive': query.isNew() || cannot(query, 'create')}">
<li><a href ng-click="showSaveAsModal($event)" ng-class="{'inactive': query.isNew() || cannot('query', 'create')}">
<i class="icon-action-menu icon-save1"></i>{{ I18n.t('js.toolbar.settings.save_as') }}</a>
</li>
<li><a href ng-click="deleteQuery($event)" ng-class="{'inactive': query.isNew() || cannot(query, 'delete')}">
<li><a href ng-click="deleteQuery($event)" ng-class="{'inactive': query.isNew() || cannot('query', 'delete')}">
<i class="icon-action-menu icon-delete"></i>{{ I18n.t('js.toolbar.settings.delete') }}</a>
</li>
<li><a href ng-click="showExportModal()">
<li><a href ng-click="showExportModal()" ng-class="{'incative': cannot('work_package', 'export')}">
<i class="icon-action-menu icon-export"></i>{{ I18n.t('js.toolbar.settings.export') }}</a>
</li>
<li><a href ng-click="showShareModal($event)" ng-class="{'inactive': query.isNew()}">
<i class="icon-action-menu icon-publish"></i>{{ I18n.t('js.toolbar.settings.share') }}</a>
</li>
<li><a href ng-click="showSettingsModal($event)" ng-class="{'inactive': query.isNew() || cannot(query, 'update')}">
<li><a href ng-click="showSettingsModal($event)" ng-class="{'inactive': query.isNew() || cannot('query', 'update')}">
<i class="icon-action-menu icon-settings"></i>{{ I18n.t('js.toolbar.settings.page_settings') }}</a>
</li>
</ul>

@ -9,7 +9,7 @@
<input type="checkbox"
name="is_public"
ng-model="query.isPublic"
ng-disabled="cannot(query, 'publicize')"></input>
ng-disabled="cannot('query', 'publicize')"></input>
<div class="styled-checkbox"></div>
Page visible for others
</label>
@ -19,7 +19,7 @@
<input type="checkbox"
name="show_in_menu"
ng-model="shareSettings.starred"
ng-disabled="cannot(query, 'star')"></input>
ng-disabled="cannot('query', 'star')"></input>
<div class="styled-checkbox"></div>
Show page in menu
</label>

Loading…
Cancel
Save