From 0667c75c5bf48a98948d8bd9758f165361f32219 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Tue, 19 Aug 2014 11:02:53 +0200 Subject: [PATCH] Respect user permissions in more menu --- .../services/work-packages-table-service.js | 12 +++++ .../work-package-details-controller.js | 47 +++++++++++++++++-- .../templates/work_packages.list.details.html | 31 ++++-------- 3 files changed, 64 insertions(+), 26 deletions(-) diff --git a/app/assets/javascripts/angular/services/work-packages-table-service.js b/app/assets/javascripts/angular/services/work-packages-table-service.js index 33811a9451..c22e53295a 100644 --- a/app/assets/javascripts/angular/services/work-packages-table-service.js +++ b/app/assets/javascripts/angular/services/work-packages-table-service.js @@ -104,6 +104,18 @@ angular.module('openproject.workPackages.services') }); }, + getRowsByWorkPackageIds: function(ids) { + var rows = []; + + angular.forEach(WorkPackagesTableService.getRows(), function(row) { + if (ids.indexOf(row.object.id) >= 0) { + rows.push(row); + } + }) + + return rows; + }, + getGroupBy: function() { return workPackagesTableData.groupBy; }, diff --git a/app/assets/javascripts/angular/work_packages/controllers/work-package-details-controller.js b/app/assets/javascripts/angular/work_packages/controllers/work-package-details-controller.js index f5036d09a3..cbeaae4381 100644 --- a/app/assets/javascripts/angular/work_packages/controllers/work-package-details-controller.js +++ b/app/assets/javascripts/angular/work_packages/controllers/work-package-details-controller.js @@ -48,6 +48,7 @@ angular.module('openproject.workPackages.controllers') precedes: "precedes", follows: "follows" }) +.constant('PERMITTED_MORE_MENU_ACTIONS', ['log_time', 'duplicate', 'move', 'delete']) .controller('WorkPackageDetailsController', [ '$scope', @@ -58,6 +59,7 @@ angular.module('openproject.workPackages.controllers') 'VISIBLE_LATEST', 'RELATION_TYPES', 'RELATION_IDENTIFIERS', + 'PERMITTED_MORE_MENU_ACTIONS', '$q', 'WorkPackagesHelper', 'PathHelper', @@ -67,7 +69,10 @@ angular.module('openproject.workPackages.controllers') 'ChildrenRelationsHandler', 'ParentRelationsHandler', 'WorkPackageService', - function($scope, $state, latestTab, workPackage, I18n, VISIBLE_LATEST, RELATION_TYPES, RELATION_IDENTIFIERS, $q, WorkPackagesHelper, PathHelper, UsersHelper, ConfigurationService, CommonRelationsHandler, ChildrenRelationsHandler, ParentRelationsHandler, WorkPackageService) { + 'WorkPackageContextMenuHelper', + 'WorkPackagesTableService', + '$window', + function($scope, $state, latestTab, workPackage, I18n, VISIBLE_LATEST, RELATION_TYPES, RELATION_IDENTIFIERS, PERMITTED_MORE_MENU_ACTIONS, $q, WorkPackagesHelper, PathHelper, UsersHelper, ConfigurationService, CommonRelationsHandler, ChildrenRelationsHandler, ParentRelationsHandler, WorkPackageService, WorkPackageContextMenuHelper, WorkPackagesTableService, $window) { $scope.$on('$stateChangeSuccess', function(event, toState){ latestTab.registerState(toState.name); }); @@ -155,6 +160,19 @@ angular.module('openproject.workPackages.controllers') $scope.author = workPackage.embedded.author; } + $scope.$watch('rows', function(newVal, oldVal) { + if (!$scope.workPackage) { return; } + + // More Menu + var workPackageRows = WorkPackagesTableService.getRowsByWorkPackageIds([$scope.workPackage.props.id]); + + if (workPackageRows && workPackageRows.length == 1) { + var rowObject = workPackageRows[0].object; + + $scope.permittedActions = WorkPackageContextMenuHelper.getPermittedActions([rowObject], PERMITTED_MORE_MENU_ACTIONS); + } + }); + $scope.toggleWatch = function() { $scope.toggleWatchLink .fetch({ ajax: $scope.toggleWatchLink.props }) @@ -186,12 +204,35 @@ angular.module('openproject.workPackages.controllers') window.location = "/work_packages/" + $scope.workPackage.props.id; }; - $scope.deleteSelectedWorkPackage = function() { + $scope.triggerMoreMenuAction = function(action, link) { + var actionLink; + + switch (action) { + case 'delete': + deleteSelectedWorkPackage(); + break; + case 'log_time': + actionLink = PathHelper.timeEntryNewPath($scope.workPackage.props.id); + break; + case 'duplicate': + actionLink = PathHelper.workPackageDuplicatePath($scope.workPackage.props.projectId, $scope.workPackage.props.id); + break; + case 'move': + actionLink = PathHelper.workPackageMovePath($scope.workPackage.props.id) + break; + } + + if (actionLink) { + $window.location.href = actionLink; + } + }; + + function deleteSelectedWorkPackage() { var promis = WorkPackageService.performBulkDelete([$scope.workPackage.props.id], true); promis.success(function(data, status) { $state.go('work-packages.list'); }); - }; + } } ]); diff --git a/public/templates/work_packages.list.details.html b/public/templates/work_packages.list.details.html index 9fc0778df9..adda146bc3 100644 --- a/public/templates/work_packages.list.details.html +++ b/public/templates/work_packages.list.details.html @@ -48,7 +48,7 @@
-