mirror of
https://github.com/discourse/discourse.git
synced 2025-01-29 08:46:14 +08:00
DEV: refactor email_controller.rb
- Make an `includes(:user)` explicit rather than implicit. - Refactor the `unsubscribe` action to bail early when `key` is invalid
This commit is contained in:
parent
4d889f2ef8
commit
9497a6165f
|
@ -26,7 +26,7 @@ class EmailController < ApplicationController
|
||||||
def perform_unsubscribe
|
def perform_unsubscribe
|
||||||
RateLimiter.new(nil, "unsubscribe_#{request.ip}", 10, 1.minute).performed!
|
RateLimiter.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?
|
raise Discourse::NotFound if key.nil? || key.user.nil?
|
||||||
user = key.user
|
user = key.user
|
||||||
updated = UnsubscribeKey.get_unsubscribe_strategy_for(key)&.unsubscribe(params)
|
updated = UnsubscribeKey.get_unsubscribe_strategy_for(key)&.unsubscribe(params)
|
||||||
|
@ -46,10 +46,12 @@ class EmailController < ApplicationController
|
||||||
|
|
||||||
def unsubscribed
|
def unsubscribed
|
||||||
@email = Discourse.cache.read(params[:key])
|
@email = Discourse.cache.read(params[:key])
|
||||||
@topic_id = params[:topic_id]
|
|
||||||
user = User.find_by_email(@email)
|
raise Discourse::NotFound unless User.find_by_email(@email)
|
||||||
raise Discourse::NotFound unless user
|
|
||||||
topic = Topic.find_by(id: params[:topic_id].to_i) if @topic_id
|
if @topic_id = params[:topic_id]
|
||||||
@topic = topic if topic && Guardian.new(nil).can_see?(topic)
|
topic = Topic.find_by(id: @topic_id)
|
||||||
|
@topic = topic if topic && Guardian.new.can_see?(topic)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user