<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 Rack::Recaptcha::Helpers
  include AuthenticatedSystem
  include Subdomains
  include Sweepers

  if !AppConfig.recaptcha['activate']
    def recaptcha_valid?
      true
    end
  end

  if AppConfig.exception_notification['activate']
    include ExceptionNotifiable
    include SuperExceptionNotifier
    include ExceptionNotifierHelper

    self.exception_notifiable_silent_exceptions = []
    self.exception_notifiable_silent_exceptions << SuperExceptionNotifier::CustomExceptionClasses::PageNotFound
    self.exception_notifiable_silent_exceptions << ActionController::InvalidAuthenticityToken
    self.exception_notifiable_silent_exceptions << ActionController::RoutingError
    self.exception_notifiable_silent_exceptions << ActionController::UnknownAction

    local_addresses.clear

    exception_data :additional_data
    def additional_data
      { :group => find_group}
    end
    protected :additional_data
  end

  self.error_layout = 'application'

  protect_from_forgery

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

  helper_method :recaptcha_tag

  protected

  def check_group_access
    if ((!current_group.registered_only || is_bot?) && !current_group.private) || devise_controller? || (params[:controller] == "users" && action_name == "new" )
      return
    end

    if logged_in?
      if current_group.private && !current_user.user_of?(@current_group)
        access_denied
      end
    else
      respond_to do |format|
        format.json { render :json => {:message => "Permission denied" }}
        format.html { redirect_to new_user_session_path }
      end
    end
  end

  def find_group
    @current_group ||= begin
      subdomains = request.subdomains
      subdomains.delete("www") if request.host == "www.#{AppConfig.domain}"
      _current_group = Group.first(:state => "active", :domain => request.host)
      unless _current_group
        if subdomain = subdomains.first
          _current_group = Group.first(:state => "active", :subdomain => subdomain)
          unless _current_group.nil?
            redirect_to domain_url(:custom => _current_group.domain)
            return
          end
        end
        flash[:warn] = t("global.group_not_found", :url => request.host)
        redirect_to domain_url(:custom => AppConfig.domain)
        return
      end
      _current_group
    end
    @current_group
  end

  def current_group
    @current_group
  end
  helper_method :current_group

  def current_tags
    @current_tags ||=  if params[:tags].kind_of?(String)
      params[:tags].split("+")
    elsif params[:tags].kind_of?(Array)
      params[:tags]
    else
      []<commit_msg>find_group changed<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 Rack::Recaptcha::Helpers
  include AuthenticatedSystem
  include Subdomains
  include Sweepers

  if !AppConfig.recaptcha['activate']
    def recaptcha_valid?
      true
    end
  end

  if AppConfig.exception_notification['activate']
    include ExceptionNotifiable
    include SuperExceptionNotifier
    include ExceptionNotifierHelper

    self.exception_notifiable_silent_exceptions = []
    self.exception_notifiable_silent_exceptions << SuperExceptionNotifier::CustomExceptionClasses::PageNotFound
    self.exception_notifiable_silent_exceptions << ActionController::InvalidAuthenticityToken
    self.exception_notifiable_silent_exceptions << ActionController::RoutingError
    self.exception_notifiable_silent_exceptions << ActionController::UnknownAction

    local_addresses.clear

    exception_data :additional_data
    def additional_data
      { :group => find_group}
    end
    protected :additional_data
  end

  self.error_layout = 'application'

  protect_from_forgery

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

  helper_method :recaptcha_tag

  protected

  def check_group_access
    if ((!current_group.registered_only || is_bot?) && !current_group.private) || devise_controller? || (params[:controller] == "users" && action_name == "new" )
      return
    end

    if logged_in?
      if current_group.private && !current_user.user_of?(@current_group)
        access_denied
      end
    else
      respond_to do |format|
        format.json { render :json => {:message => "Permission denied" }}
        format.html { redirect_to new_user_session_path }
      end
    end
  end

  def find_group
    @current_group ||= begin
      subdomains = request.subdomains
      subdomains.delete("www") if request.host == "www.#{AppConfig.domain}"
      _current_group = Group.first(:state => "active")
      unless _current_group
        if subdomain = subdomains.first
          _current_group = Group.first(:state => "active", :subdomain => subdomain)
          unless _current_group.nil?
            redirect_to domain_url(:custom => _current_group.domain)
            return
          end
        end
        flash[:warn] = t("global.group_not_found", :url => request.host)
        redirect_to domain_url(:custom => AppConfig.domain)
        return
      end
      _current_group
    end
    puts "****************************************#{@current_group}"
    @current_group
  end

  def current_group
    @current_group
  end
  helper_method :current_group

  def current_tags
    @current_tags ||=  if params[:tags].kind_of?(String)
      params[:tags].split("+")
    elsif params[:tags].kind_of?(Array)
      params[:tags]
    else
      []
{'fraction_non_alphanumeric': 0.08875146247701822, 'fraction_numerical': 0.0, 'mean_word_length': 3.603076923076923, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, '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': '1201802', 'n_tokens_mistral': 1718, 'n_tokens_neox': 1668, 'n_words': 369}