A platform for community discussion. Free, open, simple.
DEV: refactor email_controller.rb
zogstrip9497a6165f2f
diff --git a/app/controllers/email_controller.rb b/app/controllers/email_controller.rbindex 66fb8a0af62..e1da5643f96 100644--- a/app/controllers/email_controller.rb+++ b/app/controllers/email_controller.rb@@ -26,7 +26,7 @@ class EmailController < ApplicationControllerdef perform_unsubscribeRateLimiter.new(nil, "unsubscribe_#{request.ip}", 10, 1.minute).performed!- key = UnsubscribeKey.find_by(key: params[:key])+ key = UnsubscribeKey.includes(:user).find_by(key: params[:key])raise Discourse::NotFound if key.nil? || key.user.nil?user = key.userupdated = UnsubscribeKey.get_unsubscribe_strategy_for(key)&.unsubscribe(params)@@ -46,10 +46,12 @@ class EmailController < ApplicationControllerdef unsubscribed@email = Discourse.cache.read(params[:key])- @topic_id = params[:topic_id]- user = User.find_by_email(@email)- raise Discourse::NotFound unless user- topic = Topic.find_by(id: params[:topic_id].to_i) if @topic_id- @topic = topic if topic && Guardian.new(nil).can_see?(topic)++ raise Discourse::NotFound unless User.find_by_email(@email)++ if @topic_id = params[:topic_id]+ topic = Topic.find_by(id: @topic_id)+ @topic = topic if topic && Guardian.new.can_see?(topic)+ endendend