<commit_before>class Admin::ArticlesController < Admin::ApplicationController
  before_filter :load_article, :only => [ :show, :edit, :update, :destroy ]
  load_and_authorize_resource

  respond_to :html, :js

  def index
    load_index
    respond_with do |format|
      format.js { render :index }
    end
  end

  def show
    @api_key = APP_CONFIG['api_key']

    respond_with(@article) do |format|
      format.js { render :show }
    end
  end

  # GET /articles/new
  def new
    load_index
    @article = Article.new
    respond_with(@article) do |format|
      format.js { render :index }
    end
  end

  # POST /articles
  def create
    load_index
    @article = Article.new(article_params)
    @article.save
    respond_with(@article) do |format|
      format.js { render :index }
    end
  end

  # GET /articles/:id/edit
  def edit
    respond_with(@article) do |format|
      format.js { render :show }
    end
  end

  # PUT /articles/:id(.:format)
  def update
    @article.update_attributes(article_params)
    respond_with(@article) do |format|
      format.js { render :show }
    end
  end

  # DELETE /articles/:id(.:format)
  def destroy
    @article.destroy
    redirect_to articles_path
  end

  protected
  def load_article()
    # Load one article given query params
    id_hash = Article.from_uri(params[:id])
    @article = Article.where(id_hash).first

    # raise error if article wasn't found
    raise ActiveRecord::RecordNotFound.new if @article.blank?
  end

  def load_index
    collection = Article
    collection = collection.cited(params[:cited])  if params[:cited]
    collection = collection.query(params[:query])  if params[:query]
    if params[:class_name]
      @class_name = params[:class_name]
      collection = collection.includes(:alerts)
      if @class_name == "All Alerts"
        collection = collection.where("alerts.unresolved = 1 ")
      else
        collection = collection.where("alerts.unresolved = 1 AND alerts.class_name = ?", @class_name)
      end
    end
    collection = collection.order_articles(params[:order])

    @articles = collection.paginate(:page => params[:page])

    if params[:source]
      @sources = Source.where("lower(name) in (?)", params[:source].split(",")).order("name")
    else
      @sources = Source.order("name")
    end
  end

  private

  def article_params
    params.require(:article).permit(:doi, :title, :published_on, :pub_med, :pub_med_central, :mendeley, :url)
  end<commit_msg>ALM-382 make strong_parameters work with cancan<commit_after>class Admin::ArticlesController < Admin::ApplicationController
  before_filter :load_article, :only => [ :show, :edit, :update, :destroy ]
  before_filter :new_article, :only => [:create]
  load_and_authorize_resource

  respond_to :html, :js

  def index
    load_index
    respond_with do |format|
      format.js { render :index }
    end
  end

  def show
    @api_key = APP_CONFIG['api_key']

    respond_with(@article) do |format|
      format.js { render :show }
    end
  end

  # GET /articles/new
  def new
    load_index
    @article = Article.new
    respond_with(@article) do |format|
      format.js { render :index }
    end
  end

  # POST /articles
  def create
    load_index
    @article.save
    respond_with(@article) do |format|
      format.js { render :index }
    end
  end

  # GET /articles/:id/edit
  def edit
    respond_with(@article) do |format|
      format.js { render :show }
    end
  end

  # PUT /articles/:id(.:format)
  def update
    @article.update_attributes(safe_params)
    respond_with(@article) do |format|
      format.js { render :show }
    end
  end

  # DELETE /articles/:id(.:format)
  def destroy
    @article.destroy
    redirect_to articles_path
  end

  protected
  def load_article
    # Load one article given query params
    id_hash = Article.from_uri(params[:id])
    @article = Article.where(id_hash).first

    # raise error if article wasn't found
    raise ActiveRecord::RecordNotFound.new if @article.blank?
  end

  def new_article
    @article = Article.new(safe_params)
  end

  def load_index
    collection = Article
    collection = collection.cited(params[:cited])  if params[:cited]
    collection = collection.query(params[:query])  if params[:query]
    if params[:class_name]
      @class_name = params[:class_name]
      collection = collection.includes(:alerts)
      if @class_name == "All Alerts"
        collection = collection.where("alerts.unresolved = 1 ")
      else
        collection = collection.where("alerts.unresolved = 1 AND alerts.class_name = ?", @class_name)
      end
    end
    collection = collection.order_articles(params[:order])

    @articles = collection.paginate(:page => params[:page])

    if params[:source]
      @sources = Source.where("lower(name) in (?)", params[:source].split(",")).order("name")
    else
      @sources = Source.order("name")
    end
  end

  private

  def safe_params
    params.require(:article).permit(:doi, :title, :pub_med, :pub_med_central, :mendeley, :url, :published_on)
  end
{'fraction_non_alphanumeric': 0.11326349080846017, 'fraction_numerical': 0.0013836726625815379, 'mean_word_length': 3.1407528641571196, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '5516359', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1566, 'n_words': 383}