Skip to content

Commit

Permalink
add auth to orphans controller show action (#2817)
Browse files Browse the repository at this point in the history
Co-authored-by: Sri Harsha <sriharsha.poosa@gmail.com>
  • Loading branch information
RyanEddyIC and sri49 authored Oct 29, 2024
1 parent 8bdde0f commit 0b3c825
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/users/orphans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def index
end

def show
authorize User, :staff_can_access_user_account_tab?
end

def destroy
Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/users/orphans_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Users::OrphansController, dbclean: :after_each do
let(:admin_person) { FactoryBot.create(:person, :with_hbx_staff_role) }
let(:admin_user) {FactoryBot.create(:user, :with_hbx_staff_role, :person => admin_person)}
let(:admin_permission) { FactoryBot.create(:permission, :super_admin) }

let(:consumer_person) { FactoryBot.create(:person, :with_consumer_role, :with_family) }
let(:consumer_user) {FactoryBot.create(:user, :person => consumer_person)}

let(:orphan_user) { FactoryBot.create(:user) }

context "show" do
it "should respond successfully to users with correct permissions" do
admin_permission.update_attributes!(can_access_user_account_tab: true)
admin_person.hbx_staff_role.update_attributes(permission_id: admin_permission.id)

sign_in(admin_user)
get :show, params: { id: orphan_user.id}, xhr: true
expect(response).to have_http_status(:success)
end

it "should redirect users without permission" do
sign_in(consumer_user)
get :show, params: { id: orphan_user.id}, xhr: true
expect(response).to have_http_status(:forbidden)
end
end
end

0 comments on commit 0b3c825

Please sign in to comment.