Respect user permissions in more menu

pull/1782/head
Hagen Schink 10 years ago
parent 579528d6ea
commit 0667c75c5b
  1. 12
      app/assets/javascripts/angular/services/work-packages-table-service.js
  2. 47
      app/assets/javascripts/angular/work_packages/controllers/work-package-details-controller.js
  3. 31
      public/templates/work_packages.list.details.html

@ -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;
},

@ -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');
});
};
}
}
]);

@ -48,7 +48,7 @@
<div class="work-packages--details-toolbar">
<button class="button" ng-click="editWorkPackage()"><i class="icon-left icon-edit"></i>{{ I18n.t('js.button_edit') }}</button>
<button class="button"
<button class="button dropdown-relative"
with-dropdown
dropdown-id="moreDropdown">
{{ I18n.t('js.button_more') }}
@ -58,28 +58,13 @@
<div class="dropdown dropdown-relative dropdown-anchor-right dropdown-up" id="moreDropdown">
<ul class="dropdown-menu">
<li>
<a href="{{ PathHelper.timeEntryNewPath(workPackage.props.id) }}">
<i class="icon-time"></i>
Log time
</a>
</li>
<li>
<a href="{{ PathHelper.workPackageDuplicatePath(workPackage.props.projectId, workPackage.props.id) }}">
<i class="icon-duplicate"></i>
Duplicate
</a>
</li>
<li>
<a href="{{ PathHelper.workPackageMovePath(workPackage.props.id) }}">
<i class="icon-move"></i>
Move
</a>
</li>
<li>
<a href ng-click="deleteSelectedWorkPackage()">
<i class="icon-delete"></i>
Delete
<li ng-repeat="(action, link) in permittedActions"
ng-click="triggerMoreMenuAction(action, link)"
class="{{action}}">
<a href
ng-class="['icon-context', 'icon-' + action]"
ng-click="deleteWorkPackages()"
ng-bind="I18n.t('js.button_' + action)">
</a>
</li>
</ul>

Loading…
Cancel
Save