Skip to content

Commit cd16453

Browse files
committed
Only experience-cs admins can destroy public projects
For the moment, we only want to allow experience-cs admin users to be able to destroy public projects.
1 parent 5328d95 commit cd16453

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

app/controllers/api/public_projects_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def update
3232
end
3333

3434
def destroy
35+
authorize! :update, :public_project
36+
3537
if @project.destroy
3638
head :ok
3739
else

spec/features/public_project/destroying_a_public_project_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'rails_helper'
44

55
RSpec.describe 'Destroying a public project', type: :request do
6-
let(:destroyer) { build(:user) }
6+
let(:destroyer) { build(:experience_cs_admin_user) }
77
let(:project) { create(:project, locale: 'en') }
88
let(:headers) { { Authorization: UserProfileMock::TOKEN } }
99

@@ -26,6 +26,15 @@
2626
expect(response).to have_http_status(:unauthorized)
2727
end
2828

29+
context 'when destroyer is not an experience-cs admin' do
30+
let(:destroyer) { build(:user) }
31+
32+
it 'responds 403 Forbidden' do
33+
delete("/api/public_projects/#{project.identifier}", headers:)
34+
expect(response).to have_http_status(:forbidden)
35+
end
36+
end
37+
2938
it 'responds 404 Not Found when project is not found' do
3039
delete('/api/public_projects/another-identifier', headers:)
3140
expect(response).to have_http_status(:not_found)

spec/requests/public_projects/destroy_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let(:locale) { 'fr' }
77
let(:project_loader) { instance_double(ProjectLoader) }
88
let(:project) { create(:project, locale: 'en') }
9-
let(:destroyer) { build(:user) }
9+
let(:destroyer) { build(:experience_cs_admin_user) }
1010

1111
context 'when auth is correct' do
1212
let(:headers) { { Authorization: UserProfileMock::TOKEN } }

0 commit comments

Comments
 (0)