From 356791492ef78e8e5cf109a1ad73656c676cdea7 Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Thu, 4 Dec 2014 14:27:52 +0100 Subject: [PATCH] fix watcher selection * path was wrong * elements are now embedded. Adaptation in frontend required for that * link to availableWatchers was always presented. Changing that need handling in frontend --- doc/apiv3-documentation.apib | 24 +++++++++---------- .../details-tab-watchers-controller.js | 12 +++++++--- lib/api/v3/utilities/path_helper.rb | 2 +- .../work_packages/work_package_representer.rb | 2 +- spec/lib/api/v3/utilities/path_helper_spec.rb | 2 +- .../work_package_representer_spec.rb | 7 ++++++ 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/doc/apiv3-documentation.apib b/doc/apiv3-documentation.apib index e8c20fe05a..920bb59bf4 100644 --- a/doc/apiv3-documentation.apib +++ b/doc/apiv3-documentation.apib @@ -1882,18 +1882,18 @@ Note that due to sharing this might be more than the versions *defined* by that ## Linked Properties: -| Link | Description | Type | Constraints | Supported operations | Condition | -| :------------: | --------------------------------------------------------- | ----------- | ----------- | -------------------- | -------------------------------- | -| self | This work package | WorkPackage | not null | READ | | -| author | The person that created the work package | User | not null | READ | | -| assignee | The person that is intended to work on the work package | User | | READ / WRITE | | -| availableWatchers | All users that can be added to the work package as watchers. | User | | READ | | -| category | The category of the work package | Category | | READ / WRITE | | -| priority | The priority of the work package | Priority | not null | READ / WRITE | | -| responsible | The person that is responsible for the overall outcome | User | | READ / WRITE | | -| status | The current status of the work package | Status | not null | READ / WRITE | | -| timeEntries | All time entries logged on the work package. Please note that this is a link to an HTML resource for now and as such, the link is subject to change. | N/A | | READ | **Permission** view time entries | -| version | The version associated to the work package | Version | | READ / WRITE | | +| Link | Description | Type | Constraints | Supported operations | Condition | +| :------------: | --------------------------------------------------------- | ----------- | ----------- | -------------------- | -------------------------------- | +| self | This work package | WorkPackage | not null | READ | | +| author | The person that created the work package | User | not null | READ | | +| assignee | The person that is intended to work on the work package | User | | READ / WRITE | | +| availableWatchers | All users that can be added to the work package as watchers. | User | | READ | **Permission** add work package watchers | +| category | The category of the work package | Category | | READ / WRITE | | +| priority | The priority of the work package | Priority | not null | READ / WRITE | | +| responsible | The person that is responsible for the overall outcome | User | | READ / WRITE | | +| status | The current status of the work package | Status | not null | READ / WRITE | | +| timeEntries | All time entries logged on the work package. Please note that this is a link to an HTML resource for now and as such, the link is subject to change. | N/A | | READ | **Permission** view time entries | +| version | The version associated to the work package | Version | | READ / WRITE | | ## Properties: diff --git a/frontend/app/work_packages/controllers/details-tab-watchers-controller.js b/frontend/app/work_packages/controllers/details-tab-watchers-controller.js index cd6edab7e3..9f60f3d0fd 100644 --- a/frontend/app/work_packages/controllers/details-tab-watchers-controller.js +++ b/frontend/app/work_packages/controllers/details-tab-watchers-controller.js @@ -67,13 +67,19 @@ module.exports = function($scope, $filter, $timeout, I18n, ADD_WATCHER_SELECT_IN } function fetchAvailableWatchers() { + if ($scope.workPackage.links.availableWatchers === undefined) { + $scope.availableWatchers = []; + return; + } + $scope.workPackage.links.availableWatchers .fetch() .then(function(data) { // Temporarily filter out watchers already assigned to the work package on the client-side - $scope.availableWatchers = getFilteredCollection(data.embedded.availableWatchers, $scope.watchers); - // TODO do filtering on the API side and replace the update of the available watchers with the code provided in the following line - // $scope.availableWatchers = data.embedded.availableWatchers; + $scope.availableWatchers = getFilteredCollection(data.embedded.elements, $scope.watchers); + // TODO do filtering on the API side and replace the update of the + // available watchers with the code provided in the following line + // $scope.availableWatchers = data.embedded.elements; }); } diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb index a9473ed16d..cee304e40c 100644 --- a/lib/api/v3/utilities/path_helper.rb +++ b/lib/api/v3/utilities/path_helper.rb @@ -55,7 +55,7 @@ module API end def self.available_watchers(work_package_id) - "#{work_package(work_package_id)}/watchers" + "#{work_package(work_package_id)}/available_watchers" end def self.categories(project_id) diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rb index 19c630fc96..e7fb0139b1 100644 --- a/lib/api/v3/work_packages/work_package_representer.rb +++ b/lib/api/v3/work_packages/work_package_representer.rb @@ -137,7 +137,7 @@ module API { href: api_v3_paths.available_watchers(represented.id), title: 'Available Watchers' - } + } if current_user_allowed_to(:add_work_package_watchers) end link :watchChanges do diff --git a/spec/lib/api/v3/utilities/path_helper_spec.rb b/spec/lib/api/v3/utilities/path_helper_spec.rb index bc7e780151..045a042aeb 100644 --- a/spec/lib/api/v3/utilities/path_helper_spec.rb +++ b/spec/lib/api/v3/utilities/path_helper_spec.rb @@ -78,7 +78,7 @@ describe ::API::V3::Utilities::PathHelper do it_behaves_like 'api v3 path' - it { is_expected.to match(/^\/api\/v3\/work_packages\/42\/watchers/) } + it { is_expected.to match(/^\/api\/v3\/work_packages\/42\/available_watchers/) } end describe '#categories' do diff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb index 61f8ca4609..91959dd41a 100644 --- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb @@ -457,6 +457,13 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do let(:permission) { :manage_subtasks } end end + + describe 'availableWatchers' do + it_behaves_like 'action link' do + let(:action) { 'availableWatchers' } + let(:permission) { :add_work_package_watchers } + end + end end describe '_embedded' do