Skip to content
This repository was archived by the owner on Nov 6, 2021. It is now read-only.

Commit cb75fbd

Browse files
Customizable partner form (#287)
* feature: Separate cards out into partials * feature: Add edit partials * WIP * Add missing request spec * Add in customizable partner form to partners. Co-authored-by: androidgrl <kawaharajamie@gmail.com>
1 parent 86f0985 commit cb75fbd

34 files changed

Lines changed: 1059 additions & 904 deletions

.rubocop_todo.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config --exclude-limit 9999`
3-
# on 2020-03-09 00:26:07 -0400 using RuboCop version 0.80.1.
3+
# on 2020-04-06 20:32:47 -0400 using RuboCop version 0.80.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -29,6 +29,13 @@ Rails/HelperInstanceVariable:
2929
Exclude:
3030
- 'app/helpers/application_helper.rb'
3131

32+
# Offense count: 1
33+
# Configuration parameters: Include.
34+
# Include: app/models/**/*.rb
35+
Rails/InverseOf:
36+
Exclude:
37+
- 'app/models/partner.rb'
38+
3239
# Offense count: 2
3340
# Configuration parameters: Include.
3441
# Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Api::V1::PartnerFormsController < ApiController
2+
skip_before_action :verify_authenticity_token
3+
respond_to :json
4+
5+
def create
6+
return head :forbidden unless api_key_valid?
7+
8+
partner_form = PartnerForm.where(
9+
diaper_bank_id: partner_form_params[:diaper_bank_id],
10+
).first_or_create
11+
12+
partner_form.update(sections: partner_form_params[:sections])
13+
14+
render json: {
15+
partner_form: partner_form
16+
}
17+
rescue ActiveRecord::RecordInvalid => e
18+
render e.message
19+
end
20+
21+
private
22+
23+
def api_key_valid?
24+
return true if Rails.env.development?
25+
26+
request.headers["X-Api-Key"] == ENV["DIAPER_KEY"]
27+
end
28+
29+
def partner_form_params
30+
params.require(:partner_form).permit(
31+
:diaper_bank_id,
32+
sections: []
33+
)
34+
end
35+
end

app/models/partner.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,22 @@ class Partner < ApplicationRecord
101101

102102
has_many :partner_requests, dependent: :destroy
103103
has_many :family_requests, dependent: :destroy
104+
has_one :partner_form, primary_key: :diaper_bank_id, foreign_key: :diaper_bank_id, dependent: :destroy
104105

105106
delegate :email, to: :user
106107

108+
ALL_PARTIALS = %w[
109+
media_information
110+
agency_stability
111+
organizational_capacity
112+
sources_of_funding
113+
population_served
114+
executive_director
115+
diaper_pick_up_person
116+
agency_distribution_information
117+
attached_documents
118+
].freeze
119+
107120
def export_hash
108121
{
109122
name: name,
@@ -228,6 +241,10 @@ def flipper_id
228241
"Partner;#{id}"
229242
end
230243

244+
def partials_to_show
245+
displayable_partials || ALL_PARTIALS
246+
end
247+
231248
def impact_metrics
232249
{
233250
families_served: families_served_count,
@@ -238,6 +255,10 @@ def impact_metrics
238255

239256
private
240257

258+
def displayable_partials
259+
partner_form&.sections
260+
end
261+
241262
def expose_attachment_path(documentation)
242263
# NOTE(chaserx): I'm not sure how I feel about this.
243264
# I think smells because the `export_json` method should probably be

app/models/partner_form.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class PartnerForm < ApplicationRecord
2+
validates :diaper_bank_id, presence: true, uniqueness: true
3+
end

0 commit comments

Comments
 (0)