mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
FIX: don't error out when an unsubscribe key isn't associated to a user anymore
This commit is contained in:
parent
d666b73893
commit
bf6c3b7017
@ -9,51 +9,42 @@ class EmailController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unsubscribe
|
def unsubscribe
|
||||||
key = UnsubscribeKey.find_by(key: params[:key])
|
@not_found = true
|
||||||
|
@watched_count = nil
|
||||||
|
|
||||||
if key
|
if key = UnsubscribeKey.find_by(key: params[:key])
|
||||||
@user = key.user
|
if @user = key.user
|
||||||
post = key.post
|
post = key.post
|
||||||
@topic = (post && post.topic) || key.topic
|
@topic = post&.topic || key.topic
|
||||||
@type = key.unsubscribe_key_type
|
@type = key.unsubscribe_key_type
|
||||||
|
@not_found = false
|
||||||
|
|
||||||
if current_user.present? && (@user != current_user)
|
if current_user.present? && (@user != current_user)
|
||||||
@different_user = @user.name
|
@different_user = @user.name
|
||||||
@return_url = request.original_url
|
@return_url = request.original_url
|
||||||
end
|
end
|
||||||
|
|
||||||
@watching_topic = @topic && TopicUser.exists?(user_id: @user.id,
|
watching = TopicUser.notification_levels[:watching]
|
||||||
notification_level: TopicUser.notification_levels[:watching],
|
|
||||||
topic_id: @topic.id)
|
|
||||||
|
|
||||||
@watched_count = nil
|
if @topic
|
||||||
if @topic && @topic.category_id
|
@watching_topic = TopicUser.exists?(user_id: @user.id, notification_level: watching, topic_id: @topic.id)
|
||||||
if CategoryUser.exists?(user_id: @user.id,
|
if @topic.category_id
|
||||||
notification_level: CategoryUser.watching_levels,
|
if CategoryUser.exists?(user_id: @user.id, notification_level: CategoryUser.watching_levels, category_id: @topic.category_id)
|
||||||
category_id: @topic.category_id)
|
@watched_count = TopicUser.joins(:topic)
|
||||||
@watched_count = TopicUser.joins(:topic)
|
.where(user: @user, notification_level: watching, "topics.category_id" => @topic.category_id)
|
||||||
.where(:user => @user,
|
.count
|
||||||
:notification_level => TopicUser.notification_levels[:watching],
|
end
|
||||||
"topics.category_id" => @topic.category_id
|
end
|
||||||
).count
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if @user.blank?
|
|
||||||
@not_found = true
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_unsubscribe
|
def perform_unsubscribe
|
||||||
|
|
||||||
key = UnsubscribeKey.find_by(key: params[:key])
|
key = UnsubscribeKey.find_by(key: params[:key])
|
||||||
unless key && key.user
|
raise Discourse::NotFound unless key && key.user
|
||||||
raise Discourse::NotFound
|
|
||||||
end
|
|
||||||
|
|
||||||
topic = (key.post && key.post.topic) || key.topic
|
topic = key&.post&.topic || key.topic
|
||||||
user = key.user
|
user = key.user
|
||||||
|
|
||||||
updated = false
|
updated = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user