<commit_before>class TransactsController < ApplicationController
  skip_before_filter :require_activation
  before_filter :login_or_oauth_required
  before_filter :find_group_by_asset
  skip_before_filter :verify_authenticity_token, :set_person_locale, :if => :oauth?

  def index
    @transactions = current_person.transactions.select {|transact| transact.group == @group}
    respond_to do |format|
      format.html
      format.xml { render :xml => @transactions.to_xml(:root => "txns") }
      format.json { render :json => @transactions.as_json }
    end
  end

  def show
    @transact = current_person.transactions.find(params[:id])
    if nil == @transact
        flash[:error] = t('error_could_not_find_transaction')
        redirect_to home_url
        return
    end
    respond_to do |format|
      format.html
      format.xml { render :xml => @transact.to_xml }
      format.json { render :json => @transact.as_json }
    end
  end

  def new
    @amount = params[:amount] || ""
    if params[:to]
      @worker = opentransact_find_worker(params[:to])
      if nil == @worker
        flash[:error] = t('error_could_not_find_payee')
        render :action => "new"
        return
      end
    end
  end

  def create
    @worker = opentransact_find_worker(params[:to])
    if nil == @worker
      flash[:error] = t('error_could_not_find_payee')
      render :action => "new"
      return
    end

    # Transact.to and Transact.memo - makes @transact look opentransacty
    #
    @transact = Transact.new(:to => params[:to], :memo => params[:memo], :amount => params[:amount], :callback_url => params[:callback_url], :redirect_url => params[:redirect_url])
    @transact.customer = current_person
    @transact.worker = @worker
    @transact.group = @group

    @transact.metadata = @transact.create_req(params[:memo])

    if can?(:create, @transact) && @transact.save
      if @transact.redirect_url.blank?
        flash[:notice] = t('notice_transfer_succeeded')
        respond_to do |format|
          format.html { redirect_to person_path(@worker) }
          format.json { render :json => @transact.as_json }
          format.xml { render :xml => @transact.to_xml }
        end
      else
        @transact.redirect_url << "?status=ok"
        redirect_to @transact.redirect_url
      end
    else
      flash[:error] = t('error_with_transfer')
      @transact.metadata.destroy
      render :action => "new"
    end

  end

  def opentransact_find_worker(payee)
    # assume identifier is either an email address or a url
    if payee.split('@').size == 2
      @worker = Person.find_by_email(payee)
    else
      @worker = Person.find_by_openid_identifier(OpenIdAuthentication.normalize_identifier(CGI.unescape(payee)))
    end
  end

  private

  def find_group_by_asset
    @group = Group.find_by_asset(params[:asset])
    if oauth?
      invalid_oauth_response unless current_token.group_id == @group.id
    end
  end
end
<commit_msg>groupy branch: fix json opentransact error message if payee not found<commit_after>class TransactsController < ApplicationController
  skip_before_filter :require_activation
  before_filter :login_or_oauth_required
  before_filter :find_group_by_asset
  skip_before_filter :verify_authenticity_token, :set_person_locale, :if => :oauth?

  def index
    @transactions = current_person.transactions.select {|transact| transact.group == @group}
    respond_to do |format|
      format.html
      format.xml { render :xml => @transactions.to_xml(:root => "txns") }
      format.json { render :json => @transactions.as_json }
    end
  end

  def show
    @transact = current_person.transactions.find(params[:id])
    if nil == @transact
        flash[:error] = t('error_could_not_find_transaction')
        redirect_to home_url
        return
    end
    respond_to do |format|
      format.html
      format.xml { render :xml => @transact.to_xml }
      format.json { render :json => @transact.as_json }
    end
  end

  def new
    @amount = params[:amount] || ""
    if params[:to]
      @worker = opentransact_find_worker(params[:to])
      if nil == @worker
        flash[:error] = t('error_could_not_find_payee')
        render :action => "new"
        return
      end
    end
  end

  def create
    # Transact.to and Transact.memo - makes @transact look opentransacty
    #
    @transact = Transact.new(:to => params[:to], :memo => params[:memo], :amount => params[:amount], :callback_url => params[:callback_url], :redirect_url => params[:redirect_url])

    @worker = opentransact_find_worker(params[:to])
    if nil == @worker
      respond_to do |format|
        format.html do
          flash[:error] = t('error_could_not_find_payee')
          render :action => "new"
        end
        format.json do
          @transact.errors.add_to_base(t('error_could_not_find_payee'))
          render :json => @transact.as_json, :status => :unprocessable_entity
        end
      end
      return
    end

    @transact.customer = current_person
    @transact.worker = @worker
    @transact.group = @group

    @transact.metadata = @transact.create_req(params[:memo])

    if can?(:create, @transact) && @transact.save
      if @transact.redirect_url.blank?
        flash[:notice] = t('notice_transfer_succeeded')
        respond_to do |format|
          format.html { redirect_to person_path(@worker) }
          format.json { render :json => @transact.as_json }
          format.xml { render :xml => @transact.to_xml }
        end
      else
        @transact.redirect_url << "?status=ok"
        redirect_to @transact.redirect_url
      end
    else
      flash[:error] = t('error_with_transfer')
      @transact.metadata.destroy
      render :action => "new"
    end

  end

  def opentransact_find_worker(payee)
    # assume identifier is either an email address or a url
    if payee.split('@').size == 2
      @worker = Person.find_by_email(payee)
    else
      @worker = Person.find_by_openid_identifier(OpenIdAuthentication.normalize_identifier(CGI.unescape(payee)))
    end
  end

  private

  def find_group_by_asset
    @group = Group.find_by_asset(params[:asset])
    if oauth?
      invalid_oauth_response unless current_token.group_id == @group.id
    end
  end
end

{'fraction_non_alphanumeric': 0.10986547085201794, 'fraction_numerical': 0.00032030749519538755, 'mean_word_length': 3.047310434219054, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, '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': '6873763', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1968, 'n_words': 420}