OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
introduce separate permission for selecting custom fields
ulfertsebcf9138cc97
diff --git a/app/controllers/project_settings/custom_fields_controller.rb b/app/controllers/projects/settings/custom_fields_controller.rbsimilarity index 64%rename from app/controllers/project_settings/custom_fields_controller.rbrename to app/controllers/projects/settings/custom_fields_controller.rbindex 223b13f6d44..47a565b5851 100644--- a/app/controllers/project_settings/custom_fields_controller.rb+++ b/app/controllers/projects/settings/custom_fields_controller.rb@@ -28,11 +28,31 @@# See COPYRIGHT and LICENSE files for more details.#++-class ProjectSettings::CustomFieldsController < ProjectSettingsController+class Projects::Settings::CustomFieldsController < ProjectSettingsControllermenu_item :settings_custom_fieldsdef show- @wp_custom_fields = WorkPackageCustomField.order("#{CustomField.table_name}.position")- render template: 'project_settings/custom_fields'+ @wp_custom_fields = WorkPackageCustomField.order(:position)+ end++ def update+ Project.transaction do+ if update_custom_fields+ flash[:notice] = t(:notice_successful_update)+ else+ flash[:error] = t(:notice_project_cannot_update_custom_fields,+ errors: @project.errors.full_messages.join(', '))+ raise ActiveRecord::Rollback+ end+ end++ redirect_to custom_fields_settings_project_path(@project)+ end++ private++ def update_custom_fields+ @project.work_package_custom_field_ids = permitted_params.project[:work_package_custom_field_ids]+ @project.saveendenddiff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rbindex 93a230d386f..515e6170693 100644--- a/app/controllers/projects_controller.rb+++ b/app/controllers/projects_controller.rb@@ -33,7 +33,7 @@ class ProjectsController < ApplicationControllermenu_item :roadmap, only: :roadmapbefore_action :find_project, except: %i[index level_list new]- before_action :authorize, only: %i[modules custom_fields copy]+ before_action :authorize, only: %i[copy]before_action :authorize_global, only: %i[new]before_action :require_admin, only: %i[archive unarchive destroy destroy_info]@@ -83,20 +83,6 @@ class ProjectsController < ApplicationControllerendend- def custom_fields- Project.transaction do- @project.work_package_custom_field_ids = permitted_params.project[:work_package_custom_field_ids]- if @project.save- flash[:notice] = t(:notice_successful_update)- else- flash[:error] = t(:notice_project_cannot_update_custom_fields,- errors: @project.errors.full_messages.join(', '))- raise ActiveRecord::Rollback- end- end- redirect_to settings_custom_fields_project_path(@project)- end-def archivechange_status_action(:archive)enddiff --git a/app/helpers/project_settings_helper.rb b/app/helpers/project_settings_helper.rbindex f8f1081e701..c12560da712 100644--- a/app/helpers/project_settings_helper.rb+++ b/app/helpers/project_settings_helper.rb@@ -49,7 +49,7 @@ module ProjectSettingsHelper},{name: 'custom_fields',- action: { controller: '/project_settings/custom_fields', action: 'show' },+ action: { controller: '/projects/settings/custom_fields', action: 'show' },label: :label_custom_field_plural},{diff --git a/app/views/projects/form/_custom_fields.html.erb b/app/views/projects/settings/custom_fields/_form.html.erbsimilarity index 100%rename from app/views/projects/form/_custom_fields.html.erbrename to app/views/projects/settings/custom_fields/_form.html.erbdiff --git a/app/views/project_settings/custom_fields.html.erb b/app/views/projects/settings/custom_fields/show.html.erbsimilarity index 84%rename from app/views/project_settings/custom_fields.html.erbrename to app/views/projects/settings/custom_fields/show.html.erbindex dfb25bcd980..ab3448e185b 100644--- a/app/views/project_settings/custom_fields.html.erb+++ b/app/views/projects/settings/custom_fields/show.html.erb@@ -43,18 +43,17 @@ See COPYRIGHT and LICENSE files for more details.<% end %><% end %>-<% if @wp_custom_fields.any? %>+<% if @wp_custom_fields.any? %><%= labelled_tabular_form_for @project,- url: { controller: '/projects', action: 'custom_fields', id: @project },- method: :put,+ url: custom_fields_settings_project_path(@project),html: { id: 'modules-form' } do |form| %>- <%= render partial: "projects/form/custom_fields",- locals: {- project: @project,- form: form,- work_package_custom_fields: @wp_custom_fields- } %>+ <%= render partial: 'form',+ locals: {+ project: @project,+ form: form,+ work_package_custom_fields: @wp_custom_fields+ } %><div class="generic-table--action-buttons"><%= form.button t(:button_save), class: 'button -highlight -with-icon icon-checkmark' %>diff --git a/app/views/projects/settings/modules/show.html.erb b/app/views/projects/settings/modules/show.html.erbindex 64d454bdbe1..4e5689b8c43 100644--- a/app/views/projects/settings/modules/show.html.erb+++ b/app/views/projects/settings/modules/show.html.erb@@ -34,8 +34,7 @@ See COPYRIGHT and LICENSE files for more details.<%= error_messages_for_contract(@project, @errors) %><%= labelled_tabular_form_for @project,- url: modules_settings_project_path(@project),- method: :patch do |form| %>+ url: modules_settings_project_path(@project) do |form| %><%= render partial: "form",locals: { form: form } %>diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex 5c59c483018..b6cb43569e2 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -112,6 +112,12 @@ OpenProject::AccessControl.map do |map|},require: :member+ map.permission :select_custom_fields,+ {+ 'projects/settings/custom_fields': %i[show update]+ },+ require: :member+map.permission :add_subprojects,{ projects: %i[new] },require: :memberdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 43b09a0729e..eb488b7368b 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2225,6 +2225,7 @@ en:permission_protect_wiki_pages: "Protect wiki pages"permission_rename_wiki_pages: "Rename wiki pages"permission_save_queries: "Save views"+ permission_select_custom_fields: "Select custom fields"permission_select_project_modules: "Select project modules"permission_manage_types: "Select types"permission_view_calendar: "View calendar"diff --git a/config/routes.rb b/config/routes.rbindex b14ead3e1f3..a45d3d3d97f 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -184,7 +184,7 @@ OpenProject::Application.routes.draw donamespace 'settings' doProjectSettingsHelper.project_settings_tabs- .select { |s| %w[modules general types].include?(s[:name]) }+ .select { |s| %w[modules general types custom_fields].include?(s[:name]) }.each do |tab|get tab[:name],controller: tab[:name],@@ -198,7 +198,7 @@ OpenProject::Application.routes.draw doProjectSettingsHelper.project_settings_tabs- .reject { |s| %w[modules general types].include?(s[:name]) }+ .reject { |s| %w[modules general types custom_fields].include?(s[:name]) }.each do |tab|get "settings/#{tab[:name]}",controller: "project_settings/#{tab[:name]}",@@ -216,7 +216,6 @@ OpenProject::Application.routes.draw doget :copy- put :custom_fieldsput :archiveput :unarchivepatch :typesdiff --git a/lib/api/v3/work_packages/create_form_representer.rb b/lib/api/v3/work_packages/create_form_representer.rbindex 8b89b8f6425..54ba13ddba0 100644--- a/lib/api/v3/work_packages/create_form_representer.rb+++ b/lib/api/v3/work_packages/create_form_representer.rb@@ -72,7 +72,7 @@ module APIcurrent_user_allowed_to(:edit_project,context: represented.project)){- href: settings_custom_fields_project_path(represented.project.identifier),+ href: custom_fields_settings_project_path(represented.project.identifier),type: 'text/html',title: I18n.t('label_custom_field_plural')}diff --git a/lib/api/v3/work_packages/create_project_form_representer.rb b/lib/api/v3/work_packages/create_project_form_representer.rbindex 7fbb7cdfc52..521d303670b 100644--- a/lib/api/v3/work_packages/create_project_form_representer.rb+++ b/lib/api/v3/work_packages/create_project_form_representer.rb@@ -69,7 +69,7 @@ module APIcurrent_user_allowed_to(:edit_project,context: represented.project){- href: settings_custom_fields_project_path(represented.project.identifier),+ href: custom_fields_settings_project_path(represented.project.identifier),type: 'text/html',title: I18n.t('label_custom_field_plural')}diff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rbindex 01c1e353ca9..269e9576070 100644--- a/lib/api/v3/work_packages/work_package_collection_representer.rb+++ b/lib/api/v3/work_packages/work_package_collection_representer.rb@@ -115,7 +115,7 @@ module APIif project.present? &&(current_user.try(:admin?) || current_user_allowed_to(:edit_project, context: project)){- href: settings_custom_fields_project_path(project.identifier),+ href: custom_fields_settings_project_path(project.identifier),type: 'text/html',title: I18n.t('label_custom_field_plural')}diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rbindex ea4885cb112..39b4564d581 100644--- a/lib/api/v3/work_packages/work_package_representer.rb+++ b/lib/api/v3/work_packages/work_package_representer.rb@@ -147,7 +147,7 @@ module APInext if represented.project.nil?{- href: settings_custom_fields_project_path(represented.project.identifier),+ href: custom_fields_settings_project_path(represented.project.identifier),type: 'text/html',title: "Custom fields"}diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rbindex 906f788f902..119fa5c9186 100644--- a/spec/controllers/projects_controller_spec.rb+++ b/spec/controllers/projects_controller_spec.rb@@ -124,52 +124,6 @@ describe ProjectsController, type: :controller doendend- describe 'settings' do- describe '#custom_fields' do- let(:project) { FactoryBot.create(:project) }- let(:custom_field_1) { FactoryBot.create(:work_package_custom_field) }- let(:custom_field_2) { FactoryBot.create(:work_package_custom_field) }-- let(:params) do- {- id: project.id,- project: {- work_package_custom_field_ids: [custom_field_1.id, custom_field_2.id]- }- }- end-- let(:request) { put :custom_fields, params: params }-- context 'with valid project' do- before do- request- end-- it { expect(response).to redirect_to(controller: '/project_settings/custom_fields', id: project, action: 'show') }-- it 'sets flash[:notice]' do- expect(flash[:notice]).to eql(I18n.t(:notice_successful_update))- end- end-- context 'with invalid project' do- before do- allow_any_instance_of(Project).to receive(:save).and_return(false)- request- end-- it { expect(response).to redirect_to(controller: '/project_settings/custom_fields', id: project, action: 'show') }-- it 'sets flash[:error]' do- expect(flash[:error]).to include(- "You cannot update the project's available custom fields. The project is invalid:"- )- end- end- end- end-describe '#destroy' dorender_viewsdiff --git a/spec/features/projects/copy_spec.rb b/spec/features/projects/copy_spec.rbindex 1f743a0bd2a..cb2781af263 100644--- a/spec/features/projects/copy_spec.rb+++ b/spec/features/projects/copy_spec.rb@@ -76,7 +76,7 @@ describe 'Projects copy',FactoryBot.create(:role,permissions: permissions)end- let(:permissions) { %i(copy_projects edit_project add_subprojects manage_types view_work_packages) }+ let(:permissions) { %i(copy_projects edit_project add_subprojects manage_types view_work_packages select_custom_fields) }let(:wp_user) douser = FactoryBot.create(:user)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.rbindex 5e47361252f..5ac37c1a892 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@@ -1043,7 +1043,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doit_behaves_like 'action link' dolet(:action) { 'customFields' }let(:permission) { :edit_project }- let(:href) { settings_custom_fields_project_path(work_package.project.identifier) }+ let(:href) { custom_fields_settings_project_path(work_package.project.identifier) }endenddiff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rbindex 74eb3ac7063..e53f68f75f4 100644--- a/spec/routing/project_routing_spec.rb+++ b/spec/routing/project_routing_spec.rb@@ -82,26 +82,16 @@ describe ProjectsController, type: :routing dodescribe 'templated' doit doexpect(delete('/projects/123/templated'))- .to route_to(- controller: 'projects/templated', action: 'destroy', id: '123'- )+ .to route_to(controller: 'projects/templated', action: 'destroy', id: '123')endit doexpect(post('/projects/123/templated'))- .to route_to(- controller: 'projects/templated', action: 'create', id: '123'- )+ .to route_to(controller: 'projects/templated', action: 'create', id: '123')endenddescribe 'miscellaneous' do- it do- expect(put('projects/123/custom_fields')).to route_to(- controller: 'projects', action: 'custom_fields', id: '123'- )- end-it doexpect(put('projects/123/archive')).to route_to(controller: 'projects', action: 'archive', id: '123'diff --git a/spec/routing/project_settings_routing_spec.rb b/spec/routing/project_settings_routing_spec.rbindex 7be641fb86d..c8fbba88c2a 100644--- a/spec/routing/project_settings_routing_spec.rb+++ b/spec/routing/project_settings_routing_spec.rb@@ -31,58 +31,80 @@ require 'spec_helper'describe ProjectSettingsController, type: :routing dodescribe 'show' doit do- expect(get('/projects/123/settings/general')).to route_to(- controller: 'project_settings/general', action: 'show', id: '123'- )+ expect(get('/projects/123/settings/general'))+ .to route_to(+ controller: 'projects/settings/general', action: 'show', id: '123'+ )endit do- expect(get('/projects/123/settings/modules')).to route_to(- controller: 'project_settings/modules', action: 'show', id: '123'- )+ expect(get('/projects/123/settings/modules'))+ .to route_to(+ controller: 'projects/settings/modules', action: 'show', id: '123'+ )endit doexpect(patch('/projects/123/settings/modules')).to route_to(- controller: 'project_settings/modules', action: 'update', id: '123'+ controller: 'projects/settings/modules', action: 'update', id: '123'+ )+ end++ it do+ expect(get('/projects/123/settings/custom_fields'))+ .to route_to(+ controller: 'projects/settings/custom_fields', action: 'show', id: '123'+ )+ end++ it do+ expect(patch('/projects/123/settings/custom_fields'))+ .to route_to(+ controller: 'projects/settings/custom_fields', action: 'update', id: '123')endit do- expect(get('/projects/123/settings/custom_fields')).to route_to(- controller: 'project_settings/custom_fields', action: 'show', id: '123'- )+ expect(get('/projects/123/settings/versions'))+ .to route_to(+ controller: 'project_settings/versions', action: 'show', id: '123'+ )endit do- expect(get('/projects/123/settings/versions')).to route_to(- controller: 'project_settings/versions', action: 'show', id: '123'- )+ expect(get('/projects/123/settings/categories'))+ .to route_to(+ controller: 'project_settings/categories', action: 'show', id: '123'+ )endit do- expect(get('/projects/123/settings/categories')).to route_to(- controller: 'project_settings/categories', action: 'show', id: '123'- )+ expect(get('/projects/123/settings/repository'))+ .to route_to(+ controller: 'project_settings/repository', action: 'show', id: '123'+ )endit do- expect(get('/projects/123/settings/repository')).to route_to(- controller: 'project_settings/repository', action: 'show', id: '123'- )+ expect(get('/projects/123/settings/activities'))+ .to route_to(+ controller: 'project_settings/activities', action: 'show', id: '123'+ )endit do- expect(get('/projects/123/settings/activities')).to route_to(- controller: 'project_settings/activities', action: 'show', id: '123'- )+ expect(get('/projects/123/settings/types'))+ .to route_to(+ controller: 'projects/settings/types', action: 'show', id: '123'+ )endit do- expect(get('/projects/123/settings/types')).to route_to(- controller: 'project_settings/types', action: 'show', id: '123'- )+ expect(patch('/projects/123/settings/types'))+ .to route_to(+ controller: 'projects/settings/types', action: 'update', id: '123'+ )endendend