Skip to content
This repository was archived by the owner on Nov 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 9999`
# on 2020-03-09 00:26:07 -0400 using RuboCop version 0.80.1.
# on 2020-04-06 20:32:47 -0400 using RuboCop version 0.80.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -29,6 +29,13 @@ Rails/HelperInstanceVariable:
Exclude:
- 'app/helpers/application_helper.rb'

# Offense count: 1
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/InverseOf:
Exclude:
- 'app/models/partner.rb'

# Offense count: 2
# Configuration parameters: Include.
# Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb
Expand Down
35 changes: 35 additions & 0 deletions app/controllers/api/v1/partner_forms_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Api::V1::PartnerFormsController < ApiController
skip_before_action :verify_authenticity_token
respond_to :json

def create
return head :forbidden unless api_key_valid?

partner_form = PartnerForm.where(
diaper_bank_id: partner_form_params[:diaper_bank_id],
).first_or_create

partner_form.update(sections: partner_form_params[:sections])

render json: {
partner_form: partner_form
}
rescue ActiveRecord::RecordInvalid => e
render e.message
end

private

def api_key_valid?
return true if Rails.env.development?

request.headers["X-Api-Key"] == ENV["DIAPER_KEY"]
end

def partner_form_params
params.require(:partner_form).permit(
:diaper_bank_id,
sections: []
)
end
end
21 changes: 21 additions & 0 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,22 @@ class Partner < ApplicationRecord

has_many :partner_requests, dependent: :destroy
has_many :family_requests, dependent: :destroy
has_one :partner_form, primary_key: :diaper_bank_id, foreign_key: :diaper_bank_id, dependent: :destroy

delegate :email, to: :user

ALL_PARTIALS = %w[
media_information
agency_stability
organizational_capacity
sources_of_funding
population_served
executive_director
diaper_pick_up_person
agency_distribution_information
attached_documents
].freeze

def export_hash
{
name: name,
Expand Down Expand Up @@ -228,6 +241,10 @@ def flipper_id
"Partner;#{id}"
end

def partials_to_show
displayable_partials || ALL_PARTIALS
end

def impact_metrics
{
families_served: families_served_count,
Expand All @@ -238,6 +255,10 @@ def impact_metrics

private

def displayable_partials
partner_form&.sections
end

def expose_attachment_path(documentation)
# NOTE(chaserx): I'm not sure how I feel about this.
# I think smells because the `export_json` method should probably be
Expand Down
3 changes: 3 additions & 0 deletions app/models/partner_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class PartnerForm < ApplicationRecord
validates :diaper_bank_id, presence: true, uniqueness: true
end
Loading