<commit_before>module MnoEnterprise
  class Jpi::V1::OrganizationController < Jpi::V1::BaseResourceController
    respond_to :json

    # GET /jpi/v1/organization/:id
    def index
      render partial: 'index'
    end

    # PUT /jpi/v1/organization/:id
    def update
      # Authorize and update
      authorize! :update, @organization

      # Update only Organization name and soa_status
      @organization.name = params[:organization][:name]
      if @organization.save
        # Update the soa_enabled flag
        unless params[:organization][:soa_enabled].nil?
          @organization.change_soa_status(!!params[:organization][:soa_enabled])
        end

        render partial: 'organization'
      else
        render json: @organization.errors, status: :bad_request
      end
    end

    # PUT /jpi/v1/organization/:id/charge
    def charge
      authorize! :manage_billing, @organization
      payment = @organization.charge
      s = ''
      if payment
        if payment.success?
          s = 'success'
        else
          s = 'fail'
        end
      else
        s = 'error'
      end

      render json: { status: s, data: payment }
    end

    # PUT /jpi/v1/organization/:id/update_billing
    def update_billing
      whitelist = ['title','first_name','last_name','number','month','year','country','verification_value','billing_address','billing_city','billing_postcode', 'billing_country']
      attributes = params[:credit_card].select { |k,v| whitelist.include?(k.to_s) }

      # Authorize and upsert
      authorize! :update, @organization
      if (@credit_card = @organization.credit_card)
        @credit_card.smart_update_attributes(attributes)
      else
        @credit_card = @organization.create_credit_card(attributes)
      end

      if @credit_card.errors.empty?
        render partial: 'credit_card'
      else<commit_msg>disabled advanced features<commit_after>module MnoEnterprise
  class Jpi::V1::OrganizationController < Jpi::V1::BaseResourceController
    respond_to :json

    # GET /jpi/v1/organization/:id
    def index
      render partial: 'index'
    end

    # PUT /jpi/v1/organization/:id
    def update
      # Authorize and update
      authorize! :update, @organization

      # Update only Organization name and soa_status
      @organization.name = params[:organization][:name]
      if @organization.save
        # Update the soa_enabled flag
        unless params[:organization][:soa_enabled].nil?
          @organization.change_soa_status(!!params[:organization][:soa_enabled])
        end

        render partial: 'organization'
      else
        render json: @organization.errors, status: :bad_request
      end
    end

    # PUT /jpi/v1/organization/:id/charge
    # def charge
    #   authorize! :manage_billing, @organization
    #   payment = @organization.charge
    #   s = ''
    #   if payment
    #     if payment.success?
    #       s = 'success'
    #     else
    #       s = 'fail'
    #     end
    #   else
    #     s = 'error'
    #   end
    #
    #   render json: { status: s, data: payment }
    # end

    # PUT /jpi/v1/organization/:id/update_billing
    def update_billing
      whitelist = ['title','first_name','last_name','number','month','year','country','verification_value','billing_address','billing_city','billing_postcode', 'billing_country']
      attributes = params[:credit_card].select { |k,v| whitelist.include?(k.to_s) }

      # Authorize and upsert
      authorize! :update, @organization
      if (@credit_card = @organization.credit_card)
        @credit_card.smart_update_attributes(attributes)
      else
        @credit_card = @organization.create_credit_card(attributes)
      end

      if @credit_card.errors.empty?
        render partial: 'credit_card'
      else
{'fraction_non_alphanumeric': 0.1083509513742072, 'fraction_numerical': 0.003171247357293869, 'mean_word_length': 2.6962890625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4643561', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1117, 'n_words': 233}