Merge pull request #5400 from opf/feature/25066/link-to-custom-fields-project-settings-from-work-package-list

Feature #25066 Add link to work package list

[ci skip]
pull/5427/head
Oliver Günther 8 years ago committed by GitHub
commit 900ded8427
  1. 4
      frontend/app/components/context-menus/settings-menu/settings-menu.controller.ts
  2. 4
      frontend/app/components/context-menus/settings-menu/settings-menu.service.html
  3. 11
      lib/api/v3/work_packages/work_package_collection_representer.rb
  4. 53
      spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb

@ -105,6 +105,10 @@ function SettingsDropdownMenuController($scope:IMyScope,
let form = states.table.form.value!; let form = states.table.form.value!;
let query = states.table.query.value!; let query = states.table.query.value!;
if (query.results && query.results.customFields) {
$scope.queryCustomFields = query.results.customFields;
}
$scope.saveQuery = function (event:JQueryEventObject) { $scope.saveQuery = function (event:JQueryEventObject) {
event.stopPropagation(); event.stopPropagation();
if (!query.id && allowQueryAction(event, 'updateImmediately')) { if (!query.id && allowQueryAction(event, 'updateImmediately')) {

@ -72,5 +72,9 @@
ng-class="{'inactive': showSettingsModalInvalid()}"> ng-class="{'inactive': showSettingsModalInvalid()}">
<i class="icon-action-menu icon-settings"></i>{{ I18n.t('js.toolbar.settings.page_settings') }}</a> <i class="icon-action-menu icon-settings"></i>{{ I18n.t('js.toolbar.settings.page_settings') }}</a>
</li> </li>
<li class="dropdown-divider" ng-if="queryCustomFields"></li>
<li><a class="menu-item" href="{{queryCustomFields.href}}" ng-if="queryCustomFields">
<i class="icon-action-menu icon-custom-fields"></i>{{ queryCustomFields.name }}</a>
</li>
</ul> </ul>
</div> </div>

@ -102,6 +102,17 @@ module API
} if represented.any? } if represented.any?
end end
link :customFields do
if project.present? &&
(current_user.try(:admin?) || current_user_allowed_to(:edit_project, context: project))
{
href: settings_project_path(project.identifier, tab: 'custom_fields'),
type: 'text/html',
title: I18n.t('label_custom_field_plural')
}
end
end
links :representations do links :representations do
representation_formats if current_user.allowed_to?(:export_work_packages, project, global: project.nil?) representation_formats if current_user.allowed_to?(:export_work_packages, project, global: project.nil?)
end end

@ -381,5 +381,58 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter do
.at_path('_embedded/schemas/_embedded/elements/0/_links/self/href') .at_path('_embedded/schemas/_embedded/elements/0/_links/self/href')
end end
end end
context 'with project admin priviliges' do
# In this spec a user responds to `allowed_to` with true per default.
let(:project) { FactoryGirl.build_stubbed(:project) }
it 'has a link to set the custom fields for that project' do
expected = {
href: "/projects/#{project.identifier}/settings/custom_fields",
type: "text/html",
title: "Custom fields"
}
is_expected
.to be_json_eql(expected.to_json)
.at_path('_links/customFields')
end
end
context 'without project admin priviliges' do
# In this spec a user responds to `allowed_to` with true per default.
let(:project) { FactoryGirl.build_stubbed(:project) }
before do
allow(user).to receive(:allowed_to?).with(:edit_project, project).and_return(false)
end
it 'has no link to set the custom fields for that project' do
is_expected.to_not have_json_path('_links/customFields')
end
end
context 'with project admin priviliges' do
# In this spec a user responds to `allowed_to` with true per default.
let(:project) { FactoryGirl.build_stubbed(:project) }
let(:user) { FactoryGirl.build_stubbed(:admin) }
before do
allow(user).to receive(:allowed_to?).with(:edit_project, project).and_return(false)
end
it 'has a link to set the custom fields for that project' do
expected = {
href: "/projects/#{project.identifier}/settings/custom_fields",
type: "text/html",
title: "Custom fields"
}
is_expected
.to be_json_eql(expected.to_json)
.at_path('_links/customFields')
end
end
end end
end end

Loading…
Cancel
Save