<commit_before>class Admin::Page::LinksController < Admin::BaseController
  default_param :link, :author_id, :only => [:create, :update], &lambda { current_user.id }

  before_filter :set_section
  before_filter :set_links,   :only => [:index]
  before_filter :set_link,    :only => [:show, :edit, :update, :destroy]

  def new
    @link = @section.links.build params[:link] || {}
  end

  def edit
  end

  def create
    @link = @section.links.build params[:link]
    if @link.save
      trigger_events(@link)
      flash[:notice] = t(:'adva.links.flash.create.success')
      redirect_to [:edit, :admin, @site, @section, @link]
    else
      set_categories
      flash.now[:error] = t(:'adva.links.flash.create.failure')
      render :action => 'new'
    end
  end

  def update
    params[:link][:version].present? ? rollback : update_attributes
  end

  def update_attributes
    @link.attributes = params[:link]

    if save_with_revision? ? @link.save : @link.save_without_revision
      trigger_events(@link)
      flash[:notice] = t(:'adva.links.flash.update.success')
      redirect_to [:edit, :admin, @site, @section, @link]
    else
      set_categories
      flash.now[:error] = t(:'adva.links.flash.update.failure')
      render :action => 'edit', :cl => content_locale
    end
  end

  def rollback
    version = params[:link][:version].to_i

    if @link.version != version and @link.revert_to(version)
      trigger_event(@link, :rolledback)
      flash[:notice] = t(:'adva.links.flash.rollback.success', :version => version)
    else
      flash[:error] = t(:'adva.links.flash.rollback.failure', :version => version)
    end
    redirect_to [:edit, :admin, @site, @section, @link]
  end

  def destroy
    if @link.destroy
      trigger_events(@link)
      flash[:notice] = t(:'adva.links.flash.destroy.success')
      redirect_to [:admin, @site, @section, :contents]
    else
      set_categories
      flash.now[:error] = t(:'adva.links.flash.destroy.failure')
      render :action => 'edit'
    end
  end

  protected

    def current_resource
      @link || @section
    end

    def set_menu
      @menu = Menus::Admin::Links.new
    end

    def set_links
      @links = @section.links.filtered params[:filters]
    end<commit_msg>fix links controller.<commit_after>class Admin::Page::LinksController < Admin::BaseController
  default_param :link, :author_id, :only => [:create, :update], &lambda { current_user.id }

  before_filter :set_section
  before_filter :set_links,   :only => [:index]
  before_filter :set_link,    :only => [:show, :edit, :update, :destroy]

  def new
    @link = @section.links.build params[:link] || {}
  end

  def edit
  end

  def create
    @link = @section.links.build params[:link]
    if @link.save
      trigger_events(@link)
      flash[:notice] = t(:'adva.links.flash.create.success')
      redirect_to [:edit, :admin, @site, @section, @link]
    else
      flash.now[:error] = t(:'adva.links.flash.create.failure')
      render :action => 'new'
    end
  end

  def update
    @link.attributes = params[:link]

    if @link.save
      trigger_events(@link)
      flash[:notice] = t(:'adva.links.flash.update.success')
      redirect_to [:edit, :admin, @site, @section, @link]
    else
      flash.now[:error] = t(:'adva.links.flash.update.failure')
      render :action => 'edit', :cl => content_locale
    end
  end

  def destroy
    if @link.destroy
      trigger_events(@link)
      flash[:notice] = t(:'adva.links.flash.destroy.success')
      redirect_to [:admin, @site, @section, :contents]
    else
      flash.now[:error] = t(:'adva.links.flash.destroy.failure')
      render :action => 'edit'
    end
  end

  protected

    def current_resource
      @link || @section
    end

    def set_menu
      @menu = Menus::Admin::Links.new
    end

    def set_links
      @links = @section.links.filtered params[:filters]
    end
{'fraction_non_alphanumeric': 0.1446524749935881, 'fraction_numerical': 0.0, 'mean_word_length': 3.1009463722397475, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '3135403', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1271, 'n_words': 278}