<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
  include ExceptionNotifiable
  include SuperExceptionNotifier
  include ExceptionNotifierHelper
  self.error_layout = 'error'

  include AuthenticatedSystem
  include Subdomains
  local_addresses.clear

  protect_from_forgery

  before_filter :find_group
  before_filter :check_group_access
  before_filter :find_languages
  before_filter :set_locale
  layout :set_layout

  protected

  def access_denied
    store_location
    raise AccessDenied
  end

  def check_group_access
    if @current_group &&
       (@current_group.private && (!logged_in? || !current_user.user_of?(@current_group)))
      access_denied
    end
  end

  def set_layout
    if current_group.isolate
      'group'
    else
      'newlayout'
    end
  end

  def find_group
    @current_group ||= begin
      subdomains = request.subdomains
      subdomains.delete("www") if request.host == "www.#{AppConfig.domain}"
      _current_group = Group.find(:first, :state => "active", :domain => request.host)
      unless _current_group
        flash[:warn] = t("global.group_not_found", :url => request.host)
        redirect_to domain_url(:custom => AppConfig.domain)
        return
      end
      _current_group
    end<commit_msg>access_denied now redirect to login page instead of raise AccessDenied exception<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
  include ExceptionNotifiable
  include SuperExceptionNotifier
  include ExceptionNotifierHelper
  self.error_layout = 'error'

  include AuthenticatedSystem
  include Subdomains
  local_addresses.clear

  protect_from_forgery

  before_filter :find_group
  before_filter :check_group_access
  before_filter :find_languages
  before_filter :set_locale
  layout :set_layout

  protected

  def access_denied
    store_location
    if logged_in?
      flash[:error] = t("global.permission_denied")
    else
      flash[:error] = t("global.please_login")
    end
    redirect_to login_path
    return
#     raise AccessDenied
  end

  def check_group_access
    if @current_group &&
       (@current_group.private && (!logged_in? || !current_user.user_of?(@current_group)))
      access_denied
    end
  end

  def set_layout
    if current_group.isolate
      'group'
    else
      'newlayout'
    end
  end

  def find_group
    @current_group ||= begin
      subdomains = request.subdomains
      subdomains.delete("www") if request.host == "www.#{AppConfig.domain}"
      _current_group = Group.find(:first, :state => "active", :domain => request.host)
      unless _current_group
        flash[:warn] = t("global.group_not_found", :url => request.host)
        redirect_to domain_url(:custom => AppConfig.domain)
        return
      end
      _current_group
    end
{'fraction_non_alphanumeric': 0.07357212003872217, 'fraction_numerical': 0.0, 'mean_word_length': 3.5790251107828657, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5551208', 'n_tokens_mistral': 913, 'n_tokens_neox': 883, 'n_words': 232}