<commit_before># Provides full CRUD for Partners. These are minimal representations of corresponding Partner records in PartnerBase.
# Though the functionality of Partners is actually fleshed out in PartnerBase, in DiaperBase, we maintain a collection
# of which Partners are associated with which Diaperbanks.
class PartnersController < ApplicationController
  include Importable

  def index
    @unfiltered_partners_for_statuses = Partner.where(organization: current_organization)
    @partners = Partner.where(organization: current_organization).class_filter(filter_params).alphabetized
  end

  def create
    @partner = current_organization.partners.new(partner_params)
    if @partner.save
      redirect_to partners_path, notice: "Partner added!"
    else
      flash[:error] = "Something didn't work quite right -- try again?"
      render action: :new
    end
  end

  def approve_application
    @partner = current_organization.partners.find(params[:id])
    response = DiaperPartnerClient.put(partner_id: @partner.id, status: "approved")
    if response.is_a?(Net::HTTPSuccess)
      @partner.approved!
      redirect_to partners_path, notice: "Partner approved!"
    else
      redirect_to partners_path, error: "Failed to update Partner data!"
    end
  end

  def show
    @partner = current_organization.partners.find(params[:id])
  end

  def new
    @partner = current_organization.partners.new
  end

  # NOTE(chaserx): this is confusing and could be renamed to reflect what it's returning/showing review_application
  def approve_partner
    @partner = current_organization.partners.find(params[:id])

    # TODO: create a service that abstracts all of this from PartnersController, like PartnerDetailRetriever.call(id: params[:id])

    # TODO: move this code to new service,
    @diaper_partner = DiaperPartnerClient.get(id: params[:id])
    @diaper_partner = JSON.parse(@diaper_partner, symbolize_names: true) if @diaper_partner
    @agency = if @diaper_partner
                @diaper_partner[:agency]
              else
                autovivifying_hash
              end
  end

  def edit
    @partner = current_organization.partners.find(params[:id])
  end

  def update
    @partner = current_organization.partners.find(params[:id])
    if @partner.update(partner_params)
      redirect_to partners_path, notice: "#{@partner.name} updated!"
    else
      flash[:error] = "Something didn't work quite right -- try again?"
      render action: :edit
    end
  end

  def destroy
    current_organization.partners.find(params[:id]).destroy
    redirect_to partners_path
  end

  def invite
    partner = current_organization.partners.find(params[:id])
    partner.register_on_partnerbase
    redirect_to partners_path, notice: "#{partner.name} invited!"
  end

  def re_invite
    partner = current_organization.partners.find(params[:partner])
    partner.add_user_on_partnerbase(email: params[:email])
    redirect_to partner_path(partner), notice: "We have invited #{params[:email]} to #{partner.name}!"
  end

  def recertify_partner
    @partner = current_organization.partners.find(params[:id])
    response = DiaperPartnerClient.put(partner_id: @partner.id, status: "recertification_required")
    if response.is_a?(Net::HTTPSuccess)
      @partner.recertification_required!
      redirect_to partners_path, notice: "#{@partner.name} recertification successfully requested!"
    else
      redirect_to partners_path, error: "#{@partner.name} failed to update partner records"
    end
  end
  
  def deactivate
    @partner = current_organization.partners.find(params[:id])
    response = DiaperPartnerClient.put(partner_id: @partner.id, status: "deactivated")
    if response.is_a?(Net::HTTPSuccess) && @partner.update_column(:status, "deactivated" )
      redirect_to partners_path, notice: "#{@partner.name} successfully deactivated!"
    else
      redirect_to partners_path, error: "#{@partner.name} failed to deactivate!"
    end
  end

  def reactivate 
    @partner = current_organization.partners.find(params[:id])

    response = DiaperPartnerClient.put(partner_id: @partner.id, status: "awaiting_review")
    if response.is_a?(Net::HTTPSuccess) && @partner.update_column(:status, "awaiting_review")
      redirect_to partners_path, notice: "#{@partner.name} successfully reactivated!"
    else
      redirect_to partners_path, error: "#{@partner.name} failed to reactivate!"
    end
  end

  private

  def autovivifying_hash
    Hash.new { |ht, k| ht[k] = autovivifying_hash }
  end

  def partner_params
    params.require(:partner).permit(:name, :email, :send_reminders, :status)
  end

  def filter_params
    return {} unless params.key?(:filters)

    params.require(:filters).slice(:by_status)
  end
end


<commit_msg>Remove 'status' from whitelist<commit_after># Provides full CRUD for Partners. These are minimal representations of corresponding Partner records in PartnerBase.
# Though the functionality of Partners is actually fleshed out in PartnerBase, in DiaperBase, we maintain a collection
# of which Partners are associated with which Diaperbanks.
class PartnersController < ApplicationController
  include Importable

  def index
    @unfiltered_partners_for_statuses = Partner.where(organization: current_organization)
    @partners = Partner.where(organization: current_organization).class_filter(filter_params).alphabetized
  end

  def create
    @partner = current_organization.partners.new(partner_params)
    if @partner.save
      redirect_to partners_path, notice: "Partner added!"
    else
      flash[:error] = "Something didn't work quite right -- try again?"
      render action: :new
    end
  end

  def approve_application
    @partner = current_organization.partners.find(params[:id])
    response = DiaperPartnerClient.put(partner_id: @partner.id, status: "approved")
    if response.is_a?(Net::HTTPSuccess)
      @partner.approved!
      redirect_to partners_path, notice: "Partner approved!"
    else
      redirect_to partners_path, error: "Failed to update Partner data!"
    end
  end

  def show
    @partner = current_organization.partners.find(params[:id])
  end

  def new
    @partner = current_organization.partners.new
  end

  # NOTE(chaserx): this is confusing and could be renamed to reflect what it's returning/showing review_application
  def approve_partner
    @partner = current_organization.partners.find(params[:id])

    # TODO: create a service that abstracts all of this from PartnersController, like PartnerDetailRetriever.call(id: params[:id])

    # TODO: move this code to new service,
    @diaper_partner = DiaperPartnerClient.get(id: params[:id])
    @diaper_partner = JSON.parse(@diaper_partner, symbolize_names: true) if @diaper_partner
    @agency = if @diaper_partner
                @diaper_partner[:agency]
              else
                autovivifying_hash
              end
  end

  def edit
    @partner = current_organization.partners.find(params[:id])
  end

  def update
    @partner = current_organization.partners.find(params[:id])
    if @partner.update(partner_params)
      redirect_to partners_path, notice: "#{@partner.name} updated!"
    else
      flash[:error] = "Something didn't work quite right -- try again?"
      render action: :edit
    end
  end

  def destroy
    current_organization.partners.find(params[:id]).destroy
    redirect_to partners_path
  end

  def invite
    partner = current_organization.partners.find(params[:id])
    partner.register_on_partnerbase
    redirect_to partners_path, notice: "#{partner.name} invited!"
  end

  def re_invite
    partner = current_organization.partners.find(params[:partner])
    partner.add_user_on_partnerbase(email: params[:email])
    redirect_to partner_path(partner), notice: "We have invited #{params[:email]} to #{partner.name}!"
  end

  def recertify_partner
    @partner = current_organization.partners.find(params[:id])
    response = DiaperPartnerClient.put(partner_id: @partner.id, status: "recertification_required")
    if response.is_a?(Net::HTTPSuccess)
      @partner.recertification_required!
      redirect_to partners_path, notice: "#{@partner.name} recertification successfully requested!"
    else
      redirect_to partners_path, error: "#{@partner.name} failed to update partner records"
    end
  end
  
  def deactivate
    @partner = current_organization.partners.find(params[:id])
    response = DiaperPartnerClient.put(partner_id: @partner.id, status: "deactivated")
    if response.is_a?(Net::HTTPSuccess) && @partner.update_column(:status, "deactivated" )
      redirect_to partners_path, notice: "#{@partner.name} successfully deactivated!"
    else
      redirect_to partners_path, error: "#{@partner.name} failed to deactivate!"
    end
  end

  def reactivate 
    @partner = current_organization.partners.find(params[:id])

    response = DiaperPartnerClient.put(partner_id: @partner.id, status: "awaiting_review")
    if response.is_a?(Net::HTTPSuccess) && @partner.update_column(:status, "awaiting_review")
      redirect_to partners_path, notice: "#{@partner.name} successfully reactivated!"
    else
      redirect_to partners_path, error: "#{@partner.name} failed to reactivate!"
    end
  end

  private

  def autovivifying_hash
    Hash.new { |ht, k| ht[k] = autovivifying_hash }
  end

  def partner_params
    params.require(:partner).permit(:name, :email, :send_reminders)
  end

  def filter_params
    return {} unless params.key?(:filters)

    params.require(:filters).slice(:by_status)
  end
end



{'fraction_non_alphanumeric': 0.09597652975691534, 'fraction_numerical': 0.0, 'mean_word_length': 4.1455525606469, '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': '2256411', 'n_tokens_mistral': 2939, 'n_tokens_neox': 2866, 'n_words': 702}