Add unsubscribe option to badge and connect emails (#6027)
This commit is contained in:
parent
38622317b7
commit
6b481166fe
2 changed files with 13 additions and 14 deletions
|
|
@ -1,28 +1,25 @@
|
|||
class EmailSubscriptionsController < ApplicationController
|
||||
# No need to authorize this because its implicit when unsubbing
|
||||
PREFERRED_EMAIL_NAME = {
|
||||
email_digest_periodic: "DEV digest emails",
|
||||
email_comment_notifications: "comment notifications",
|
||||
email_follower_notifications: "follower notifications",
|
||||
email_mention_notifications: "mention notifications",
|
||||
email_connect_messages: "DEV connect messages",
|
||||
email_unread_notifications: "unread notifications",
|
||||
email_badge_notifications: "badge notifications"
|
||||
}.freeze
|
||||
|
||||
def unsubscribe
|
||||
verified_params = Rails.application.message_verifier(:unsubscribe).verify(params[:ut])
|
||||
|
||||
if verified_params[:expires_at] > Time.current
|
||||
user = User.find(verified_params[:user_id])
|
||||
user.update(verified_params[:email_type] => false)
|
||||
@email_type = preferred_email_name(verified_params[:email_type])
|
||||
@email_type = PREFERRED_EMAIL_NAME[verified_params[:email_type]]
|
||||
else
|
||||
render "invalid_token"
|
||||
end
|
||||
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
||||
not_found
|
||||
end
|
||||
|
||||
def preferred_email_name(given_email_type)
|
||||
emails_type = {
|
||||
email_digest_periodic: "DEV digest emails",
|
||||
email_comment_notifications: "comment notifications",
|
||||
email_follower_notifications: "follower notifications",
|
||||
email_mention_notifications: "mention notifications",
|
||||
email_connect_messages: "connect messages",
|
||||
email_unread_notifications: "unread notifications"
|
||||
}
|
||||
emails_type[given_email_type]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class NotifyMailer < ApplicationMailer
|
|||
@badge_achievement = badge_achievement
|
||||
@user = @badge_achievement.user
|
||||
@badge = @badge_achievement.badge
|
||||
@unsubscribe = generate_unsubscribe_token(@user.id, :email_badge_notifications)
|
||||
mail(to: @user.email, subject: "You just got a badge")
|
||||
end
|
||||
|
||||
|
|
@ -69,6 +70,7 @@ class NotifyMailer < ApplicationMailer
|
|||
@message = direct_message
|
||||
@user = @message.direct_receiver
|
||||
subject = "#{@message.user.name} just messaged you"
|
||||
@unsubscribe = generate_unsubscribe_token(@user.id, :email_connect_messages)
|
||||
mail(to: @user.email, subject: subject)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue