Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show orgs with parent coalitions on hub/organization page for org leads #5594

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions app/forms/hub/coalition_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def save
return false unless valid?

coalition.assign_attributes(attributes_for(:coalition))
if states
UpdateStateRoutingTargetsService.update(coalition, states.split(","))
end
UpdateStateRoutingTargetsService.update(coalition, states&.split(","))
coalition.save
end
end
Expand Down
28 changes: 22 additions & 6 deletions app/presenters/hub/organizations_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,35 @@ def initialize(current_ability)
accessible_organizations = Organization.accessible_by(current_ability)
@organizations = accessible_organizations.includes(:child_sites).with_computed_client_count.load
@coalitions = Coalition.accessible_by(current_ability)
@state_routing_targets = StateRoutingTarget.where(target: accessible_organizations).or(StateRoutingTarget.where(target: @coalitions)).load.group_by(&:state_abbreviation)
coalition_parents_of_dependent_orgs = accessible_organizations.where.not(coalition_id: nil).reorder(nil).distinct.pluck(:coalition_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need to do reorder(nil) & distinct needed here?

@state_routing_targets = StateRoutingTarget.where(target: accessible_organizations)
.or(StateRoutingTarget.where(target: @coalitions))
.or(StateRoutingTarget.where(target_id: coalition_parents_of_dependent_orgs))
.distinct.load.group_by(&:state_abbreviation)
end


Capacity = Struct.new(:current_count, :total_capacity) do
def initialize(current_count = 0, total_capacity = 0)
super
end
end

def accessible_entities_for(state)
@state_routing_targets[state]&.map do |target|
target.target_type == "Coalition" ? coalition(target.target_id) : organization(target.target_id)
end
return [] unless @state_routing_targets[state]

@state_routing_targets[state].flat_map do |srt|
case srt.target_type
when Coalition::TYPE
if (coalition_obj = coalition(srt.target_id))
coalition_obj
else
srt.target.organizations&.filter_map { |org| organization(org.id) }
end
when Organization::TYPE, VitaPartner::TYPE
organization(srt.target_id)
end
end.compact.uniq
end

# use instead of coalition.organizations in the view so that we're not loading organizations 2x
Expand Down Expand Up @@ -59,8 +75,8 @@ def state_capacity(state)
capacity
end

def unrouted_independent_organizations
organizations.where.missing(:state_routing_targets).where(coalition_id: nil)
def unrouted_organizations
organizations.where.missing(:state_routing_targets)
end

def unrouted_coalitions
Expand Down
1 change: 1 addition & 0 deletions app/views/hub/coalitions/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<% content_for :page_title, @title %>
<% content_for :card do %>
<div class="slab slab--padded">
<%= link_to t("general.all_organizations"), hub_organizations_path %>
<div class="grid">
<div class="grid-item width-one-half">
<%= render "hub/coalitions/form", url: hub_coalition_path(id: @coalition.id), http_method: :patch %>
Expand Down
8 changes: 5 additions & 3 deletions app/views/hub/organizations/_unrouted_entities.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</div>

<ul class="no-bullets">
<% if @presenter.unrouted_independent_organizations.any? %>
<% @presenter.unrouted_independent_organizations.each do |org| %>
<% if @presenter.unrouted_organizations.any? %>
<% @presenter.unrouted_organizations.each do |org| %>
<%= render "organization", organization: org %>
<% end %>
<% end %>
Expand All @@ -19,7 +19,9 @@
<% end %>
</ul>

<% if @presenter.unrouted_independent_organizations.empty? && @presenter.unrouted_coalitions.empty? %>
<% if @presenter.unrouted_organizations.empty? && @presenter.unrouted_coalitions.empty? %>
<%= t("general.NA") %>
<% end %>
</div>

<!--not grabbing the orgs that have a coalition parent here for org leads-->
6 changes: 3 additions & 3 deletions app/views/hub/organizations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<h1 class="h1"><%= title %></h1>
<div>
<% if can? :create, VitaPartner %>
<%= link_to t("hub.organizations.index.add_organization"), new_hub_organization_path, class: "button"%>
<%= link_to t("hub.organizations.index.add_organization"), new_hub_organization_path, class: "button spacing-below-15"%>
<% end %>
</div>
<div>
<% if can? :create, Coalition %>
<%= link_to t("hub.organizations.index.add_coalition"), new_hub_coalition_path, class: "button"%>
<%= link_to t("hub.organizations.index.add_coalition"), new_hub_coalition_path, class: "button spacing-below-25"%>
<% end %>
</div>
</div>
Expand All @@ -24,7 +24,7 @@
<% end %>
<% else %>
<% if @presenter.state_routing_targets.length > 0 %>
<%= @presenter.state_routing_targets.values.flatten.each do |state_routing_target| %>
<% @presenter.state_routing_targets.values.flatten.each do |state_routing_target| %>
<%= render "state", state_abbreviation: state_routing_target.state_abbreviation, state_name: state_routing_target.full_state_name%>
<% end %>
<% else %>
Expand Down
7 changes: 5 additions & 2 deletions app/views/hub/sites/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<% @title = @site.name %>
<% @title = "Edit #{@site.name}" %>
<% content_for :page_title, @title %>
<% content_for :card do %>
<section class="slab slab--padded">
<%= link_to(@site.parent_organization.name, edit_hub_organization_path(id: @site.parent_organization)) %>
<p><%= link_to t("general.all_organizations"), hub_organizations_path %></p>

<p class="grid spacing-below-0"><%= link_to(@site.parent_organization.name, edit_hub_organization_path(id: @site.parent_organization)) %></p>

<div class="grid">
<div class="grid--item width-one-half">
<%= render "form", url: hub_site_path(id: @site.id), http_method: :patch %>
Expand Down
35 changes: 30 additions & 5 deletions spec/presenters/hub/organizations_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
end
end

describe "#unrouted_independent_organizations" do
it "returns a collection of the independent organizations that have no state routing rules" do
expect(subject.unrouted_independent_organizations).to match_array([unrouted_organization])
describe "#unrouted_organizations" do
it "returns a collection of the organizations that have no state routing rules" do
expect(subject.unrouted_organizations).to match_array([high_capacity_unrouted_organization, unrouted_organization, unrouted_organization_with_coalition])
end
end

Expand Down Expand Up @@ -115,12 +115,12 @@
end
end

describe "#unrouted_independent_organizations" do
describe "#unrouted_organizations" do
context "with a user with access to one unrouted organization" do
let(:user) { create(:user, role: create(:organization_lead_role, organization: unrouted_organization)) }

it "returns just the one organization even though other unrouted orgs exist" do
expect(subject.unrouted_independent_organizations).to match_array([unrouted_organization])
expect(subject.unrouted_organizations).to match_array([unrouted_organization])
end
end
end
Expand All @@ -134,5 +134,30 @@
end
end
end

context "with organizations that have a parent coalition" do
let(:user) { create :organization_lead_user, organization: org }
let(:org) { create :organization, coalition: create(:coalition), capacity_limit: 300 }

before do
create :state_routing_target, target: org.coalition, state_abbreviation: "NC"
create :state_routing_target, target: org.coalition, state_abbreviation: "NY"
end

it "shows the organization but not the coalition" do
expect(subject.accessible_entities_for("NC")).to eq [org]
expect(subject.accessible_entities_for("NY")).to eq [org]
end

it "returns state capacities for org" do
capacity = subject.state_capacity("NC")
expect(capacity.current_count).to eq 0
expect(capacity.total_capacity).to eq 300

capacity = subject.state_capacity("NY")
expect(capacity.current_count).to eq 0
expect(capacity.total_capacity).to eq 300
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the "capacity" mean in this context? Does it limit a certain organization to a total count of...clients? users?

end
end
end
end
Loading