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

Add Single step invite and process partner process capability #4075

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
3 changes: 2 additions & 1 deletion app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def organization_params
:repackage_essentials, :distribute_monthly,
:ndbn_member_id, :enable_child_based_requests,
:enable_individual_requests, :enable_quantity_based_requests,
:ytd_on_distribution_printout, partner_form_fields: []
:ytd_on_distribution_printout, :one_step_partner_invite,
partner_form_fields: []
)
end

Expand Down
22 changes: 22 additions & 0 deletions app/controllers/partners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ def approve_application
end
end

def invite_and_approve
# Invite the partner
partner = current_organization.partners.find(params[:id])

partner_invite_service = PartnerInviteService.new(partner: partner, force: true)
partner_invite_service.call

# If no errors inviting, then approve the partner
if partner_invite_service.errors.none?
partner_approval_service = PartnerApprovalService.new(partner: partner)
partner_approval_service.call

if partner_approval_service.errors.none?
redirect_to partners_path, notice: "Partner invited and approved!"
else
redirect_to partners_path, error: "Failed to approve partner because: #{partner_approval_service.errors.full_messages}"
end
else
redirect_to partners_path, notice: "Failed to invite #{partner.name}! #{partner_invite_service.errors.full_messages}"
end
dorner marked this conversation as resolved.
Show resolved Hide resolved
end

def show
@partner = current_organization.partners.find(params[:id])
@impact_metrics = @partner.impact_metrics unless @partner.uninvited?
Expand Down
55 changes: 28 additions & 27 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@
#
# Table name: organizations
#
# id :integer not null, primary key
# city :string
# deadline_day :integer
# default_storage_location :integer
# distribute_monthly :boolean default(FALSE), not null
# email :string
# enable_child_based_requests :boolean default(TRUE), not null
# enable_individual_requests :boolean default(TRUE), not null
# enable_quantity_based_requests :boolean default(TRUE), not null
# intake_location :integer
# invitation_text :text
# latitude :float
# longitude :float
# name :string
# partner_form_fields :text default([]), is an Array
# reminder_day :integer
# repackage_essentials :boolean default(FALSE), not null
# short_name :string
# state :string
# street :string
# url :string
# ytd_on_distribution_printout :boolean default(TRUE), not null
# zipcode :string
# created_at :datetime not null
# updated_at :datetime not null
# account_request_id :integer
# ndbn_member_id :bigint
# id :integer not null, primary key
# city :string
# deadline_day :integer
# default_storage_location :integer
# distribute_monthly :boolean default(FALSE), not null
# email :string
# enable_child_based_requests :boolean default(TRUE), not null
# enable_individual_requests :boolean default(TRUE), not null
# enable_quantity_based_requests :boolean default(TRUE), not null
# intake_location :integer
# invitation_text :text
# latitude :float
# longitude :float
# name :string
# partner_form_fields :text default([]), is an Array
# reminder_day :integer
# repackage_essentials :boolean default(FALSE), not null
# short_name :string
# state :string
# street :string
# url :string
# one_step_partner_invite :boolean default(FALSE), not null
# ytd_on_distribution_printout :boolean default(TRUE), not null
# zipcode :string
# created_at :datetime not null
# updated_at :datetime not null
# account_request_id :integer
# ndbn_member_id :bigint
#

class Organization < ApplicationRecord
Expand Down
6 changes: 6 additions & 0 deletions app/views/organizations/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@
<%= humanize_boolean(@organization.ytd_on_distribution_printout) %>
</p>
</div>
<div class="mb-4">
<h3 class='font-bold'>Use One step Partner invite and approve process?</h3>
<p>
<%= humanize_boolean(@organization.one_step_partner_invite) %>
</p>
</div>
<% if @organization.logo.attached? %>
<div class="mb-4">
<h3 class='font-bold'>Logo</h3>
Expand Down
1 change: 1 addition & 0 deletions app/views/organizations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<%= f.input :enable_individual_requests, label: 'Enable partners to make requests for individuals?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :enable_quantity_based_requests, label: 'Enable partners to make quantity-based requests?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :ytd_on_distribution_printout, label: 'Show Year-to-date values on distribution printout?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>
<%= f.input :one_step_partner_invite, label: 'Use One Step Invite and Approve partner process?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %>

<% default_email_text_hint = "You can use the variables <code>%{partner_name}</code>, <code>%{delivery_method}</code>, <code>%{distribution_date}</code>, and <code>%{comment}</code> to include the partner's name, delivery method, distribution date, and comments sent in the request." %>
<%= f.input :default_email_text, label: "Distribution Email Content", hint: default_email_text_hint.html_safe do %>
Expand Down
9 changes: 8 additions & 1 deletion app/views/partners/_partner_row.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<% status = partner_row.status %>
<% can_one_step_invite_and_approve = partner_row.organization.one_step_partner_invite %>

<tr>
<td class='text-blue-500'><%= link_to partner_row.name, partner_path(partner_row) %></td>
<td><%= link_to partner_row.email, "mailto:#{partner_row.email}" %></td>
Expand All @@ -25,7 +27,12 @@
<td>
<% case status %>
<% when "uninvited" %>
<%= invite_button_to(invite_partner_path(partner_row), confirm: "Send an invitation to #{partner_row.name} to begin using the partner application?") %>
<% if can_one_step_invite_and_approve %>
<% button_options = { icon: "envelope", type: "warning", text: "Invite and Approve", size: "xs", confirm: "One step invite and approve #{partner_row.name} to begin using the partner application?" } %>
<%= invite_button_to(invite_and_approve_partner_path(partner_row), button_options) %>
<% else %>
<%= invite_button_to(invite_partner_path(partner_row), confirm: "Send an invitation to #{partner_row.name} to begin using the partner application?") %>
<% end %>
<% when "invited" %>
<%= view_button_to partner_path(partner_row) + "#partner-information", { text: "Review Application", icon: "check", type: "warning" } %>
<%= invite_button_to(invite_partner_path(partner_row), confirm: "Re-send an invitation to #{partner_row.name}?", text: 'Re-send Invite') %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def set_up_flipper
patch :profile
get :approve_application
post :invite
post :invite_and_approve
post :invite_partner_user
post :recertify_partner
put :deactivate
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddOneStepPartnerInviteToOrganization < ActiveRecord::Migration[7.0]
def change
add_column :organizations, :one_step_partner_invite, :boolean, null: false
change_column_default :organizations, :one_step_partner_invite, false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_12_29_200106) do
ActiveRecord::Schema[7.0].define(version: 2024_01_31_202431) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -478,6 +478,7 @@
t.boolean "enable_individual_requests", default: true, null: false
t.boolean "enable_quantity_based_requests", default: true, null: false
t.boolean "ytd_on_distribution_printout", default: true, null: false
t.boolean "one_step_partner_invite", default: false, null: false
t.index ["latitude", "longitude"], name: "index_organizations_on_latitude_and_longitude"
t.index ["short_name"], name: "index_organizations_on_short_name"
end
Expand Down
55 changes: 28 additions & 27 deletions spec/factories/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@
#
# Table name: organizations
#
# id :integer not null, primary key
# city :string
# deadline_day :integer
# default_storage_location :integer
# distribute_monthly :boolean default(FALSE), not null
# email :string
# enable_child_based_requests :boolean default(TRUE), not null
# enable_individual_requests :boolean default(TRUE), not null
# enable_quantity_based_requests :boolean default(TRUE), not null
# intake_location :integer
# invitation_text :text
# latitude :float
# longitude :float
# name :string
# partner_form_fields :text default([]), is an Array
# reminder_day :integer
# repackage_essentials :boolean default(FALSE), not null
# short_name :string
# state :string
# street :string
# url :string
# ytd_on_distribution_printout :boolean default(TRUE), not null
# zipcode :string
# created_at :datetime not null
# updated_at :datetime not null
# account_request_id :integer
# ndbn_member_id :bigint
# id :integer not null, primary key
# city :string
# deadline_day :integer
# default_storage_location :integer
# distribute_monthly :boolean default(FALSE), not null
# email :string
# enable_child_based_requests :boolean default(TRUE), not null
# enable_individual_requests :boolean default(TRUE), not null
# enable_quantity_based_requests :boolean default(TRUE), not null
# intake_location :integer
# invitation_text :text
# latitude :float
# longitude :float
# name :string
# partner_form_fields :text default([]), is an Array
# reminder_day :integer
# repackage_essentials :boolean default(FALSE), not null
# short_name :string
# state :string
# street :string
# url :string
# one_step_partner_invite :boolean default(FALSE), not null
# ytd_on_distribution_printout :boolean default(TRUE), not null
# zipcode :string
# created_at :datetime not null
# updated_at :datetime not null
# account_request_id :integer
# ndbn_member_id :bigint
#

FactoryBot.define do
Expand Down
15 changes: 15 additions & 0 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# == Schema Information
#
# Table name: events
#
# id :bigint not null, primary key
# data :jsonb
# event_time :datetime not null
# eventable_type :string
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
# eventable_id :bigint
# organization_id :bigint
# user_id :bigint
#
Comment on lines +1 to +15
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The app added this. Doesn't detract from the change, and I think it's more useful to have. Opting to keep it in.

RSpec.describe Event, type: :model do
let(:organization) { FactoryBot.create(:organization) }
describe "#most_recent_snapshot" do
Expand Down
55 changes: 28 additions & 27 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@
#
# Table name: organizations
#
# id :integer not null, primary key
# city :string
# deadline_day :integer
# default_storage_location :integer
# distribute_monthly :boolean default(FALSE), not null
# email :string
# enable_child_based_requests :boolean default(TRUE), not null
# enable_individual_requests :boolean default(TRUE), not null
# enable_quantity_based_requests :boolean default(TRUE), not null
# intake_location :integer
# invitation_text :text
# latitude :float
# longitude :float
# name :string
# partner_form_fields :text default([]), is an Array
# reminder_day :integer
# repackage_essentials :boolean default(FALSE), not null
# short_name :string
# state :string
# street :string
# url :string
# ytd_on_distribution_printout :boolean default(TRUE), not null
# zipcode :string
# created_at :datetime not null
# updated_at :datetime not null
# account_request_id :integer
# ndbn_member_id :bigint
# id :integer not null, primary key
# city :string
# deadline_day :integer
# default_storage_location :integer
# distribute_monthly :boolean default(FALSE), not null
# email :string
# enable_child_based_requests :boolean default(TRUE), not null
# enable_individual_requests :boolean default(TRUE), not null
# enable_quantity_based_requests :boolean default(TRUE), not null
# intake_location :integer
# invitation_text :text
# latitude :float
# longitude :float
# name :string
# partner_form_fields :text default([]), is an Array
# reminder_day :integer
# repackage_essentials :boolean default(FALSE), not null
# short_name :string
# state :string
# street :string
# url :string
# one_step_partner_invite :boolean default(FALSE), not null
# ytd_on_distribution_printout :boolean default(TRUE), not null
# zipcode :string
# created_at :datetime not null
# updated_at :datetime not null
# account_request_id :integer
# ndbn_member_id :bigint
#

RSpec.describe Organization, type: :model do
Expand Down
Loading
Loading