Skip to content

Commit

Permalink
3197: Merge partner records (#3214)
Browse files Browse the repository at this point in the history
* 3197: Merge partner records (WIP)

* 3197: Request merging

* Lint fixes

* Spec and lint fixes

* More spec fixes

* More spec and lint fixes

* last fix???

* Fix migrations to handle bad data

* Fix merge error

* Fix DB migrations

* Fix but that prevented partners from updating their profile info

* QA fixes

* Spec fixes

* Last fixes (finger cross)

Co-authored-by: Edwin <[email protected]>
  • Loading branch information
Daniel Orner and edwinthinks authored Dec 14, 2022
1 parent 9969afb commit d799030
Show file tree
Hide file tree
Showing 106 changed files with 697 additions and 902 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,4 @@ body a {
body:not(.sidebar-mini-md) .content-wrapper, body:not(.sidebar-mini-md) .main-footer, body:not(.sidebar-mini-md) .main-header {
margin-left: 280px;
}

2 changes: 1 addition & 1 deletion app/controllers/partners/approval_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Partners
class ApprovalRequestsController < BaseController
def create
svc = Partners::RequestApprovalService.new(partner: current_partner.partner)
svc = Partners::RequestApprovalService.new(partner: current_partner)
svc.call

if svc.errors.none?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/partners/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def verify_partner_is_active
end

def authorize_verified_partners
return if current_partner.verified?
return if current_partner.approved?

redirect_to partners_requests_path, notice: "Please review your application details and submit for approval in order to make a new request."
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/partners/children_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def new
family = current_partner.families.find_by!(id: params[:family_id])
@child = family.children.new

requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.partner.id).call
requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.id).call
@formatted_requestable_items = requestable_items.map do |rt|
[rt.name, rt.id]
end
Expand All @@ -50,7 +50,7 @@ def active

def edit
@child = current_partner.children.find_by(id: params[:id])
requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.partner.id).call
requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.id).call
@formatted_requestable_items = requestable_items.map do |rt|
[rt.name, rt.id]
end
Expand Down
16 changes: 7 additions & 9 deletions app/controllers/partners/dashboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ def index; end
def show
@partner = current_partner
@partner_requests = @partner.requests.order(created_at: :desc).limit(10)
@upcoming_distributions = ::Partner.find(@partner.partner_id)
.distributions.order(issued_at: :desc)
.where('issued_at >= ?', Time.zone.today)
@distributions = ::Partner.find(@partner.partner_id)
.distributions.order(issued_at: :desc)
.where('issued_at < ?', Time.zone.today)
.limit(5)
@upcoming_distributions = @partner.distributions.order(issued_at: :desc)
.where('issued_at >= ?', Time.zone.today)
@distributions = @partner.distributions.order(issued_at: :desc)
.where('issued_at < ?', Time.zone.today)
.limit(5)

@parent_org = Organization.find(@partner.essentials_bank_id)
@parent_org = Organization.find(@partner.organization_id)

@requests_in_progress = @parent_org
.ordered_requests
.where(partner: @partner.partner_id)
.where(partner: @partner.id)
.where(status: 0)

@families = @partner.families
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/partners/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ class DistributionsController < BaseController

def index
@partner = current_partner
@distributions = ::Partner.find(@partner.partner_id)
.distributions.order(issued_at: :desc)
@distributions = @partner.distributions.order(issued_at: :desc)

@parent_org = Organization.find(@partner.essentials_bank_id)
@parent_org = Organization.find(@partner.organization_id)
end

def print
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/partners/individuals_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class IndividualsRequestsController < BaseController
def new
@request = FamilyRequest.new({}, initial_items: 1)

requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.partner.id).call
requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.id).call
@formatted_requestable_items = requestable_items.map do |rt|
[rt.name, rt.id]
end.sort
Expand All @@ -24,7 +24,7 @@ def create
else
@request = FamilyRequest.new({}, initial_items: 1)
@errors = create_service.errors
@requestable_items = Organization.find(current_partner.essentials_bank_id).valid_items.map do |item|
@requestable_items = Organization.find(current_partner.organization_id).valid_items.map do |item|
[item[:name], item[:id]]
end.sort

Expand Down
12 changes: 7 additions & 5 deletions app/controllers/partners/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def show; end
def edit; end

def update
if current_partner.update(partner_params)
if current_partner.update(partner_params) && current_partner.profile.update(profile_params)
flash[:success] = "Details were successfully updated."
redirect_to partners_profile_path
else
Expand All @@ -16,11 +16,13 @@ def update
private

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

def profile_params
params.require(:profile).permit(
:agency_type,
:other_agency_type,
:partner_status,
:proof_of_partner_status,
:agency_mission,
:address1,
Expand Down Expand Up @@ -88,7 +90,7 @@ def partner_params
:enable_individual_requests,
:enable_quantity_based_requests,
documents: []
)
).select { |_, v| v.present? }
end
end
end
12 changes: 6 additions & 6 deletions app/controllers/partners/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ def index
end

def new
@partner_request = Partners::Request.new
@partner_request = ::Request.new
@partner_request.item_requests.build

requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.partner.id).call
requestable_items = PartnerFetchRequestableItemsService.new(partner_id: current_partner.id).call
@formatted_requestable_items = requestable_items.map do |rt|
[rt.name, rt.id]
end.sort
Expand All @@ -36,7 +36,7 @@ def create

@partner_request = create_service.partner_request
@errors = create_service.errors
@formatted_requestable_items = Organization.find(current_partner.essentials_bank_id).valid_items.map do |item|
@formatted_requestable_items = Organization.find(current_partner.organization_id).valid_items.map do |item|
[item[:name], item[:id]]
end.sort

Expand All @@ -49,11 +49,11 @@ def create
private

def partner_request_params
params.require(:partners_request).permit(:comments, item_requests_attributes: [
:item_id,
params.require(:request).permit(:comments, item_requests_attributes: [
:item_id,
:quantity,
:_destroy
])
])
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/partners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def approve_application

def show
@partner = current_organization.partners.find(params[:id])
@impact_metrics = @partner.profile.impact_metrics unless @partner.uninvited?
@impact_metrics = @partner.impact_metrics unless @partner.uninvited?
@partner_distributions = @partner.distributions.includes(:partner, :storage_location, line_items: [:item]).order("issued_at DESC")
@partner_profile_fields = current_organization.partner_form_fields
@partner_users = @partner.profile.users.order(name: :asc)
@partner_users = @partner.users.order(name: :asc)

respond_to do |format|
format.html
Expand Down
18 changes: 10 additions & 8 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class ProfilesController < ApplicationController
def edit
@partner = current_organization.partners.find(params[:id]).profile
@partner = current_organization.partners.find(params[:id])
end

def update
@partner = current_organization.partners.find(params[:id]).profile
if @partner.update(edit_profile_params)
redirect_to partner_path(@partner.partner) + "#partner-information", notice: "#{@partner.name} updated!"
@partner = current_organization.partners.find(params[:id])
if @partner.update(edit_partner_params) && @partner.profile.update(edit_profile_params)
redirect_to partner_path(@partner) + "#partner-information", notice: "#{@partner.name} updated!"
else
flash[:error] = "Something didn't work quite right -- try again?"
render action: :edit
Expand All @@ -15,12 +15,14 @@ def update

private

def edit_partner_params
params.require(:partner).permit(:name)
end

def edit_profile_params
params.require(:partners_partner).permit(
:name,
params.require(:profile).permit(
:agency_type,
:other_agency_type,
:partner_status,
:proof_of_partner_status,
:agency_mission,
:address1,
Expand Down Expand Up @@ -99,6 +101,6 @@ def edit_profile_params
:enable_individual_requests,
:enable_quantity_based_requests,
documents: []
)
).select { |_, v| v.present? }
end
end
10 changes: 5 additions & 5 deletions app/helpers/partners_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def humanize_boolean(boolean)
end

def partner_status_badge(partner)
if partner.partner_status == "verified"
tag.span partner.partner_status, class: %w(badge badge-pill badge-primary float-right)
elsif partner.partner_status == "recertification_required"
tag.span partner.partner_status, class: %w(badge badge-pill badge-danger float-right)
if partner.status == "approved"
tag.span partner.display_status, class: %w(badge badge-pill badge-primary float-right)
elsif partner.status == "recertification_required"
tag.span partner.display_status, class: %w(badge badge-pill badge-danger float-right)
else
tag.span partner.partner_status, class: %w(badge badge-pill badge-info float-right)
tag.span partner.display_status, class: %w(badge badge-pill badge-info float-right)
end
end
end
Loading

0 comments on commit d799030

Please sign in to comment.