<commit_before>class AttachmentsController < ApplicationController

  before_filter :find_message_and_check_read_access

  def show
    attachment_path =  @message.attachment.path
    if @message.has_image? && params[:style].present? && (['thumb','big','small'].include? params[:style])
      attachment_path.sub!('original', params[:style])
    end
    if USE_X_ACCEL_REDIRECT # nginx
      head(:x_accel_redirect => attachment_path.sub(RAILS_ROOT,''),
         :content_type => @message.attachment_content_type,
         :content_disposition => "inline")
    else # apache or others
      send_file  attachment_path, :type => @message.attachment_content_type, :disposition => 'inline', :x_sendfile => USE_X_SENDFILE
    end
  end

private

  def find_message_and_check_read_access
    @message = Rails.cache.fetch('message_'+params[:id]) {Message.published.find(params[:id])}
    unless (logged_in? && @message.conversation.readable_by?(current_user)) || !@message.conversation.private?
      flash[:error] = "Sorry, this attachment is unavailable."
      redirect_to root_path
      return
    end
  end

end<commit_msg>just testing something , will be reverting in the next commit<commit_after>class AttachmentsController < ApplicationController

  before_filter :find_message_and_check_read_access

  def show
    attachment_path =  @message.attachment.path
    if @message.has_image? && params[:style].present? && (['thumb','big','small'].include? params[:style])
      attachment_path.sub!('original', params[:style])
    end
    if USE_X_ACCEL_REDIRECT # nginx
      head(:x_accel_redirect => attachment_path.sub(RAILS_ROOT,''),
         :content_type => @message.attachment_content_type,
         :content_disposition => "inline")
    else # apache or others
      send_file  attachment_path, :type => @message.attachment_content_type, :disposition => 'inline', :x_sendfile => USE_X_SENDFILE
    end
  end

private

  def find_message_and_check_read_access
    @message = Rails.cache.fetch('message_'+params[:id]) {Message.published.find(params[:id])}
    # unless (logged_in? && @message.conversation.readable_by?(current_user)) || !@message.conversation.private?
    #   flash[:error] = "Sorry, this attachment is unavailable."
    #   redirect_to root_path
    #   return
    # end
  end

end
{'fraction_non_alphanumeric': 0.12065972222222222, 'fraction_numerical': 0.0, 'mean_word_length': 4.488095238095238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '4656804', 'n_tokens_mistral': 712, 'n_tokens_neox': 697, 'n_words': 132}