<commit_before>class Admin::BaseController < ApplicationController
  include Admin::EditionRoutesHelper

  layout 'admin'
  prepend_before_filter :authenticate_user!
  before_filter :require_signin_permission!
  before_filter :skip_slimmer

  def limit_edition_access!
    forbidden! unless @edition.accessible_by?(current_user)
  end

  def require_fatality_handling_permission!
    forbidden! unless current_user.can_handle_fatalities?
  end

  def require_import_permission!
    authorise_user!(User::Permissions::IMPORT)
  end

  private

  def forbidden!
    render "admin/editions/forbidden", status: 403
  end
end<commit_msg>Add enforcer to admin controllers<commit_after>class Admin::BaseController < ApplicationController
  include Admin::EditionRoutesHelper

  layout 'admin'
  prepend_before_filter :authenticate_user!
  before_filter :require_signin_permission!
  before_filter :skip_slimmer

  def limit_edition_access!
    forbidden! unless @edition.accessible_by?(current_user)
  end

  def require_fatality_handling_permission!
    forbidden! unless current_user.can_handle_fatalities?
  end

  def require_import_permission!
    authorise_user!(User::Permissions::IMPORT)
  end

  def can?(action, subject)
    enforcer_for(subject).can?(action)
  end
  helper_method :can?

  def enforce_permission!(action, subject)
    unless can?(action, subject)
      puts "You can't #{action} that #{subject.inspect}"
      forbidden!
    end
  end

  private

  def enforcer_for(subject)
    actor = current_user || User.new
    enforcer = Whitehall::Authority::Enforcer.new(actor, subject)
  end

  def forbidden!
    render "admin/editions/forbidden", status: 403
  end
end
{'fraction_non_alphanumeric': 0.07605466428995841, 'fraction_numerical': 0.0035650623885918, 'mean_word_length': 5.101449275362318, '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': '2479703', 'n_tokens_mistral': 541, 'n_tokens_neox': 524, 'n_words': 110}