Skip to content

Commit 8198292

Browse files
committed
added auth for destroy org_user
1 parent 3b92285 commit 8198292

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

app/controllers/api/organization_users_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def show
2929

3030
def destroy
3131
@organization_user = organization_user
32+
authorize @organization_user
3233
@organization_user.destroy!
3334
render 'show.json.jb'
3435
end

spec/controllers/api/organization_users_controller_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,23 @@
207207
end
208208

209209
describe 'DELETE /organizations/:organization_id/users/:id' do
210+
before do
211+
allow_any_instance_of(OrganizationUserPolicy).to receive(:destroy?).and_return(true)
212+
end
213+
214+
context 'when organization user policy fails' do
215+
before do
216+
allow_any_instance_of(OrganizationUserPolicy).to receive(:destroy?).and_return(false)
217+
end
218+
219+
it 'renders 401' do
220+
set_auth_header(chidi)
221+
delete :destroy, params: { organization_id: good_place.id, id: chidi.id }
222+
223+
expect(response).to have_http_status(401)
224+
end
225+
end
226+
210227
it 'renders 401 if organization does not exist' do
211228
set_auth_header(chidi)
212229
delete :destroy, params: { organization_id: 123, id: chidi.id }

spec/policies/organization_user_policy_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,3 @@
2727
end
2828
end
2929
end
30-
31-
# run these tests, they should pass
32-
# use this policy in the organization users controller
33-
# update organization user controller spec like we did for invitation controller spec (create mock)
34-
# done? (last check)

0 commit comments

Comments
 (0)