<commit_before>class ApplicationController < ActionController::Base
  protect_from_forgery
  helper_method :login_required
  before_filter :set_our_current_user
  before_filter :login_required, :only => :admin
  before_filter :admin_required, :only => :admin

  def index
    # only show 10 repositories and 30 commits on index page
    if current_user
      @repositories = AqRepository.public_with_private_user(current_user.id).limit(10)
    else
      @repositories = AqRepository.public.limit(10)
    end
    @commits = AqCommit.of_public_repositories.order("committed_time DESC").limit(30)
  end

  def repositories
    page = (!params[:page] or (params[:page] == "0")) ? 1 : params[:page]

    if current_user
      @repositories = AqRepository.public_with_private_user(current_user.id).paginate :page => page, :per_page => Settings.pagination.all_repositories
    else
      @repositories = AqRepository.public.paginate :page => page, :per_page => Settings.pagination.all_repositories
    end

  end

  def admin
  end

  def check_branch_existancy
    branch = params[:branch] || "master"
    repo = params[:id]

    repo = AqRepository.find(repo)
    branch = repo.branches.find_by_name(branch)

    if !branch and (repo.branches.count > 0)
      return raise ActiveRecord::RecordNotFound
    end
  end

  # We need to access to "current_user" from some models
  # and we can't with Devise, so we use this workaroud
  def set_our_current_user
    User.our_current_user = current_user || nil
  end

  def warning_no_sshkey
    if current_user
      if current_user.ssh_keys.size == 0<commit_msg>Fix before filter to check if no ssh key<commit_after>class ApplicationController < ActionController::Base
  protect_from_forgery
  helper_method :login_required
  before_filter :set_our_current_user
  before_filter :login_required, :only => :admin
  before_filter :admin_required, :only => :admin

  def index
    # only show 10 repositories and 30 commits on index page
    if current_user
      @repositories = AqRepository.public_with_private_user(current_user.id).limit(10)
    else
      @repositories = AqRepository.public.limit(10)
    end
    @commits = AqCommit.of_public_repositories.order("committed_time DESC").limit(30)
  end

  def repositories
    page = (!params[:page] or (params[:page] == "0")) ? 1 : params[:page]

    if current_user
      @repositories = AqRepository.public_with_private_user(current_user.id).paginate :page => page, :per_page => Settings.pagination.all_repositories
    else
      @repositories = AqRepository.public.paginate :page => page, :per_page => Settings.pagination.all_repositories
    end

  end

  def admin
  end

  def check_branch_existancy
    branch = params[:branch] || "master"
    repo = params[:id]

    repo = AqRepository.find(repo)
    branch = repo.branches.find_by_name(branch)

    if !branch and (repo.branches.count > 0)
      return raise ActiveRecord::RecordNotFound
    end
  end

  # We need to access to "current_user" from some models
  # and we can't with Devise, so we use this workaroud
  def set_our_current_user
    User.our_current_user = current_user || nil
  end

  def warning_no_sshkey
    repository = AqRepository.find(params[:id])
    if current_user.id == repository.owner.id
      if current_user.ssh_keys.size == 0
{'fraction_non_alphanumeric': 0.08829755065013607, 'fraction_numerical': 0.008466888418506199, 'mean_word_length': 3.937313432835821, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '5312550', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1016, 'n_words': 254}