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

[46190] Link back button of diff page to the correct page

Christophe Bliard02673ed212de
diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb
index c3f0a73dbf4..65a4c1d1111 100644
--- a/app/controllers/activities_controller.rb
+++ b/app/controllers/activities_controller.rb
@@ -32,7 +32,8 @@ class ActivitiesController < ApplicationController
:verify_activities_module_activated,
:determine_date_range,
:determine_subprojects,
- :determine_author
+ :determine_author,
+ :set_current_activity_page
after_action :set_session
@@ -115,6 +116,10 @@ class ActivitiesController < ApplicationController
end
end
+ def set_current_activity_page
+ RequestStore[:current_activity_page] = @project ? "projects/#{@project.identifier}" : 'all'
+ end
+
def set_session
session[:activity] = @activity.scope
end
diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb
index e5e37940199..dccb9d4c576 100644
--- a/app/controllers/journals_controller.rb
+++ b/app/controllers/journals_controller.rb
@@ -67,6 +67,7 @@ class JournalsController < ApplicationController
return render_400 message: I18n.t(:error_journal_attribute_not_present, attribute: field_param)
end
+ @activity_page = params['activity_page']
@diff = Redmine::Helpers::Diff.new(to, from)
respond_to do |format|
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 7abe515456b..2e397d1c36d 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -44,6 +44,7 @@ class UsersController < ApplicationController
before_action :authorize_for_user, only: [:destroy]
before_action :check_if_deletion_allowed, only: %i[deletion_info
destroy]
+ before_action :set_current_activity_page, only: [:show]
# Password confirmation helpers and actions
include PasswordConfirmation
@@ -273,6 +274,10 @@ class UsersController < ApplicationController
render_404 unless Users::DeleteContract.deletion_allowed? @user, User.current
end
+ def set_current_activity_page
+ RequestStore[:current_activity_page] = "users/#{@user.id}"
+ end
+
def my_or_admin_layout
# TODO: how can this be done better:
# check if the route used to call the action is in the 'my' namespace
diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb
new file mode 100644
index 00000000000..a1c3728e8b1
--- /dev/null
+++ b/app/helpers/journals_helper.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 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.
+#++
+
+module JournalsHelper
+ def back_to_activity_page_url(activity_page)
+ case activity_page&.split('/')
+ in ['all']
+ activities_url
+ in ['projects', project_id]
+ project_activities_url(project_id)
+ in ['users', user_id]
+ user_url(user_id)
+ in ['work_packages', work_package_id]
+ work_package_url(work_package_id)
+ else
+ nil
+ end
+ end
+end
diff --git a/app/views/journals/diff.html.erb b/app/views/journals/diff.html.erb
index 2966b1cff64..5bfdae4c418 100644
--- a/app/views/journals/diff.html.erb
+++ b/app/views/journals/diff.html.erb
@@ -27,11 +27,13 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
+<% html_title @journable.to_s %>
+
<p><%= authoring @journal.created_at, @journal.user, label: :label_updated_time_by %></p>
<%= render partial: 'diff',
locals: { diff: @diff } %>
-<p><%= link_to(t(:button_back), polymorphic_path(@journable)) %></p>
-
-<% html_title "#{ @journable.to_s }" %>
+<% if @activity_page -%>
+ <p><%= link_to(t(:button_back), back_to_activity_page_url(@activity_page)) %></p>
+<% end -%>
diff --git a/lib/api/v3/activities/activities_by_work_package_api.rb b/lib/api/v3/activities/activities_by_work_package_api.rb
index 8a2c0a0d9c0..7e7d8e5cc42 100644
--- a/lib/api/v3/activities/activities_by_work_package_api.rb
+++ b/lib/api/v3/activities/activities_by_work_package_api.rb
@@ -35,6 +35,7 @@ module API
resource :activities do
get do
self_link = api_v3_paths.work_package_activities @work_package.id
+ RequestStore[:current_activity_page] = "work_packages/#{@work_package.id}"
journals = @work_package.journals.includes(:data,
:customizable_journals,
:attachable_journals,
diff --git a/lib/open_project/journal_formatter/diff.rb b/lib/open_project/journal_formatter/diff.rb
index da76e57d347..3b161be4e47 100644
--- a/lib/open_project/journal_formatter/diff.rb
+++ b/lib/open_project/journal_formatter/diff.rb
@@ -69,10 +69,13 @@ class OpenProject::JournalFormatter::Diff < JournalFormatter::Base
end
def link(key, options)
- url_attr = default_attributes(options).merge(controller: '/journals',
- action: 'diff',
- id: @journal.id,
- field: key.downcase)
+ url_attr = default_attributes(options)
+ .merge(controller: '/journals',
+ action: 'diff',
+ id: @journal.id,
+ field: key.downcase,
+ activity_page: RequestStore[:current_activity_page])
+ .compact
if options[:html]
link_to(I18n.t(:label_details),
diff --git a/spec/helpers/journals_helper_spec.rb b/spec/helpers/journals_helper_spec.rb
new file mode 100644
index 00000000000..1a3b4b644df
--- /dev/null
+++ b/spec/helpers/journals_helper_spec.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 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'
+
+RSpec.describe JournalsHelper do
+ describe 'back_to_activity_page_url' do
+ {
+ 'all' => 'http://test.host/activities',
+ 'projects/some-identifier' => 'http://test.host/projects/some-identifier/activities',
+ 'unsupported_gizmo' => nil,
+ 'users/5' => 'http://test.host/users/5',
+ 'work_packages/42' => 'http://test.host/work_packages/42',
+ nil => nil
+ }.each do |activity_page, expected_url|
+ context "when activity page is #{activity_page.inspect}" do
+ it do
+ expect(back_to_activity_page_url(activity_page)).to eq(expected_url)
+ end
+ end
+ end
+ end
+end