<commit_before>class GuildsController < ApplicationController
  before_action :check_permissions, only: [:edit, :update]

  def index
    @guilds ||= Bot::Discord::Omega.guilds(current_user).map do |guild_hash|
      Guild.from_hash(guild_hash, current_user)
    end
  end

  def edit
    @guild = current_guild
  end

  def update
    @guild = current_guild
    if @guild.update(guild_params)
      redirect_to guilds_path
    else
      render :edit
    end
  end

  private

  def check_permissions
    unless current_guild.has_access?(current_user)<commit_msg>added logic to log off when an auth error happens<commit_after>class GuildsController < ApplicationController
  before_action :check_permissions, only: [:edit, :update]

  def index
    begin
      @guilds ||= Bot::Discord::Omega.guilds(current_user).map do |guild_hash|
        Guild.from_hash(guild_hash, current_user)
      end
    rescue RestClient::Unauthorized => ex
      redirect_to destroy_user_session_path
    end
  end

  def edit
    @guild = current_guild
  end

  def update
    @guild = current_guild
    if @guild.update(guild_params)
      redirect_to guilds_path
    else
      render :edit
    end
  end

  private

  def check_permissions
    unless current_guild.has_access?(current_user)
{'fraction_non_alphanumeric': 0.0706436420722135, 'fraction_numerical': 0.0, 'mean_word_length': 3.458041958041958, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '2215129', 'n_tokens_mistral': 428, 'n_tokens_neox': 415, 'n_words': 97}