<commit_before>class PostsController < ApplicationController
  before_action :doorkeeper_authorize!, :only => [ :for_project_user, :for_user ], :if => lambda { authenticate_with_oauth? }
  before_filter :authenticate_user!, :except => [:index, :show, :browse, :for_user ], :unless => lambda { authenticated_with_oauth? }
  load_only = [ :show, :edit, :update, :destroy ]
  before_filter :load_post, :only => load_only
  blocks_spam :only => load_only, :instance => :post
  before_filter :load_parent, :except => [:browse, :for_project_user, :for_user]
  before_filter :load_new_post, :only => [:new, :create]
  before_filter :owner_required, :only => [:create, :edit, :update, :destroy]

  layout "bootstrap"
  
  def index
    scope = @parent.is_a?(User) ? @parent.journal_posts : @parent.posts
    if @parent.is_a?(User)
      block_if_spammer(@parent) && return
    elsif !@parent.is_a?(Site)
      block_if_spam(@parent) && return
    end
    @posts = scope.not_flagged_as_spam.published.page(params[:page]).
      per_page(10).order("published_at DESC")
    
    # Grab the monthly counts of all posts to show archives
    get_archives
    
    if @parent == current_user || (@parent.respond_to?(:editable_by?) && @parent.editable_by?(current_user))
      @drafts = scope.unpublished.order("created_at DESC")
    end
    
    respond_to do |format|
      format.html
      format.atom
      format.json do
        render json: @posts, :include => {
          user: {
            only: [:id, :login], 
            methods: [:user_icon_url, :medium_user_icon_url]
          }
        }
      end
    end
  end
  
  def show
    case @post.parent_type
    when "User" && params[:login].blank?
      redirect_to journal_post_path(@parent.login, @post)
      return
    when "Project" && params[:project_id].blank?
      redirect_to project_journal_post_path(@parent, @post)
      return
    when "Site" && (params[:project_id] || params[:login])
      redirect_to site_post_path(@post)
      return
    end

    if params[:login] && @parent.is_a?(Project)<commit_msg>Include parent details in response to posts/index.<commit_after>class PostsController < ApplicationController
  before_action :doorkeeper_authorize!, :only => [ :for_project_user, :for_user ], :if => lambda { authenticate_with_oauth? }
  before_filter :authenticate_user!, :except => [:index, :show, :browse, :for_user ], :unless => lambda { authenticated_with_oauth? }
  load_only = [ :show, :edit, :update, :destroy ]
  before_filter :load_post, :only => load_only
  blocks_spam :only => load_only, :instance => :post
  before_filter :load_parent, :except => [:browse, :for_project_user, :for_user]
  before_filter :load_new_post, :only => [:new, :create]
  before_filter :owner_required, :only => [:create, :edit, :update, :destroy]

  layout "bootstrap"
  
  def index
    scope = @parent.is_a?(User) ? @parent.journal_posts : @parent.posts
    if @parent.is_a?(User)
      block_if_spammer(@parent) && return
    elsif !@parent.is_a?(Site)
      block_if_spam(@parent) && return
    end
    @posts = scope.not_flagged_as_spam.published.page(params[:page]).
      per_page(10).order("published_at DESC")
    
    # Grab the monthly counts of all posts to show archives
    get_archives
    
    if @parent == current_user || (@parent.respond_to?(:editable_by?) && @parent.editable_by?(current_user))
      @drafts = scope.unpublished.order("created_at DESC")
    end
    
    respond_to do |format|
      format.html
      format.atom
      format.json do
        render json: @posts, :include => {
          user: {
            only: [:id, :login], 
            methods: [:user_icon_url, :medium_user_icon_url]
          },
          parent: {
            only: [ :id, :title, :name ],
            methods: [ :icon_url, :site_name_short ]
          }
        }
      end
    end
  end
  
  def show
    case @post.parent_type
    when "User" && params[:login].blank?
      redirect_to journal_post_path(@parent.login, @post)
      return
    when "Project" && params[:project_id].blank?
      redirect_to project_journal_post_path(@parent, @post)
      return
    when "Site" && (params[:project_id] || params[:login])
      redirect_to site_post_path(@post)
      return
    end

    if params[:login] && @parent.is_a?(Project)
{'fraction_non_alphanumeric': 0.1318298070216229, 'fraction_numerical': 0.0009300162752848175, 'mean_word_length': 3.2977022977022976, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '5545401', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1410, 'n_words': 301}