<commit_before>class Api::V1::ProjectsController < Api::ApiController
  include FilterByOwner
  include TranslatableResource

  doorkeeper_for :update, :create, :destroy, scopes: [:project]
  resource_actions :default
  schema_type :json_schema

  alias_method :project, :controlled_resource

  CONTENT_PARAMS = [:description,
                    :title,
                    :science_case,
                    :introduction,
                    :faq,
                    :education_content,
                    :result,
                    team_members: [:name, :bio, :twitter, :institution],
                    guide: [:image, :explanation]]

  CONTENT_FIELDS = [:title,
                    :description,
                    :guide,
                    :faq,
                    :education_content,
                    :result,
                    :team_members,
                    :science_case,
                    :introduction]

  INDEX_FIELDS = [:title, :description]

  before_action :add_owner_ids_to_filter_param!, only: :index

  private

  def create_response(projects)
    serializer.resource({ include: 'owners' },
                        resource_scope(projects),
                        fields: CONTENT_FIELDS)
  end

  def content_from_params(ps)
    ps[:title] = ps[:display_name]
    content = ps.slice(*CONTENT_FIELDS)
    content[:language] = ps[:primary_language]
    ps.except!(*CONTENT_FIELDS)
    content.select { |k,v| !!v }
  end

  def build_resource_for_create(create_params)
    create_params[:project_contents] = [ProjectContent.new(content_from_params(create_params))]
    add_user_as_linked_owner(create_params)
    super(create_params)
  end

  def build_update_hash(update_params, id)
    content_update = content_from_params(update_params)
    unless content_update.blank?
      Project.find(id).primary_content.update!(content_update)
    end
    super(update_params, id)
  end

  def new_items(resource, relation, value)
    super(resource, relation, value).map do |object|
      object.dup.tap do |dup_object|
        if dup_object.is_a?(Workflow)
          dup_object.workflow_contents = object.workflow_contents.map(&:dup)
        end
      end
    end
  end

  def context
    case action_name
    when "index"
      { languages: current_languages, fields: INDEX_FIELDS }
    when "show"
      { languages: current_languages, fields: CONTENT_FIELDS }
    else
      { fields: CONTENT_FIELDS }
    end
  end
end<commit_msg>Always return all content for projects on index<commit_after>class Api::V1::ProjectsController < Api::ApiController
  include FilterByOwner
  include TranslatableResource

  doorkeeper_for :update, :create, :destroy, scopes: [:project]
  resource_actions :default
  schema_type :json_schema

  alias_method :project, :controlled_resource

  CONTENT_PARAMS = [:description,
                    :title,
                    :science_case,
                    :introduction,
                    :faq,
                    :education_content,
                    :result,
                    team_members: [:name, :bio, :twitter, :institution],
                    guide: [:image, :explanation]]

  CONTENT_FIELDS = [:title,
                    :description,
                    :guide,
                    :faq,
                    :education_content,
                    :result,
                    :team_members,
                    :science_case,
                    :introduction]


  before_action :add_owner_ids_to_filter_param!, only: :index

  private

  def create_response(projects)
    serializer.resource({ include: 'owners' },
                        resource_scope(projects),
                        fields: CONTENT_FIELDS)
  end

  def content_from_params(ps)
    ps[:title] = ps[:display_name]
    content = ps.slice(*CONTENT_FIELDS)
    content[:language] = ps[:primary_language]
    ps.except!(*CONTENT_FIELDS)
    content.select { |k,v| !!v }
  end

  def build_resource_for_create(create_params)
    create_params[:project_contents] = [ProjectContent.new(content_from_params(create_params))]
    add_user_as_linked_owner(create_params)
    super(create_params)
  end

  def build_update_hash(update_params, id)
    content_update = content_from_params(update_params)
    unless content_update.blank?
      Project.find(id).primary_content.update!(content_update)
    end
    super(update_params, id)
  end

  def new_items(resource, relation, value)
    super(resource, relation, value).map do |object|
      object.dup.tap do |dup_object|
        if dup_object.is_a?(Workflow)
          dup_object.workflow_contents = object.workflow_contents.map(&:dup)
        end
      end
    end
  end

  def context
    case action_name
    when "show", "index"
      { languages: current_languages, fields: CONTENT_FIELDS }
    else
      { fields: CONTENT_FIELDS }
    end
  end
end
{'fraction_non_alphanumeric': 0.08815653964984552, 'fraction_numerical': 0.00041194644696189496, 'mean_word_length': 2.314675767918089, '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': '5891088', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1392, 'n_words': 272}