Skip to content

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

Move project_settings_path to ApplicationHelper to be globally available and start adapting tests to new structure

Henriette Dingercbc530ca9db0
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index b55292988a6..45a4bc28316 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -43,6 +43,7 @@ class ApplicationController < ActionController::Base
include Redmine::I18n
include HookHelper
include ErrorsHelper
+ include ApplicationHelper
include ::OpenProject::Authentication::SessionExpiry
include AdditionalUrlHelpers
include OpenProjectErrorHelper
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index db6342cc6fa..8d8eea83977 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -47,7 +47,7 @@ class CategoriesController < ApplicationController
respond_to do |format|
format.html do
flash[:notice] = l(:notice_successful_create)
- redirect_to controller: '/project_settings', action: 'show', tab: 'categories', id: @project
+ redirect_to settings_project_path(@project, tab: 'categories')
end
format.js do
render locals: { project: @project, category: @category }
@@ -69,7 +69,7 @@ class CategoriesController < ApplicationController
@category.attributes = permitted_params.category
if @category.save
flash[:notice] = l(:notice_successful_update)
- redirect_to controller: '/project_settings', action: 'show', tab: 'categories', id: @project
+ redirect_to settings_project_path(@project, tab: 'categories')
else
render action: 'edit'
end
@@ -80,12 +80,12 @@ class CategoriesController < ApplicationController
if @issue_count == 0
# No issue assigned to this category
@category.destroy
- redirect_to controller: '/project_settings', action: 'show', id: @project, tab: 'categories'
+ redirect_to settings_project_path(@project, tab: 'categories')
return
elsif params[:todo]
reassign_to = @project.categories.find_by(id: params[:reassign_to_id]) if params[:todo] == 'reassign'
@category.destroy(reassign_to)
- redirect_to controller: '/project_settings', action: 'show', id: @project, tab: 'categories'
+ redirect_to settings_project_path(@project, tab: 'categories')
return
end
@categories = @project.categories - [@category]
diff --git a/app/controllers/project_enumerations_controller.rb b/app/controllers/project_enumerations_controller.rb
index 9a35834c477..45b331bba06 100644
--- a/app/controllers/project_enumerations_controller.rb
+++ b/app/controllers/project_enumerations_controller.rb
@@ -42,7 +42,7 @@ class ProjectEnumerationsController < ApplicationController
flash[:notice] = l(:notice_successful_update)
end
- redirect_to settings_project_path(id: @project, tab: 'activities')
+ redirect_to settings_project_path(@project, tab: 'activities')
end
def destroy
@@ -50,6 +50,6 @@ class ProjectEnumerationsController < ApplicationController
flash[:notice] = l(:notice_successful_update)
- redirect_to settings_project_path(id: @project, tab: 'activities')
+ redirect_to settings_project_path(@project, tab: 'activities')
end
end
diff --git a/app/controllers/project_settings_controller.rb b/app/controllers/project_settings_controller.rb
index bf668033fcb..bbd3b8b594d 100644
--- a/app/controllers/project_settings_controller.rb
+++ b/app/controllers/project_settings_controller.rb
@@ -34,6 +34,7 @@ class ProjectSettingsController < ApplicationController
def show; end
private
+
def find_project
@project = Project.find(params[:id])
rescue ActiveRecord::RecordNotFound
diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb
index 84f0bf20f91..9257bb612a7 100644
--- a/app/controllers/versions_controller.rb
+++ b/app/controllers/versions_controller.rb
@@ -103,7 +103,7 @@ class VersionsController < ApplicationController
if request.put?
@project.close_completed_versions
end
- redirect_to settings_project_path(tab: 'versions', id: @project)
+ redirect_to settings_project_path(@project, tab: 'versions')
end
def destroy
@@ -116,13 +116,13 @@ class VersionsController < ApplicationController
flash[:error] = call.errors.full_messages
end
- redirect_to settings_project_path(tab: 'versions', id: @project)
+ redirect_to settings_project_path(@project, tab: 'versions')
end
private
def redirect_back_or_version_settings
- redirect_back_or_default(settings_project_path(tab: 'versions', id: @project))
+ redirect_back_or_default(settings_project_path(@project, tab: 'versions'))
end
def find_project
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 271307ce1a6..a53c4c8f37b 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -527,4 +527,12 @@ module ApplicationHelper
s += raw '<br /><em>' + rules + '</em>' unless rules.empty?
s
end
+
+ def settings_project_path(project, opts = {})
+ if opts[:tab]
+ url_for controller: "project_settings/#{opts[:tab]}", action: 'show', only_path: true, id: project
+ else
+ url_for controller: "project_settings/generic", action: 'show', only_path: true, id: project
+ end
+ end
end
diff --git a/app/helpers/project_settings_helper.rb b/app/helpers/project_settings_helper.rb
index 2427b4a79ad..0a1b5d6428a 100644
--- a/app/helpers/project_settings_helper.rb
+++ b/app/helpers/project_settings_helper.rb
@@ -31,7 +31,7 @@
module ProjectSettingsHelper
extend self
def project_settings_tabs
- tabs = [
+ [
{
name: 'generic',
action: { controller: '/project_settings/generic', action: 'show' },
@@ -74,5 +74,4 @@ module ProjectSettingsHelper
}
]
end
-
end
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 2e8c3296682..730f42e4ffb 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -41,14 +41,6 @@ module ProjectsHelper
html_options
end
- def settings_project_path(project, opts = {})
- if opts[:tab]
- url_for controller: "project_settings/#{opts[:tab]}", action: 'show', only_path: true, id: project
- else
- url_for controller: "project_settings", action: 'show', only_path: true, id: project
- end
- end
-
# Returns a set of options for a select field, grouped by project.
def version_options_for_select(versions, selected = nil)
grouped = Hash.new { |h, k| h[k] = [] }
@@ -115,9 +107,9 @@ module ProjectsHelper
end
def project_more_menu_settings_item(project)
- if User.current.allowed_to?({ controller: '/project_settings', action: 'show' }, project)
+ if User.current.allowed_to?({ controller: '/project_settings/generic', action: 'show' }, project)
[t(:label_project_settings),
- { controller: '/project_settings', action: 'show', id: project },
+ { controller: '/project_settings/generic', action: 'show', id: project },
class: 'icon-context icon-settings',
title: t(:label_project_settings)]
end
diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb
index 690d6009d10..dfd69cee82e 100644
--- a/app/helpers/repositories_helper.rb
+++ b/app/helpers/repositories_helper.rb
@@ -249,10 +249,9 @@ module RepositoriesHelper
scm_options(repository),
class: 'form--select repositories--remote-select',
data: {
- url: url_for(controller: '/project_settings',
+ url: url_for(controller: '/project_settings/repository',
action: 'show',
- tab: 'repository',
- project_id: @project.id),
+ id: @project.id),
},
disabled: (repository && !repository.new_record?)
)
diff --git a/config/routes.rb b/config/routes.rb
index 422836deaee..1d52449062e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -175,8 +175,6 @@ OpenProject::Application.routes.draw do
get "settings/#{tab[:name]}", controller: "project_settings/#{tab[:name]}", action: 'show', as: "settings_#{tab[:name]}"
end
- get 'settings', controller: 'project_settings/generic', action: 'show', as: :settings
-
get 'identifier', action: 'identifier'
patch 'identifier', action: 'update_identifier'
diff --git a/lib/api/v3/work_packages/create_form_representer.rb b/lib/api/v3/work_packages/create_form_representer.rb
index 7ec252c28b5..93674552ab0 100644
--- a/lib/api/v3/work_packages/create_form_representer.rb
+++ b/lib/api/v3/work_packages/create_form_representer.rb
@@ -31,6 +31,7 @@ module API
module V3
module WorkPackages
class CreateFormRepresenter < FormRepresenter
+ include ApplicationHelper
link :self do
{
href: api_v3_paths.create_work_package_form,
diff --git a/lib/api/v3/work_packages/create_project_form_representer.rb b/lib/api/v3/work_packages/create_project_form_representer.rb
index d70922e0608..073f00500d9 100644
--- a/lib/api/v3/work_packages/create_project_form_representer.rb
+++ b/lib/api/v3/work_packages/create_project_form_representer.rb
@@ -31,6 +31,7 @@ module API
module V3
module WorkPackages
class CreateProjectFormRepresenter < FormRepresenter
+ include ApplicationHelper
link :self do
{
href: api_v3_paths.create_project_work_package_form(represented.project_id),
diff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rb
index 5b951309b22..915150492ed 100644
--- a/lib/api/v3/work_packages/work_package_collection_representer.rb
+++ b/lib/api/v3/work_packages/work_package_collection_representer.rb
@@ -32,6 +32,7 @@ module API
module V3
module WorkPackages
class WorkPackageCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection
+ include ApplicationHelper
element_decorator ::API::V3::WorkPackages::WorkPackageRepresenter
def initialize(models,
diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rb
index cfef6d35f65..4ac9339bc15 100644
--- a/lib/api/v3/work_packages/work_package_representer.rb
+++ b/lib/api/v3/work_packages/work_package_representer.rb
@@ -37,6 +37,7 @@ module API
include API::Decorators::FormattableProperty
include API::Caching::CachedRepresenter
include ::API::V3::Attachments::AttachableRepresenterMixin
+ include ApplicationHelper
extend ::API::V3::Utilities::CustomFieldInjector::RepresenterClass
cached_representer key_parts: %i(project),
diff --git a/modules/backlogs/lib/open_project/backlogs/engine.rb b/modules/backlogs/lib/open_project/backlogs/engine.rb
index b550a7e0209..da63734611f 100644
--- a/modules/backlogs/lib/open_project/backlogs/engine.rb
+++ b/modules/backlogs/lib/open_project/backlogs/engine.rb
@@ -121,16 +121,16 @@ module OpenProject::Backlogs
# We still override version and project settings views from the core! URH
override_core_views!
- patches [:PermittedParams,
- :WorkPackage,
- :Status,
- :Type,
- :Project,
- :ProjectsController,
- :ProjectSettingsHelper,
- :User,
- :VersionsController,
- :Version]
+ patches %i[PermittedParams
+ WorkPackage
+ Status
+ Type
+ Project
+ ProjectsController
+ ProjectSettingsHelper
+ User
+ VersionsController
+ Version]
patch_with_namespace :API, :V3, :WorkPackages, :Schema, :SpecificWorkPackageSchema
patch_with_namespace :BasicData, :SettingSeeder
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 59291d4aaab..c70a42511f1 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -159,7 +159,7 @@ describe ProjectsController, type: :controller do
end
it 'redirects to settings#types' do
- expect(response).to redirect_to(settings_project_path(project.identifier, tab: 'types'))
+ expect(response).to redirect_to(controller: '/project_settings/types', id: project, action: 'show')
end
end
@@ -179,7 +179,7 @@ describe ProjectsController, type: :controller do
end
it 'redirects to settings#types' do
- expect(response).to redirect_to(settings_project_path(project.identifier, tab: 'types'))
+ expect(response).to redirect_to(controller: '/project_settings/types', id: project, action: 'show')
end
end
end
@@ -237,7 +237,7 @@ describe ProjectsController, type: :controller do
request
end
- it { expect(response).to redirect_to(settings_project_path(project, 'custom_fields')) }
+ 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))
@@ -250,7 +250,7 @@ describe ProjectsController, type: :controller do
request
end
- it { expect(response).to redirect_to(settings_project_path(project, 'custom_fields')) }
+ 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(
diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb
index e46c4fc2039..bd963e19a7e 100644
--- a/spec/controllers/repositories_controller_spec.rb
+++ b/spec/controllers/repositories_controller_spec.rb
@@ -75,7 +75,7 @@ describe RepositoriesController, type: :controller do
end
it 'redirects to settings' do
- expect(response).to redirect_to(settings_project_path(project, tab: 'repository'))
+ expect(response).to redirect_to(controller: '/project_settings/repository', id: project.identifier, action: 'show')
end
end
@@ -85,7 +85,7 @@ describe RepositoriesController, type: :controller do
end
it 'redirects to settings' do
- expect(response).to redirect_to(controller: '/project_settings', id: project.identifier, action: 'show', tab: 'repository')
+ expect(response).to redirect_to(controller: '/project_settings/repository', id: project.identifier, action: 'show')
end
end
@@ -101,7 +101,7 @@ describe RepositoriesController, type: :controller do
end
it 'redirects to settings' do
- expect(response).to redirect_to(controller: '/project_settings', id: project.identifier, action: 'show', tab: 'repository')
+ expect(response).to redirect_to(controller: '/project_settings/repository', id: project.identifier, action: 'show')
end
end
end
diff --git a/spec/features/categories/categories_page.rb b/spec/features/categories/categories_page.rb
index a511e4e1d75..7d12148da20 100644
--- a/spec/features/categories/categories_page.rb
+++ b/spec/features/categories/categories_page.rb
@@ -35,6 +35,6 @@ class CategoriesPage
end
def visit_settings
- visit(settings_project_path(@project) + '/categories')
+ visit(settings_project_path(@project, tab: 'categories'))
end
end
diff --git a/spec/features/projects/projects_custom_fields_spec.rb b/spec/features/projects/projects_custom_fields_spec.rb
index 3f9674cce89..4517e743aa7 100644
--- a/spec/features/projects/projects_custom_fields_spec.rb
+++ b/spec/features/projects/projects_custom_fields_spec.rb
@@ -61,7 +61,7 @@ describe 'Projects custom fields', type: :feature do
let(:editor) { ::Components::WysiwygEditor.new ".form--field.custom_field_#{custom_field.id}" }
scenario 'allows settings the project boolean CF (regression #26313)', js: true do
- visit settings_project_path(id: project.id)
+ visit settings_project_path(project.id)
# expect CF, description and status description ckeditor
expect(page).to have_selector('.op-ckeditor--wrapper', count: 3)
@@ -88,7 +88,7 @@ describe 'Projects custom fields', type: :feature do
end
scenario 'allows settings the project boolean CF (regression #26313)', js: true do
- visit settings_project_path(id: project.id)
+ visit settings_project_path(project.id)
expect(page).to have_no_checked_field identifier
check identifier
diff --git a/spec/features/projects/projects_spec.rb b/spec/features/projects/projects_spec.rb
index d70f9a73d1b..fe06c2fae2e 100644
--- a/spec/features/projects/projects_spec.rb
+++ b/spec/features/projects/projects_spec.rb
@@ -29,6 +29,7 @@
require 'spec_helper'
describe 'Projects', type: :feature do
+ include ApplicationHelper
let(:current_user) { FactoryBot.create(:admin) }
before do
@@ -159,7 +160,7 @@ describe 'Projects', type: :feature do
click_on 'Update'
expect(page).to have_content 'Successful update.'
- expect(current_path).to eq '/projects/foo-bar/settings'
+ expect(current_path).to eq '/projects/foo-bar/settings/generic'
expect(Project.first.identifier).to eq 'foo-bar'
end
@@ -205,7 +206,7 @@ describe 'Projects', type: :feature do
project.custom_field_values.last.value = 'FOO'
project.save!
- visit settings_project_path(id: project.id, tab: 'info')
+ visit settings_project_path(project.id)
expect(page).to have_content 'Required Foo'
expect(page).to have_content 'Optional Foo'
diff --git a/spec/features/repositories/repository_settings_page.rb b/spec/features/repositories/repository_settings_page.rb
index 1edf0c43111..ebda47ce2d8 100644
--- a/spec/features/repositories/repository_settings_page.rb
+++ b/spec/features/repositories/repository_settings_page.rb
@@ -27,6 +27,7 @@
#++
class RepositorySettingsPage
+ include ApplicationHelper
include Rails.application.routes.url_helpers
include Capybara::DSL
@@ -35,7 +36,7 @@ class RepositorySettingsPage
end
def repository_settings_path
- settings_project_path(id: @project.id, tab: 'repository')
+ settings_project_path(@project.id, tab: 'repository')
end
def visit_repository_settings
diff --git a/spec/support/pages/projects/settings.rb b/spec/support/pages/projects/settings.rb
index ac6698601ad..be8a9ab942a 100644
--- a/spec/support/pages/projects/settings.rb
+++ b/spec/support/pages/projects/settings.rb
@@ -31,6 +31,7 @@ require 'support/pages/page'
module Pages
module Projects
class Settings < Pages::Page
+ include ApplicationHelper
attr_accessor :project
def initialize(project)
diff --git a/spec/views/projects/settings.html.erb_spec.rb b/spec/views/projects/settings.html.erb_spec.rb
index 19898e09b9c..dc63b326a97 100644
--- a/spec/views/projects/settings.html.erb_spec.rb
+++ b/spec/views/projects/settings.html.erb_spec.rb
@@ -28,13 +28,13 @@
require 'spec_helper'
-describe 'project_settings/show', type: :view do
+describe 'project_settings/generic', type: :view do
let(:project) { FactoryBot.build_stubbed(:project) }
describe 'project copy permission' do
before do
assign(:project, project)
- allow(view).to receive(:render_tabs).and_return('')
+ allow(view).to receive(:labelled_tabular_form_for).and_return('')
end
context 'when project copy is allowed' do
@@ -67,7 +67,7 @@ describe 'project_settings/show', type: :view do
assign(:project, project)
allow(project).to receive(:copy_allowed?).and_return(true)
allow(User).to receive(:current).and_return(admin)
- allow(view).to receive(:render_tabs).and_return('')
+ allow(view).to receive(:labelled_tabular_form_for).and_return('')
render
end
@@ -84,7 +84,7 @@ describe 'project_settings/show', type: :view do
assign(:project, project)
allow(project).to receive(:copy_allowed?).and_return(true)
allow(User).to receive(:current).and_return(non_admin)
- allow(view).to receive(:render_tabs).and_return('')
+ allow(view).to receive(:labelled_tabular_form_for).and_return('')
render
end
diff --git a/spec_legacy/functional/projects_controller_spec.rb b/spec_legacy/functional/projects_controller_spec.rb
index 78bbb92e533..82056acbea9 100644
--- a/spec_legacy/functional/projects_controller_spec.rb
+++ b/spec_legacy/functional/projects_controller_spec.rb
@@ -292,7 +292,7 @@ describe ProjectsController, type: :controller do
issue_custom_field_ids: ['']
}
}
- assert_redirected_to '/projects/ecookbook/settings'
+ assert_redirected_to '/projects/ecookbook/settings/generic'
project = Project.find(1)
assert_equal 'Test changed name', project.name
end