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
Pass activity_page for diff back link without using global state
Christophe Bliard0f90fc4cb72c
diff --git a/app/components/activities/days_component.html.erb b/app/components/activities/days_component.html.erbindex eadc5ce7132..cac31715ac6 100644--- a/app/components/activities/days_component.html.erb+++ b/app/components/activities/days_component.html.erb@@ -2,6 +2,9 @@<% events_by_day.each do |day, events| %><%= content_tag(@header_tag, helpers.format_activity_day(day), class: 'op-activity-days--header') %>- <%= render(Activities::ListComponent.new(events:, display_user: @display_user)) %>+ <%= render(Activities::ListComponent.new(events:,+ display_user: @display_user,+ activity_page: @activity_page))+ %><% end -%></div>diff --git a/app/components/activities/days_component.rb b/app/components/activities/days_component.rbindex 28e76966840..6b5b081d57d 100644--- a/app/components/activities/days_component.rb+++ b/app/components/activities/days_component.rb@@ -29,11 +29,12 @@#++class Activities::DaysComponent < ViewComponent::Base- def initialize(events:, display_user: true, header_tag: 'h3')+ def initialize(events:, display_user: true, header_tag: 'h3', activity_page: nil)super()@events = events@display_user = display_user@header_tag = header_tag+ @activity_page = activity_pageenddef events_by_daydiff --git a/app/components/activities/item_component.rb b/app/components/activities/item_component.rbindex ccfba09fb02..81f8b0bccdd 100644--- a/app/components/activities/item_component.rb+++ b/app/components/activities/item_component.rb@@ -31,10 +31,11 @@class Activities::ItemComponent < ViewComponent::Basewith_collection_parameter :event- def initialize(event:, display_user: true)+ def initialize(event:, display_user: true, activity_page: nil)super()@event = event@display_user = display_user+ @activity_page = activity_pageenddef display_belonging_project?@@ -55,7 +56,7 @@ class Activities::ItemComponent < ViewComponent::Base@rendered_details ||=@event.journal.details- .flat_map { |detail| @event.journal.render_detail(detail) }+ .flat_map { |detail| @event.journal.render_detail(detail, activity_page: @activity_page) }enddef format_activity_title(text)diff --git a/app/components/activities/list_component.html.erb b/app/components/activities/list_component.html.erbindex 984834918e9..31bd35fc0db 100644--- a/app/components/activities/list_component.html.erb+++ b/app/components/activities/list_component.html.erb@@ -1,3 +1,6 @@<ul class="op-activity-list">- <%= render(Activities::ItemComponent.with_collection(@events, display_user: @display_user)) %>+ <%= render(Activities::ItemComponent.with_collection(@events,+ display_user: @display_user,+ activity_page: @activity_page))+ %></ul>diff --git a/app/components/activities/list_component.rb b/app/components/activities/list_component.rbindex e92262b603e..dfa0cf31f14 100644--- a/app/components/activities/list_component.rb+++ b/app/components/activities/list_component.rb@@ -29,9 +29,10 @@#++class Activities::ListComponent < ViewComponent::Base- def initialize(events:, display_user: true)+ def initialize(events:, display_user: true, activity_page: nil)super()@events = events.sort { |x, y| y.event_datetime <=> x.event_datetime }@display_user = display_user+ @activity_page = activity_pageendenddiff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rbindex 65a4c1d1111..f1c5f00dcfe 100644--- a/app/controllers/activities_controller.rb+++ b/app/controllers/activities_controller.rb@@ -117,7 +117,7 @@ class ActivitiesController < ApplicationControllerenddef set_current_activity_page- RequestStore[:current_activity_page] = @project ? "projects/#{@project.identifier}" : 'all'+ @activity_page = @project ? "projects/#{@project.identifier}" : 'all'enddef set_sessiondiff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex 2e397d1c36d..2b3a9ea698f 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -275,7 +275,7 @@ class UsersController < ApplicationControllerenddef set_current_activity_page- RequestStore[:current_activity_page] = "users/#{@user.id}"+ @activity_page = "users/#{@user.id}"enddef my_or_admin_layoutdiff --git a/app/views/activities/index.html.erb b/app/views/activities/index.html.erbindex 3fe05839c22..0c91921d410 100644--- a/app/views/activities/index.html.erb+++ b/app/views/activities/index.html.erb@@ -33,7 +33,7 @@ See COPYRIGHT and LICENSE files for more details.subtitle: t(:label_date_from_to, start: format_date(@date_to - @days), end: format_date(@date_to-1))%>-<%= render(Activities::DaysComponent.new(events: @events)) %>+<%= render(Activities::DaysComponent.new(events: @events, activity_page: @activity_page)) %><% if @events.empty? %><%= no_results_box %>diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erbindex c8250ae600e..b5d3cb82b32 100644--- a/app/views/users/show.html.erb+++ b/app/views/users/show.html.erb@@ -80,7 +80,7 @@ See COPYRIGHT and LICENSE files for more details.<p><%=t(:label_reported_work_packages)%>: <%= @user.reported_work_package_count %></p>- <%= render(Activities::DaysComponent.new(events: @events, display_user: false, header_tag: 'h4')) %>+ <%= render(Activities::DaysComponent.new(events: @events, display_user: false, header_tag: 'h4', activity_page: @activity_page)) %><%= other_formats_links do |f| %><%= f.link_to 'Atom', url: {controller: '/activities', action: 'index', id: nil, user_id: @user, key: User.current.rss_key} %>diff --git a/lib/api/v3/activities/activities_by_work_package_api.rb b/lib/api/v3/activities/activities_by_work_package_api.rbindex 7e7d8e5cc42..8a2c0a0d9c0 100644--- a/lib/api/v3/activities/activities_by_work_package_api.rb+++ b/lib/api/v3/activities/activities_by_work_package_api.rb@@ -35,7 +35,6 @@ module APIresource :activities doget doself_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/api/v3/activities/activity_property_formatters.rb b/lib/api/v3/activities/activity_property_formatters.rbindex 9b689c7f69b..520dfa30bd9 100644--- a/lib/api/v3/activities/activity_property_formatters.rb+++ b/lib/api/v3/activities/activity_property_formatters.rb@@ -37,8 +37,9 @@ module APIenddef formatted_details(journal)+ activity_page = "work_packages/#{journal.journable.id}"details = render_details(journal, html: false)- html_details = render_details(journal)+ html_details = render_details(journal, activity_page:)details.zip(html_details)@@ -47,10 +48,10 @@ module APIprivate- def render_details(journal, html: true)+ def render_details(journal, html: true, activity_page: nil)journal.details- .map { |d| journal.render_detail(d, html:) }+ .map { |d| journal.render_detail(d, html:, activity_page:) }.compactenddiff --git a/lib/open_project/journal_formatter/diff.rb b/lib/open_project/journal_formatter/diff.rbindex 3b161be4e47..2d9f691fca7 100644--- a/lib/open_project/journal_formatter/diff.rb+++ b/lib/open_project/journal_formatter/diff.rb@@ -74,7 +74,7 @@ class OpenProject::JournalFormatter::Diff < JournalFormatter::Baseaction: 'diff',id: @journal.id,field: key.downcase,- activity_page: RequestStore[:current_activity_page])+ activity_page: options[:activity_page]).compactif options[:html]diff --git a/spec/features/activities/activity_page_navigation_spec.rb b/spec/features/activities/activity_page_navigation_spec.rbindex 4b6ffa03ffd..861e6b25a0d 100644--- a/spec/features/activities/activity_page_navigation_spec.rb+++ b/spec/features/activities/activity_page_navigation_spec.rb@@ -139,4 +139,41 @@ describe 'Activity page navigation' docontext 'with subprojects NOT included by default', with_setting: { display_subprojects_work_packages: false } doinclude_examples 'subprojects checkbox state is preserved'end++ context 'when navigating to a diff' do+ before do+ project_work_package.update(description: 'New work package description')+ end++ def assert_navigating_to_diff_page_and_back_comes_back_to_the_same_page(activity_page)+ visit(activity_page)+ activity_page_url = page.current_url++ expect(page).to have_link(text: 'Details')+ expect(page.text).to include("Description changed (Details)")+ click_link('Details')++ # on diff page, click the back button+ expect(page).to have_link(text: 'Back')+ click_link('Back')++ expect(page.current_url).to eq(activity_page_url)+ end++ it 'Back button navigates to the previously seen activity page' do+ [+ activities_path,+ project_activities_path(project),+ user_path(user)+ ].each do |activity_page|+ assert_navigating_to_diff_page_and_back_comes_back_to_the_same_page(activity_page)+ end+ end++ # work package activity page is rendered by Angular, so it needs js: true+ it 'Back button navigates to the previously seen work package page', js: true do+ activity_page = work_package_path(project_work_package)+ assert_navigating_to_diff_page_and_back_comes_back_to_the_same_page(activity_page)+ end+ endend