Skip to content

Commit

Permalink
Require a partner for the partner dashboard (#4063)
Browse files Browse the repository at this point in the history
* Require a partner for the partner dashboard

* Validate that a non-partner user gets redirected

* Centralize partner-user requirement to partner base controller

* Clean out the lint!

* Fix redirect spec
  • Loading branch information
awwaiid authored Aug 23, 2024
1 parent 54165f1 commit b44acbb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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, partner)
allow(UsersRole).to receive(:current_role_for).and_return(partner_user.roles.find_by(name: "partner"))
get partners_dashboard_path
expect(response).to redirect_to(dashboard_path)
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

0 comments on commit b44acbb

Please sign in to comment.