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

fix[Op#57989]: Pass the `page` parameter in Delete requests so the current page is maintained

Kabiru Mwenja0c33b93c84ce
diff --git a/app/components/admin/custom_fields/custom_field_projects/row_component.rb b/app/components/admin/custom_fields/custom_field_projects/row_component.rb
index 51ce950bbac..d7b6ac1d62e 100644
--- a/app/components/admin/custom_fields/custom_field_projects/row_component.rb
+++ b/app/components/admin/custom_fields/custom_field_projects/row_component.rb
@@ -57,11 +57,10 @@ module Admin
def detach_from_project_url
url_helpers.custom_field_project_path(
custom_field_id: @table.params[:custom_field].id,
- custom_fields_project: { project_id: project.id }
+ custom_fields_project: { project_id: project.id },
+ page: current_page
)
end
-
- def project = model.first
end
end
end
diff --git a/app/components/projects/row_component.rb b/app/components/projects/row_component.rb
index 70adc2566d7..3f540eac0ec 100644
--- a/app/components/projects/row_component.rb
+++ b/app/components/projects/row_component.rb
@@ -373,5 +373,9 @@ module Projects
def custom_field_column?(column)
column.is_a?(::Queries::Projects::Selects::CustomField)
end
+
+ def current_page
+ table.model.current_page.to_s
+ end
end
end
diff --git a/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb b/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb
index f4645d2a23f..5ee09b6baf3 100644
--- a/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb
+++ b/app/components/settings/project_custom_fields/project_custom_field_mapping/row_component.rb
@@ -35,7 +35,8 @@ module Settings
def detach_from_project_url
url_helpers.unlink_admin_settings_project_custom_field_path(
id: @table.params[:custom_field].id,
- project_custom_field_project_mapping: { project_id: project.id }
+ project_custom_field_project_mapping: { project_id: project.id },
+ page: current_page
)
end
end
diff --git a/app/controllers/admin/custom_fields/custom_field_projects_controller.rb b/app/controllers/admin/custom_fields/custom_field_projects_controller.rb
index 8f69e323e74..e21966dd67b 100644
--- a/app/controllers/admin/custom_fields/custom_field_projects_controller.rb
+++ b/app/controllers/admin/custom_fields/custom_field_projects_controller.rb
@@ -103,7 +103,7 @@ class Admin::CustomFields::CustomFieldProjectsController < ApplicationController
update_via_turbo_stream(
component: Admin::CustomFields::CustomFieldProjects::TableComponent.new(
query: available_custom_fields_projects_query,
- params: { custom_field: @custom_field, url_for_action: }
+ params: params.merge({ custom_field: @custom_field, url_for_action: })
)
)
end
diff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rb
index b532962b12f..5bccb8501fc 100644
--- a/app/controllers/admin/settings/project_custom_fields_controller.rb
+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb
@@ -158,7 +158,7 @@ module Admin::Settings
update_via_turbo_stream(
component: Settings::ProjectCustomFields::ProjectCustomFieldMapping::TableComponent.new(
query: project_custom_field_mappings_query,
- params: { custom_field: @custom_field, url_for_action: }
+ params: params.merge({ custom_field: @custom_field, url_for_action: })
)
)
end
diff --git a/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.html.erb b/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.html.erb
index 956475512f2..cef571b12e0 100644
--- a/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.html.erb
+++ b/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.html.erb
@@ -31,7 +31,7 @@ See COPYRIGHT and LICENSE files for more details.
component_wrapper do
primer_form_with(
model: @project_storage,
- url: admin_settings_storage_project_storage_path(id: @project_storage),
+ url: admin_settings_storage_project_storage_path(id: @project_storage, page: current_page),
data: {
turbo: true,
controller: 'disable-when-checked',
diff --git a/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.rb b/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.rb
index 228e6125fb4..0db817199e7 100644
--- a/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.rb
+++ b/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.rb
@@ -32,11 +32,12 @@ module Storages::ProjectStorages
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
- def initialize(storage:, project_storage:)
+ def initialize(storage:, project_storage:, params:)
super
@storage = storage
@project_storage = project_storage
+ @params = params
end
def id
@@ -56,6 +57,10 @@ module Storages::ProjectStorages
text
end
+ def current_page
+ @params[:page]
+ end
+
def confirmation_text
I18n.t("project_storages.remove_project.dialog.confirmation_text")
end
diff --git a/modules/storages/app/components/storages/project_storages/projects/row_component.rb b/modules/storages/app/components/storages/project_storages/projects/row_component.rb
index b144b519edd..e1995faaeec 100644
--- a/modules/storages/app/components/storages/project_storages/projects/row_component.rb
+++ b/modules/storages/app/components/storages/project_storages/projects/row_component.rb
@@ -68,7 +68,8 @@ module Storages::ProjectStorages::Projects
icon: :trash,
label: I18n.t("project_storages.remove_project.label"),
href: destroy_confirmation_dialog_admin_settings_storage_project_storage_path(
- id: project_storage.id
+ id: project_storage.id,
+ page: current_page
),
data: {
controller: "async-dialog"
diff --git a/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
index 3e842e26be0..f83ffe11d00 100644
--- a/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
@@ -117,7 +117,8 @@ class Storages::Admin::Storages::ProjectStoragesController < ApplicationControll
def destroy_confirmation_dialog
respond_with_dialog Storages::ProjectStorages::DestroyConfirmationDialogComponent.new(
storage: @storage,
- project_storage: @project_storage
+ project_storage: @project_storage,
+ params:
)
end
@@ -186,7 +187,7 @@ class Storages::Admin::Storages::ProjectStoragesController < ApplicationControll
component: Storages::ProjectStorages::Projects::TableComponent.new(
query: storage_projects_query,
storage: @storage,
- params: { url_for_action: }
+ params: params.merge({ url_for_action: })
)
)
end
diff --git a/spec/features/admin/custom_fields/custom_fields_project_spec.rb b/spec/features/admin/custom_fields/custom_fields_project_spec.rb
index d77540491ba..ad769c064fb 100644
--- a/spec/features/admin/custom_fields/custom_fields_project_spec.rb
+++ b/spec/features/admin/custom_fields/custom_fields_project_spec.rb
@@ -119,18 +119,21 @@ RSpec.describe "Custom Fields Multi-Project Activation", :js do
end
end
- it "allows unlinking a project from a custom field" do
- project = create(:project)
- create(:custom_fields_project, custom_field:, project:)
+ it "allows unlinking a project from a custom field", with_settings: { per_page_options: "2,5" } do
+ projects = create_list(:project, 4)
+ projects.each { |project| create(:custom_fields_project, custom_field:, project:) }
- visit custom_field_projects_path(custom_field)
+ current_page = 3
+ visit custom_field_projects_path(custom_field, page: current_page)
+ project = custom_field_projects_page.project_in_first_row
custom_field_projects_page.click_menu_item_of("Remove from project", project)
expect(page).to have_no_text(project.name)
aggregate_failures "pagination links maintain the correct url after unlinking is done" do
- custom_field_projects_page.expect_correct_pagination_links(model: custom_field)
+ custom_field_projects_page.expect_correct_pagination_links(model: custom_field, current_page:)
+ custom_field_projects_page.expect_current_page_number(current_page)
end
end
diff --git a/spec/features/admin/project_custom_fields/project_mappings_spec.rb b/spec/features/admin/project_custom_fields/project_mappings_spec.rb
index 9742080eee5..9aaeaa5e48e 100644
--- a/spec/features/admin/project_custom_fields/project_mappings_spec.rb
+++ b/spec/features/admin/project_custom_fields/project_mappings_spec.rb
@@ -123,18 +123,21 @@ RSpec.describe "Project Custom Field Mappings", :js do
end
end
- it "allows unlinking a project from a custom field" do
- project = create(:project)
- create(:project_custom_field_project_mapping, project_custom_field:, project:)
+ it "allows unlinking a project from a custom field", with_settings: { per_page_options: "2,5" } do
+ projects = create_list(:project, 4)
+ projects.each { |project| create(:project_custom_field_project_mapping, project_custom_field:, project:) }
- visit project_mappings_admin_settings_project_custom_field_path(project_custom_field)
+ current_page = 3
+ visit project_mappings_admin_settings_project_custom_field_path(project_custom_field, page: current_page)
+ project = project_custom_field_mappings_page.project_in_first_row
project_custom_field_mappings_page.click_menu_item_of("Remove from project", project)
expect(page).to have_no_text(project.name)
aggregate_failures "pagination links maintain the correct url after unlinking is done" do
- project_custom_field_mappings_page.expect_correct_pagination_links(model: project_custom_field)
+ project_custom_field_mappings_page.expect_correct_pagination_links(model: project_custom_field, current_page:)
+ project_custom_field_mappings_page.expect_current_page_number(current_page)
end
end
diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb
index 9b504a33526..8aa1d843477 100644
--- a/spec/support/pages/projects/index.rb
+++ b/spec/support/pages/projects/index.rb
@@ -127,16 +127,23 @@ module Pages
end
end
- def expect_correct_pagination_links(model:)
- within ".op-pagination" do
+ def expect_correct_pagination_links(model:, current_page: 1)
+ within ".op-pagination--pages" do
pagination_links = page.all(".op-pagination--item-link")
expect(pagination_links.size).to be_positive
- pagination_links.each.with_index(1) do |pagination_link, page_number|
+ page_number_links = pagination_links.reject { |link| link.text =~ /previous|next/i }
+ page_number_links.each.with_index(1) do |pagination_link, page_number|
uri = URI.parse(pagination_link["href"])
expect(uri.path).to eq(path(model))
expect(uri.query).to include("page=#{page_number}")
end
+
+ if current_page > 1
+ expect(page).to have_link("Previous", href: "#{path(model)}?#{{ page: current_page - 1 }.to_query}")
+ else
+ expect(page).to have_link("Next", href: "#{path(model)}?#{{ page: current_page + 1 }.to_query}")
+ end
end
end
@@ -544,6 +551,11 @@ module Pages
within "#project-table", &
end
+ def project_in_first_row
+ first_row = within("#projects-table") { find(".op-project-row-component", match: :first) }
+ Project.find_by!(name: first_row.text.split("\n").first)
+ end
+
def within_row(project)
row = page.find("#project-#{project.id}")
row.hover