<commit_before># Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base

  helper :all # include all helpers, all the time

  # See ActionController::RequestForgeryProtection for details
  # Uncomment the :secret if you're not using the cookie session store
  protect_from_forgery # :secret => '56b4f0ad244d35b7e0d30ba0c5e1ae61'

  # Provide access to page_title in controllers
  include PageTitleHelper

  # Setup authentication (e.g., login)
  include AuthenticatedSystem

  # Setup exception handling (e.g., what to do when exception raised)
  include ExceptionHandlingMixin

  # Setup breadcrumbs
  include BreadcrumbsMixin
  add_breadcrumbs(SETTINGS.breadcrumbs)

  # Setup theme
  layout "application"
  theme THEME_NAME # DEPENDENCY: lib/theme_reader.rb

  # Make sure @event is always assigned
  before_filter :assign_events

protected

  #---[ General ]---------------------------------------------------------

  # Return the current_user's email address
  def current_email
    (current_user != :false ? current_user.email : nil) || session[:email]
  end

  #---[ Access control ]--------------------------------------------------

  # Can the current user edit the current +record+?
  def can_edit?(record=nil)
    record ||= @proposal || @user
    raise ArgumentError, "No record specified" unless record

    if logged_in?
      if current_user.admin?
        true
      else
        # Normal user
        case record
        when Proposal
          accepting_proposals?(record) && record.can_alter?(current_user)<commit_msg>Added ApplicationController#current_user_or_nil helper.<commit_after># Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base

  helper :all # include all helpers, all the time

  # See ActionController::RequestForgeryProtection for details
  # Uncomment the :secret if you're not using the cookie session store
  protect_from_forgery # :secret => '56b4f0ad244d35b7e0d30ba0c5e1ae61'

  # Provide access to page_title in controllers
  include PageTitleHelper

  # Setup authentication (e.g., login)
  include AuthenticatedSystem

  # Setup exception handling (e.g., what to do when exception raised)
  include ExceptionHandlingMixin

  # Setup breadcrumbs
  include BreadcrumbsMixin
  add_breadcrumbs(SETTINGS.breadcrumbs)

  # Setup theme
  layout "application"
  theme THEME_NAME # DEPENDENCY: lib/theme_reader.rb

  # Make sure @event is always assigned
  before_filter :assign_events

protected

  #---[ General ]---------------------------------------------------------

  # Return the current User record or a nil if not logged in.
  def current_user_or_nil
    return(current_user.kind_of?(User) ? current_user : nil)
  end
  helper_method :current_user_or_nil

  # Return the current_user's email address
  def current_email
    (current_user != :false ? current_user.email : nil) || session[:email]
  end

  #---[ Access control ]--------------------------------------------------

  # Can the current user edit the current +record+?
  def can_edit?(record=nil)
    record ||= @proposal || @user
    raise ArgumentError, "No record specified" unless record

    if logged_in?
      if current_user.admin?
        true
      else
        # Normal user
        case record
        when Proposal
          accepting_proposals?(record) && record.can_alter?(current_user)
{'fraction_non_alphanumeric': 0.12427345696097426, 'fraction_numerical': 0.00996401882092444, 'mean_word_length': 2.9368191721132897, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1856564', 'n_tokens_mistral': 1012, 'n_tokens_neox': 978, 'n_words': 323}