<commit_before>class Tournaments::InviteRequestsController < ApplicationController
  before_filter :authenticate_user!
  before_filter :find_tournament, :only => [:index, :update]
  before_filter :require_owner!, :only => [:update]

  layout 'tournament_title', :only => [:index]

  def index
    @pending_invite_requests = @tournament.invite_requests.where(invite_id: nil)
  end

  def show
  end

  def create
    @tournament = Tournament.where(public: true).friendly.find(params[:tournament_id])
    @invite_request = @tournament.invite_requests.build(user: current_user)
    if @invite_request.save
      redirect_to root_path, :notice => t('tournaments.invite_requests.create.success')
    else
      redirect_to root_path, :notice => t('tournaments.invite_requests.create.failure')
    end
  end

  def update
    @invite_request = InviteRequest.find(params[:id])
    if @invite_request && params[:approve]
      @invite = @tournament.invites.build(email: @invite_request.user.email)
      @invite.owner = current_user
      if @invite.save
        @invite_request.update_attributes(invite_id: @invite.id)
        Notifications.tournament_invitation(@invite).deliver
        redirect_to tournament_invite_requests_path(@tournament),
          :notice => t('tournaments.invites.create.success', :email => @invite.email)
      else
        redirect_to tournament_invite_requests_path(@tournament),
          :notice => t('tournaments.invites.create.failure', :email => @invite.email)
      end
    else
      # TODO: handle invalid params?<commit_msg>Clean up update on invite request controller<commit_after>class Tournaments::InviteRequestsController < ApplicationController
  before_filter :authenticate_user!
  before_filter :find_tournament, :only => [:index, :update]
  before_filter :require_owner!, :only => [:update]

  layout 'tournament_title', :only => [:index]

  def index
    @pending_invite_requests = @tournament.invite_requests.where(invite_id: nil)
  end

  def create
    @tournament = Tournament.where(public: true).friendly.find(params[:tournament_id])
    @invite_request = @tournament.invite_requests.build(user: current_user)
    if @invite_request.save
      redirect_to root_path, :notice => t('tournaments.invite_requests.create.success')
    else
      redirect_to root_path, :notice => t('tournaments.invite_requests.create.failure')
    end
  end

  def update
    @invite_request = InviteRequest.find(params[:id])
    @invite = @tournament.invites.build(email: @invite_request.user.email, owner: current_user)
    if @invite.save
      @invite_request.update_attributes!(invite_id: @invite)
      Notifications.tournament_invitation(@invite).deliver
      redirect_to tournament_invite_requests_path(@tournament),
        :notice => t('tournaments.invites.create.success', :email => @invite.email)
    else
      redirect_to tournament_invite_requests_path(@tournament),
        :notice => t('tournaments.invites.create.failure', :email => @invite.email)
{'fraction_non_alphanumeric': 0.11304347826086956, 'fraction_numerical': 0.0, 'mean_word_length': 4.590654205607477, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '253510', 'n_tokens_mistral': 959, 'n_tokens_neox': 917, 'n_words': 161}