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

Allow redirecting back to global

Oliver Güntherb65e2cb51411
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 609198f726f..657e26c1116 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -345,7 +345,7 @@ class ApplicationController < ActionController::Base
params[:back_url] || request.env["HTTP_REFERER"]
end
- def redirect_back_or_default(default, use_escaped = true)
+ def redirect_back_or_default(default, use_escaped: true, status: :found)
policy = RedirectPolicy.new(
params[:back_url],
hostname: request.host,
@@ -353,7 +353,7 @@ class ApplicationController < ActionController::Base
return_escaped: use_escaped
)
- redirect_to policy.redirect_url
+ redirect_to(policy.redirect_url, status:)
end
# Picks which layout to use based on the request
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index d667d29e9c4..cb916592082 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -148,17 +150,17 @@ class UsersController < ApplicationController
render_400 unless %i(activate lock unlock).include? @status_change
end
- def change_status
+ def change_status # rubocop:disable Metrics/AbcSize
if @user.id == current_user.id
# user is not allowed to change own status
- redirect_back_or_default(action: "edit", id: @user)
+ redirect_back_or_default({ action: "edit", id: @user })
return
end
if (params[:unlock] || params[:activate]) && user_limit_reached?
show_user_limit_error!
- return redirect_back_or_default(action: "edit", id: @user)
+ return redirect_back_or_default({ action: "edit", id: @user })
end
if params[:unlock]
@@ -184,7 +186,7 @@ class UsersController < ApplicationController
flash[:error] = I18n.t("user.error_status_change_failed",
errors: @user.errors.full_messages.join(", "))
end
- redirect_back_or_default(action: "edit", id: @user)
+ redirect_back_or_default({ action: "edit", id: @user })
end
def resend_invitation
diff --git a/app/controllers/wiki_menu_items_controller.rb b/app/controllers/wiki_menu_items_controller.rb
index 51ad5b23af8..5a6950474d1 100644
--- a/app/controllers/wiki_menu_items_controller.rb
+++ b/app/controllers/wiki_menu_items_controller.rb
@@ -101,7 +101,7 @@ class WikiMenuItemsController < ApplicationController
flash[:notice] = t(:notice_successful_update)
end
- redirect_back_or_default(action: "edit", id: @page)
+ redirect_back_or_default({ action: "edit", id: @page })
else
respond_to do |format|
format.html do
diff --git a/app/controllers/work_packages/bulk_controller.rb b/app/controllers/work_packages/bulk_controller.rb
index f2938d63a95..54b072003da 100644
--- a/app/controllers/work_packages/bulk_controller.rb
+++ b/app/controllers/work_packages/bulk_controller.rb
@@ -48,7 +48,7 @@ class WorkPackages::BulkController < ApplicationController
if @call.success?
flash[:notice] = t(:notice_successful_update)
- redirect_back_or_default(controller: "/work_packages", action: :index, project_id: @project)
+ redirect_back_or_default({ controller: "/work_packages", action: :index, project_id: @project })
else
flash[:error] = bulk_error_message(@work_packages, @call)
setup_edit
diff --git a/modules/costs/app/controllers/cost_types_controller.rb b/modules/costs/app/controllers/cost_types_controller.rb
index 099e123d435..db537b96543 100644
--- a/modules/costs/app/controllers/cost_types_controller.rb
+++ b/modules/costs/app/controllers/cost_types_controller.rb
@@ -70,7 +70,7 @@ class CostTypesController < ApplicationController
if @cost_type.save
flash[:notice] = t(:notice_successful_update)
- redirect_back_or_default(action: "index")
+ redirect_back_or_default({ action: "index" })
else
render action: :edit, status: :unprocessable_entity, layout: !request.xhr?
end
@@ -92,7 +92,7 @@ class CostTypesController < ApplicationController
if @cost_type.save
flash[:notice] = t(:notice_successful_update)
- redirect_back_or_default(action: "index")
+ redirect_back_or_default({ action: "index" })
else
@cost_type.rates.build(valid_from: Date.today) if @cost_type.rates.empty?
render action: :edit, status: :unprocessable_entity, layout: !request.xhr?
@@ -109,7 +109,7 @@ class CostTypesController < ApplicationController
if @cost_type.save
flash[:notice] = t(:notice_successful_lock)
- redirect_back_or_default(action: "index")
+ redirect_back_or_default({ action: "index" })
end
end
@@ -120,7 +120,7 @@ class CostTypesController < ApplicationController
if @cost_type.save
flash[:notice] = t(:notice_successful_restore)
- redirect_back_or_default(action: "index")
+ redirect_back_or_default({ action: "index" })
end
end
diff --git a/modules/costs/app/controllers/hourly_rates_controller.rb b/modules/costs/app/controllers/hourly_rates_controller.rb
index 50feea32249..f130372a408 100644
--- a/modules/costs/app/controllers/hourly_rates_controller.rb
+++ b/modules/costs/app/controllers/hourly_rates_controller.rb
@@ -108,9 +108,9 @@ class HourlyRatesController < ApplicationController
if @user.save
flash[:notice] = t(:notice_successful_update)
if @project.nil?
- redirect_back_or_default(controller: "users", action: "edit", id: @user)
+ redirect_back_or_default({ controller: "users", action: "edit", id: @user })
else
- redirect_back_or_default(action: "show", id: @user, project_id: @project)
+ redirect_back_or_default({ action: "show", id: @user, project_id: @project })
end
else
if @project.nil?
diff --git a/modules/meeting/app/components/meetings/delete_dialog_component.html.erb b/modules/meeting/app/components/meetings/delete_dialog_component.html.erb
index 20cd03841b7..76f05a8b869 100644
--- a/modules/meeting/app/components/meetings/delete_dialog_component.html.erb
+++ b/modules/meeting/app/components/meetings/delete_dialog_component.html.erb
@@ -32,7 +32,7 @@ See COPYRIGHT and LICENSE files for more details.
id:,
title:,
form_arguments: {
- action: project_meeting_path(@project, @meeting),
+ action: project_meeting_path(@project, @meeting, back_url: @back_url),
method: :delete,
data: { turbo: true }
}
diff --git a/modules/meeting/app/components/meetings/delete_dialog_component.rb b/modules/meeting/app/components/meetings/delete_dialog_component.rb
index 935a19c0680..768cf2488b9 100644
--- a/modules/meeting/app/components/meetings/delete_dialog_component.rb
+++ b/modules/meeting/app/components/meetings/delete_dialog_component.rb
@@ -33,11 +33,12 @@ module Meetings
include ApplicationHelper
include OpTurbo::Streamable
- def initialize(meeting:, project:)
+ def initialize(meeting:, back_url: nil)
super
@meeting = meeting
- @project = project
+ @project = meeting.project
+ @back_url = back_url
end
delegate :recurring_meeting, to: :@meeting
diff --git a/modules/meeting/app/components/meetings/row_component.rb b/modules/meeting/app/components/meetings/row_component.rb
index b69491fa3ed..5e243307fa8 100644
--- a/modules/meeting/app/components/meetings/row_component.rb
+++ b/modules/meeting/app/components/meetings/row_component.rb
@@ -143,9 +143,10 @@ module Meetings
def delete_action(menu)
return unless delete_allowed?
+ back_url = current_project ? nil : meetings_path
menu.with_item(label: recurring_meeting.present? ? I18n.t(:label_recurring_meeting_delete) : I18n.t(:label_meeting_delete),
scheme: :danger,
- href: delete_dialog_project_meeting_path(project, model),
+ href: delete_dialog_project_meeting_path(project, model, back_url:),
tag: :a,
content_arguments: {
data: { controller: "async-dialog" }
diff --git a/modules/meeting/app/controllers/meeting_agendas_controller.rb b/modules/meeting/app/controllers/meeting_agendas_controller.rb
index 064313cc876..3701f341137 100644
--- a/modules/meeting/app/controllers/meeting_agendas_controller.rb
+++ b/modules/meeting/app/controllers/meeting_agendas_controller.rb
@@ -32,12 +32,12 @@ class MeetingAgendasController < MeetingContentsController
def close
@meeting.close_agenda_and_copy_to_minutes!
- redirect_back_or_default controller: "/meetings", action: "show", id: @meeting
+ redirect_back_or_default({ controller: "/meetings", action: "show", id: @meeting })
end
def open
@content.unlock!
- redirect_back_or_default controller: "/meetings", action: "show", id: @meeting
+ redirect_back_or_default({ controller: "/meetings", action: "show", id: @meeting })
end
private
diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb
index 8b2bfdf3b7c..c0dacc61a6e 100644
--- a/modules/meeting/app/controllers/meetings_controller.rb
+++ b/modules/meeting/app/controllers/meetings_controller.rb
@@ -168,7 +168,6 @@ class MeetingsController < ApplicationController
format.turbo_stream do
respond_with_dialog Meetings::Index::DialogComponent.new(
meeting: @meeting,
- project: @project,
copy_from:
)
end
@@ -178,7 +177,7 @@ class MeetingsController < ApplicationController
def delete_dialog
respond_with_dialog Meetings::DeleteDialogComponent.new(
meeting: @meeting,
- project: @project
+ back_url: params[:back_url]
)
end
@@ -196,7 +195,7 @@ class MeetingsController < ApplicationController
if recurring
redirect_to project_recurring_meeting_path(@project, recurring), status: :see_other
else
- redirect_to project_meetings_path(@project), status: :see_other
+ redirect_back_or_default project_meetings_path(@project), status: :see_other
end
end
diff --git a/modules/meeting/spec/components/meetings/delete_dialog_component_spec.rb b/modules/meeting/spec/components/meetings/delete_dialog_component_spec.rb
index 172f2dd5518..9004221b473 100644
--- a/modules/meeting/spec/components/meetings/delete_dialog_component_spec.rb
+++ b/modules/meeting/spec/components/meetings/delete_dialog_component_spec.rb
@@ -37,7 +37,7 @@ RSpec.describe Meetings::DeleteDialogComponent, type: :component do
let(:user) { build_stubbed(:user) }
subject do
- render_inline(described_class.new(meeting:, project:))
+ render_inline(described_class.new(meeting:))
page
end
diff --git a/modules/meeting/spec/components/meetings/row_component_spec.rb b/modules/meeting/spec/components/meetings/row_component_spec.rb
index 391a53e81a9..f999aff1538 100644
--- a/modules/meeting/spec/components/meetings/row_component_spec.rb
+++ b/modules/meeting/spec/components/meetings/row_component_spec.rb
@@ -81,8 +81,10 @@ RSpec.describe Meetings::RowComponent, type: :component do
let(:meeting) { build_stubbed(:meeting, project:) }
context "without a current project" do
- it "shows delete menu item" do
- expect(subject).to have_link "Delete meeting", href: delete_dialog_project_meeting_path(project, meeting)
+ it "shows delete menu item with a back url" do
+ back_url = meetings_path
+ expect(subject).to have_link "Delete meeting",
+ href: delete_dialog_project_meeting_path(project, meeting, back_url:)
end
end
@@ -100,8 +102,10 @@ RSpec.describe Meetings::RowComponent, type: :component do
let(:meeting) { build_stubbed(:structured_meeting_template, recurring_meeting: series, project:) }
context "without a current project" do
- it "shows delete menu item" do
- expect(subject).to have_link "Delete occurrence", href: delete_dialog_project_meeting_path(project, meeting)
+ it "shows delete menu item with a back url" do
+ back_url = meetings_path
+ expect(subject).to have_link "Delete occurrence",
+ href: delete_dialog_project_meeting_path(project, meeting, back_url:)
end
end
diff --git a/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb b/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb
index f1a6cc662fc..feb2f810ca9 100644
--- a/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb
+++ b/modules/meeting/spec/features/structured_meetings/structured_meeting_crud_spec.rb
@@ -293,9 +293,8 @@ RSpec.describe "Structured meetings CRUD",
end
wait_for_network_idle
- click_on("op-meetings-header-action-trigger")
-
retry_block do
+ click_on("op-meetings-header-action-trigger")
click_on "Copy"
# dynamically wait for the modal to be loaded
expect(page).to have_text("Copy meeting")
diff --git a/modules/meeting/spec/features/structured_meetings/structured_meeting_delete_spec.rb b/modules/meeting/spec/features/structured_meetings/structured_meeting_delete_spec.rb
new file mode 100644
index 00000000000..ffb4818a62f
--- /dev/null
+++ b/modules/meeting/spec/features/structured_meetings/structured_meeting_delete_spec.rb
@@ -0,0 +1,76 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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.
+#++
+
+require "spec_helper"
+
+require_relative "../../support/pages/meetings/new"
+require_relative "../../support/pages/structured_meeting/show"
+require_relative "../../support/pages/meetings/index"
+
+RSpec.describe "Structured meetings deletion",
+ :js do
+ include Components::Autocompleter::NgSelectAutocompleteHelpers
+
+ shared_let(:project) { create(:project, enabled_module_names: %w[meetings work_package_tracking]) }
+ shared_let(:user) do
+ create(:user,
+ lastname: "First",
+ member_with_permissions: { project => %i[view_meetings create_meetings edit_meetings delete_meetings] }).tap do |u|
+ u.pref[:time_zone] = "Etc/UTC"
+
+ u.save!
+ end
+ end
+
+ shared_let(:meeting) { create(:meeting, project:, author: user) }
+
+ let(:current_user) { user }
+ let(:meetings_page) { Pages::Meetings::Index.new(project: nil) }
+
+ before do
+ login_as current_user
+ meetings_page.visit!
+ end
+
+ it "can delete globally, redirecting back to global" do
+ expect(page).to have_current_path(meetings_page.path)
+ expect(page).to have_text meeting.title
+
+ within("li", text: meeting.title) do
+ click_on "more-button"
+ click_on "Delete meeting"
+ end
+
+ within("#delete-meeting-dialog") do
+ expect(page).to have_text "Delete this meeting?"
+ click_on "Delete"
+ end
+
+ expect(page).to have_current_path(meetings_page.path)
+ end
+end