<commit_before>class ApplicationController < ActionController::Base

  ROLES =
      {	  :dmp_admin              => 1,
          :resource_editor        => 2,
          :template_editor        => 3,
          :institutional_reviewer => 4,
          :institutional_admin    => 5}


  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  # enable_authorization

  helper_method :current_user, :safe_has_role?, :require_login, :user_role_in?

  protected

  	def current_user
    	@current_user ||= User.find_by_id(session[:user_id]) if session[:user_id]
    end

    def require_login
      if session[:user_id].blank?
        flash[:error] = "You must be logged in to access this page."
        session[:return_to] = request.original_url
        redirect_to choose_institution_path and return
      end
    end

    #require that a user is logged out
    def require_logout<commit_msg>Quick code cleanup to keep enumeration cleaner and only have constants defined in one place.<commit_after>class ApplicationController < ActionController::Base

  ROLES =
      {	  :dmp_admin              => Role::DMP_ADMIN,
          :resource_editor        => Role::RESOURCE_EDITOR,
          :template_editor        => Role::TEMPLATE_EDITOR,
          :institutional_reviewer => Role::INSTITUTIONAL_REVIEWER,
          :institutional_admin    => Role::INSTITUTIONAL_ADMIN}


  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  # enable_authorization

  helper_method :current_user, :safe_has_role?, :require_login, :user_role_in?

  protected

  	def current_user
    	@current_user ||= User.find_by_id(session[:user_id]) if session[:user_id]
    end

    def require_login
      if session[:user_id].blank?
        flash[:error] = "You must be logged in to access this page."
        session[:return_to] = request.original_url
        redirect_to choose_institution_path and return
      end
    end

    #require that a user is logged out
    def require_logout
{'fraction_non_alphanumeric': 0.07710280373831775, 'fraction_numerical': 0.002336448598130841, 'mean_word_length': 2.979553903345725, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3857366', 'n_tokens_mistral': 647, 'n_tokens_neox': 618, 'n_words': 169}