FIX: Unsubscribing via key associated with deleted topic (#20275)

Currently, clicking on the unsubscribe link with a `key` associated with a
deleted topic results in an HTTP 500 response.

This change fixes that by skipping any attempt to run topic related flow if topic
isn't present.
This commit is contained in:
Selase Krakani 2023-02-16 10:47:01 +00:00 committed by GitHub
parent 9704d9aed6
commit 5a6e5a4012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -8,6 +8,8 @@ module EmailControllerHelper
topic = unsubscribe_key.associated_topic
return if topic.blank?
controller.instance_variable_set(:@topic, topic)
controller.instance_variable_set(
:@watching_topic,

View File

@ -317,6 +317,15 @@ RSpec.describe EmailController do
expect(response.body).not_to include("unwatch_category")
end
it "displays form even if topic is deleted" do
post.topic.trash!
navigate_to_unsubscribe
expect(response.status).to eq(200)
expect(response.body).to include(I18n.t("unsubscribe.all", sitename: SiteSetting.title))
end
def create_category_user(notification_level)
CategoryUser.create!(
user_id: user.id,