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
extract identifier handling into own controller
ulfertsbe366ce5d100
diff --git a/app/controllers/projects/identifier_controller.rb b/app/controllers/projects/identifier_controller.rbnew file mode 100644index 00000000000..13f20819ec4--- /dev/null+++ b/app/controllers/projects/identifier_controller.rb@@ -0,0 +1,50 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++class Projects::IdentifierController < ApplicationController+ before_action :find_project_by_project_id+ before_action :authorize++ def show; end++ def update+ service_call = Projects::UpdateService+ .new(user: current_user,+ model: @project)+ .call(identifier: permitted_params.project[:identifier])++ if service_call.success?+ flash[:notice] = I18n.t(:notice_successful_update)+ redirect_to project_settings_general_path(@project)+ else+ render action: 'show'+ end+ end+enddiff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rbindex 6846fc4297b..9cf9edf06c0 100644--- a/app/controllers/projects_controller.rb+++ b/app/controllers/projects_controller.rb@@ -69,20 +69,6 @@ class ProjectsController < ApplicationControllerrenderend- def update_identifier- service_call = Projects::UpdateService- .new(user: current_user,- model: @project)- .call(permitted_params.project)-- if service_call.success?- flash[:notice] = I18n.t(:notice_successful_update)- redirect_to project_settings_general_path(@project)- else- render action: 'identifier'- end- end-# Delete @projectdef destroyservice_call = ::Projects::ScheduleDeletionServicediff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rbindex 7dc5d701ee9..54e497f3acc 100644--- a/app/helpers/projects_helper.rb+++ b/app/helpers/projects_helper.rb@@ -85,7 +85,7 @@ module ProjectsHelperenddef project_more_menu_settings_item(project)- if User.current.allowed_to?({ controller: '/projects/settings/general', action: 'show' }, project)+ if User.current.allowed_to?({ controller: '/projects/settings/general', action: 'show', project_id: project.id }, project)[t(:label_project_settings),project_settings_general_path(project),{ class: 'icon-context icon-settings',diff --git a/app/views/projects/_toolbar.html.erb b/app/views/projects/_toolbar.html.erbindex 98c904544d6..8968d133490 100644--- a/app/views/projects/_toolbar.html.erb+++ b/app/views/projects/_toolbar.html.erb@@ -40,7 +40,7 @@ See COPYRIGHT and LICENSE files for more details.</li><% end %><li class="toolbar-item hidden-for-mobile">- <%= link_to identifier_project_path(@project), class: 'button' do %>+ <%= link_to project_identifier_path(@project), class: 'button' do %><%= op_icon('button--icon icon-edit') %><span class="button--text"><%= t('projects.settings.change_identifier') %></span><% end %>diff --git a/app/views/projects/identifier.html.erb b/app/views/projects/identifier/show.html.erbsimilarity index 94%rename from app/views/projects/identifier.html.erbrename to app/views/projects/identifier/show.html.erbindex c5668f08be7..8c8376c8245 100644--- a/app/views/projects/identifier.html.erb+++ b/app/views/projects/identifier/show.html.erb@@ -29,7 +29,9 @@ See COPYRIGHT and LICENSE files for more details.<%= error_messages_for @project %>-<%= form_for @project, url: { action: 'update_identifier' }, html: { class: 'danger-zone form -vertical' } do |f| %>+<%= form_for @project,+ url: project_identifier_path(@project),+ html: { class: 'danger-zone form -vertical' } do |f| %><section class="form--section"><h3 class="form--section-title"><%= t('project.identifier.title') %>@@ -57,7 +59,6 @@ See COPYRIGHT and LICENSE files for more details.</span></div>-<br><div class="form--field-instructions">diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex b38de5c008e..f2ce2eca6f1 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -77,7 +77,8 @@ OpenProject::AccessControl.map do |map|{'projects/settings/general': %i[show],'projects/settings/storage': %i[show],- 'projects/templated': %i[create destroy]+ 'projects/templated': %i[create destroy],+ 'projects/identifier': %i[show update]},require: :member,contract_actions: { projects: %i[update] }diff --git a/config/routes.rb b/config/routes.rbindex a8f193f6632..ae61d328a42 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -190,14 +190,12 @@ OpenProject::Application.routes.draw doresource :templated, only: %i[create destroy], controller: 'templated'resource :archive, only: %i[create destroy], controller: 'archive'+ resource :identifier, only: %i[show update], controller: 'identifier'endmember doget "settings", to: redirect('projects/%{id}/settings/general/') # rubocop:disable Style/FormatStringToken- get 'identifier', action: 'identifier'- patch 'identifier', action: 'update_identifier'-get :copypatch :typesdiff --git a/spec/features/projects/edit_settings_spec.rb b/spec/features/projects/edit_settings_spec.rbindex fac79775887..893a0f1874d 100644--- a/spec/features/projects/edit_settings_spec.rb+++ b/spec/features/projects/edit_settings_spec.rb@@ -72,7 +72,7 @@ describe 'Projects', 'editing settings', type: :feature, js: true doendit 'displays error messages on invalid input' do- visit identifier_project_path(project)+ visit project_identifier_path(project)fill_in 'project[identifier]', with: 'FOOO'click_on 'Update'