<commit_before># rails_admin-1.0 ready
module RailsAdmin
  MainController.class_eval do
    include OverrideActionsHelper
    include RestApiHelper
    include SwaggerHelper
    include AlgorithmHelper
    include NotebooksHelper
    include TraceHelper

    before_action :process_context

    alias_method :rails_admin_list_entries, :list_entries

    def list_entries(model_config = @model_config, auth_scope_key = :index, additional_scope = get_association_scope_from_params, pagination = !(params[:associated_collection] || params[:all] || params[:bulk_ids]))
      scope = rails_admin_list_entries(model_config, auth_scope_key, additional_scope, pagination)
      if (model = model_config.abstract_model.model).is_a?(Class)
        if model.include?(CrossOrigin::CenitDocument)
          if (acc = Account.current)
            CrossOrigin.names.each do |origin|
              even = params[origin_param = "#{origin}_origin"].to_i.even?
              acc.meta[origin_param] = (even ? 0 : 1)
            end
          end
          origins = model.origins
          origins << nil if origins.include?(:default)
          scope = scope.any_in(origin: origins)
        end

        if (filter_token = params[:filter_token]) &&
           (filter_token = Cenit::Token.where(token: filter_token).first) &&
           (criteria = filter_token.data && filter_token.data['criteria']).is_a?(Hash)
          scope = scope.and(criteria)
        end
      elsif (output = Setup::AlgorithmOutput.where(id: params[:algorithm_output]).first) &&
        output.data_type == model.data_type
        scope = scope.any_in(id: output.output_ids)
      end
      # Contextual record
      if get_context_record
        or_criteria = []
        model_config._fields.each do |f|
          next unless f.is_a?(RailsAdmin::Config::Fields::Types::ContextualBelongsTo) && f.association.klass == get_context_model
          or_criteria <<
            if f.include_blanks_on_collection_scope
              [
                { f.association.foreign_key => { '$exists': false } },
                { f.association.foreign_key => { '$in': [nil, get_context_id] } }
              ]
            else
              { f.association.foreign_key => get_context_id }
            end
        end
        scope = scope.or(or_criteria.flatten) unless or_criteria.empty?
      end<commit_msg>Fixing origins toggling<commit_after># rails_admin-1.0 ready
module RailsAdmin
  MainController.class_eval do
    include OverrideActionsHelper
    include RestApiHelper
    include SwaggerHelper
    include AlgorithmHelper
    include NotebooksHelper
    include TraceHelper

    before_action :process_context

    alias_method :rails_admin_list_entries, :list_entries

    def list_entries(model_config = @model_config, auth_scope_key = :index, additional_scope = get_association_scope_from_params, pagination = !(params[:associated_collection] || params[:all] || params[:bulk_ids]))
      scope = rails_admin_list_entries(model_config, auth_scope_key, additional_scope, pagination)
      if (model = model_config.abstract_model.model).is_a?(Class)
        if model.include?(CrossOrigin::CenitDocument)
          if (acc = Account.current)
            CrossOrigin.names.each do |origin|
              origin_param = "#{origin}_origin"
              if params.key?(origin_param)
                even = params[origin_param].to_i.even?
                acc.meta[origin_param] = (even ? 0 : 1)
              end
            end
          end
          origins = model.origins
          origins.select! { |origin| params["#{origin}_origin"].to_i.even? } unless acc
          origins << nil if origins.include?(:default)
          scope = scope.any_in(origin: origins)
        end

        if (filter_token = params[:filter_token]) &&
           (filter_token = Cenit::Token.where(token: filter_token).first) &&
           (criteria = filter_token.data && filter_token.data['criteria']).is_a?(Hash)
          scope = scope.and(criteria)
        end
      elsif (output = Setup::AlgorithmOutput.where(id: params[:algorithm_output]).first) &&
        output.data_type == model.data_type
        scope = scope.any_in(id: output.output_ids)
      end
      # Contextual record
      if get_context_record
        or_criteria = []
        model_config._fields.each do |f|
          next unless f.is_a?(RailsAdmin::Config::Fields::Types::ContextualBelongsTo) && f.association.klass == get_context_model
          or_criteria <<
            if f.include_blanks_on_collection_scope
              [
                { f.association.foreign_key => { '$exists': false } },
                { f.association.foreign_key => { '$in': [nil, get_context_id] } }
              ]
            else
              { f.association.foreign_key => get_context_id }
            end
        end
        scope = scope.or(or_criteria.flatten) unless or_criteria.empty?
      end
{'fraction_non_alphanumeric': 0.10089869281045752, 'fraction_numerical': 0.0016339869281045752, 'mean_word_length': 2.590175953079179, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '4623757', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1408, 'n_words': 260}