From adcab87662d6e42f24059243049d99f17152ab6f Mon Sep 17 00:00:00 2001 From: Hector Correa Date: Thu, 25 Apr 2024 16:16:52 -0400 Subject: [PATCH] Temporary work-around to fix and troubleshoot bad Work URLs generated in some places --- app/mailers/notification_mailer.rb | 6 ++++++ app/models/work.rb | 7 +++++++ app/models/work_state_transition_notification.rb | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 5b3391933..5fe16fa5c 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -11,6 +11,12 @@ def build_message @message_html = @work_activity.to_html @url = work_url(@work_activity.work) + # Troubleshooting https://github.com/pulibrary/pdc_describe/issues/1783 + if @url.includes?("/describe/describe/") + Rails.logger.error("URL #{@url} included /describe/describe/ and was fixed. See https://github.com/pulibrary/pdc_describe/issues/1783") + @url = @url.gsub("/describe/describe/", "/describe/") + end + mail(to: @user.email, subject: @subject) end end diff --git a/app/models/work.rb b/app/models/work.rb index 58ac3025d..7fdf83cc7 100644 --- a/app/models/work.rb +++ b/app/models/work.rb @@ -240,6 +240,13 @@ def update_curator(curator_user_id, current_user) new_curator = User.find(curator_user_id) work_url = "[#{title}](#{Rails.application.routes.url_helpers.work_url(self)})" + + # Troubleshooting https://github.com/pulibrary/pdc_describe/issues/1783 + if work_url.includes?("/describe/describe/") + Rails.logger.error("URL #{work_url} included /describe/describe/ and was fixed. See https://github.com/pulibrary/pdc_describe/issues/1783") + work_url = work_url.gsub("/describe/describe/", "/describe/") + end + message = if curator_user_id.to_i == current_user.id "Self-assigned @#{current_user.uid} as curator for work #{work_url}" else diff --git a/app/models/work_state_transition_notification.rb b/app/models/work_state_transition_notification.rb index 421ff34e2..a0b22a981 100644 --- a/app/models/work_state_transition_notification.rb +++ b/app/models/work_state_transition_notification.rb @@ -13,6 +13,13 @@ def initialize(work, current_user_id) @group = work.group @group_administrators = group.administrators.to_a @work_url = Rails.application.routes.url_helpers.work_url(work) + + # Troubleshooting https://github.com/pulibrary/pdc_describe/issues/1783 + if @work_url.includes?("/describe/describe/") + Rails.logger.error("URL #{@work_url} included /describe/describe/ and was fixed. See https://github.com/pulibrary/pdc_describe/issues/1783") + @work_url = @work_url.gsub("/describe/describe/", "/describe/") + end + @work_title = work.title @notification = notification_for_transition @id = work.id