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

Fix nasty error when clicking on partner approval request email as partner #3759

Closed
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
7 changes: 7 additions & 0 deletions app/controllers/partners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# of which Partners are associated with which Diaperbanks.
class PartnersController < ApplicationController
include Importable
before_action :validate_user, only: :show

def index
@unfiltered_partners_for_statuses = Partner.where(organization: current_organization)
Expand Down Expand Up @@ -164,6 +165,12 @@ def reactivate

private

def validate_user
return if current_user.has_role?(Role::ORG_ADMIN, current_organization) || current_user.has_role?(Role::ORG_USER, current_organization)

redirect_to root_path, error: "You must be logged in as the essentials bank to review this partner!"
end

def partner_params
params.require(:partner).permit(:name, :email, :send_reminders, :quota,
:notes, :partner_group_id, :default_storage_location_id, documents: [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

<br>

<%= link_to 'Review This Organization', partner_url(organization_id: @organization.short_name, id: @partner.id, anchor: "partner-information") %>
<%= link_to 'Review This Partner', partner_url(organization_id: @organization.short_name, id: @partner.id, anchor: "partner-information") %>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
You've received a request to approve the account for <%= @partner.name %>.

Review This Organization: <%=partner_url(organization_id: @organization.short_name, id: @partner.id, anchor: "partner-information") %>
Review This Partner: <%=partner_url(organization_id: @organization.short_name, id: @partner.id, anchor: "partner-information") %>
6 changes: 3 additions & 3 deletions spec/mailers/organization_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
it "renders the body with correct text with partner information" do
html = html_body(subject)
expect(html).to include("<h1> You've received a request to approve the account for #{partner.name}. </h1>")
expect(html).to include("Review This Organization")
expect(html).to include("#{organization.short_name}/partners/#{partner.id}#partner-information\">Review This Organization</a>")
expect(html).to include("Review This Partner")
expect(html).to include("#{organization.short_name}/partners/#{partner.id}#partner-information\">Review This Partner</a>")
text = text_body(subject)
expect(text).to include("You've received a request to approve the account for #{partner.name}.")
expect(text).to include("Review This Organization")
expect(text).to include("Review This Partner")
expect(text).to include("#{organization.short_name}/partners/#{partner.id}#partner-information")
end

Expand Down
16 changes: 16 additions & 0 deletions spec/system/partner_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@
end
end

context "when login as a partner" do
let(:partner) { create(:partner, name: "Invited Partner", status: :invited) }

before do
sign_out(@user)
sign_in(partner.users.first)
end

it "redirects to partner's dashbaord with error message" do
visit url_prefix + "/partners/#{partner.id}"

expect(page).to have_content("Dashboard - #{partner.name}")
expect(page.find(".alert-danger")).to have_content "You must be logged in as the essentials bank to review this partner!"
end
end

context "when viewing a deactivated partner" do
let(:deactivated) { create(:partner, name: "Deactivated Partner", status: :deactivated) }
subject { url_prefix + "/partners/#{deactivated.id}" }
Expand Down
Loading