FIX: Validate unsubscribe key has an associated user (#19262)

* FIX: Validate unsubscribe key has an associated user

* Improve error messages
This commit is contained in:
Roman Rizzi
2022-11-30 14:29:07 -03:00
committed by GitHub
parent 49e0fc04f7
commit 9bb5cf1c46
4 changed files with 19 additions and 5 deletions

View File

@@ -6,10 +6,11 @@ class EmailController < ApplicationController
skip_before_action :check_xhr, :preload_json, :redirect_to_login_if_required
def unsubscribe
key = UnsubscribeKey.find_by(key: params[:key])
key = UnsubscribeKey.includes(:user).find_by(key: params[:key])
@found = key.present?
@key_owner_found = key&.user.present?
if @found
if @found && @key_owner_found
UnsubscribeKey
.get_unsubscribe_strategy_for(key)
&.prepare_unsubscribe_options(self)