<commit_before>class SubscriptionsController < ApplicationController
  skip_before_action :authorize, only: :unsubscribe

  def unsubscribe
    subscription = Subscription.find_by secure_key: params[:secure_key]
    if subscription
      subscription.update active: false
      redirect_to root_path, success: "You have been unsubscribed from this mailing."
    else
      redirect_to root_path, error: "Invalid unsubscribe link."
    end
  end
end<commit_msg>Record unsuccessful unsubscribe attempts in New Relic.<commit_after>class SubscriptionsController < ApplicationController
  skip_before_action :authorize, only: :unsubscribe

  def unsubscribe
    subscription = Subscription.find_by(secure_key: params[:secure_key])
    if subscription
      subscription.update active: false
      redirect_to root_path, success: "You have been unsubscribed from this mailing."
    else
      error = ActiveRecord::RecordNotFound.new(
        "#{params[:secure_key]} is an invalid unsubscribe link for #{current_user.email}.")
      NewRelic::Agent.notice_error(error)
      redirect_to root_path, error: "Invalid unsubscribe link."
    end
  end
end
{'fraction_non_alphanumeric': 0.06905594405594405, 'fraction_numerical': 0.0, 'mean_word_length': 4.42654028436019, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2968336', 'n_tokens_mistral': 302, 'n_tokens_neox': 301, 'n_words': 91}