<commit_before>require 'classification_lifecycle'

class Api::V1::ClassificationsController < Api::ApiController
  include JsonApiController::PunditPolicy

  skip_before_filter :require_login, only: :create
  require_authentication :show, :index, :destroy, :update, :incomplete, :project,
    scopes: [:classification]

  resource_actions :default

  schema_type :json_schema

  rescue_from JsonApiController::AccessDenied, with: :access_denied

  before_action :filter_plural_subject_ids,
    only: [ :index, :gold_standard, :incomplete, :project ]

  def create
    super { |classification| lifecycle(:create, classification) }
  end

  def update
    super
    controlled_resources.each { |resource| lifecycle(:update, resource) }
  end

  def gold_standard
    skip_policy_scope
    resources = Pundit.policy!(api_user, GoldStandardAnnotation).scope_for(:index)
    resources = resources.where(workflow_id: params[:workflow_id]) if params[:workflow_id]

    gold_standard_page = GoldStandardAnnotationSerializer.page(
      params,
      resources,
      context
    )
    render json_api: gold_standard_page, generate_response_obj_etag: true
  end

  def incomplete
    index
  end

  def project
    if params[:last_id] && !params[:project_id]
      raise Classification::MissingParameter.new("Project ID required if last_id is included")
    end

    resources = controlled_resources
    resources = resources.where(project_id: params[:project_id]) if params[:project_id]
    resources = resources.after_id(params[:last_id]) if params[:last_id]

    render json_api: serializer.page(params, resources, context),<commit_msg>Keep the old filtering by ID that controlled_resources used to do<commit_after>require 'classification_lifecycle'

class Api::V1::ClassificationsController < Api::ApiController
  include JsonApiController::PunditPolicy

  skip_before_filter :require_login, only: :create
  require_authentication :show, :index, :destroy, :update, :incomplete, :project,
    scopes: [:classification]

  resource_actions :default

  schema_type :json_schema

  rescue_from JsonApiController::AccessDenied, with: :access_denied

  before_action :filter_plural_subject_ids,
    only: [ :index, :gold_standard, :incomplete, :project ]

  def create
    super { |classification| lifecycle(:create, classification) }
  end

  def update
    super
    controlled_resources.each { |resource| lifecycle(:update, resource) }
  end

  def gold_standard
    skip_policy_scope
    resources = Pundit.policy!(api_user, GoldStandardAnnotation).scope_for(:index)
    resources = resources.where(workflow_id: params[:workflow_id]) if params[:workflow_id]

    if resource_ids.present?
      resources = resources.where(id: resource_ids)
    end

    gold_standard_page = GoldStandardAnnotationSerializer.page(
      params,
      resources,
      context
    )
    render json_api: gold_standard_page, generate_response_obj_etag: true
  end

  def incomplete
    index
  end

  def project
    if params[:last_id] && !params[:project_id]
      raise Classification::MissingParameter.new("Project ID required if last_id is included")
    end

    resources = controlled_resources
    resources = resources.where(project_id: params[:project_id]) if params[:project_id]
    resources = resources.after_id(params[:last_id]) if params[:last_id]

    render json_api: serializer.page(params, resources, context),
{'fraction_non_alphanumeric': 0.0873015873015873, 'fraction_numerical': 0.0005878894767783657, 'mean_word_length': 4.897746967071058, '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': '7315534', 'n_tokens_mistral': 999, 'n_tokens_neox': 966, 'n_words': 227}