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

Require a partner for the partner dashboard #4063

Merged
merged 7 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 11 additions & 0 deletions app/controllers/partners/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ module Partners
class BaseController < ApplicationController
layout 'partners/application'

before_action :require_partner

private

def redirect_to_root
redirect_to root_path
end

def require_partner
unless current_partner
respond_to do |format|
format.html { redirect_to dashboard_path, flash: { error: "Logged in user is not set up as a 'partner'." } }
format.json { render body: nil, status: :forbidden }
end
end
end

def verify_partner_is_active
if current_partner.deactivated?
flash[:alert] = 'Your account has been disabled, contact the organization via their email to reactivate'
Expand Down
10 changes: 10 additions & 0 deletions spec/requests/partners/dashboard_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@
end
end

context "without a partner role" do
it "should redirect to the organization dashboard" do
partner_user.add_role(Role::ORG_USER, @organization)
partner_user.remove_role(Role::PARTNER_USER, partner)
allow(UsersRole).to receive(:current_role_for).and_return(partner_user.roles.find_by(name: "partner"))
get partners_dashboard_path
expect(response.body).to include("switch_to_role")
end
end

context "BroadcastAnnouncement card" do
it "displays announcements if there are valid ones" do
BroadcastAnnouncement.create(message: "test announcement", user_id: user.id, organization_id: organization.id)
Expand Down
Loading