Skip to content

Commit dcb5050

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

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

app/controllers/api/public_projects_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def create
1919
end
2020

2121
def update
22+
authorize! :update, :public_project
2223
result = PublicProject::Update.call(project: @project, update_hash: update_params)
2324

2425
if result.success?

spec/features/public_project/updating_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 'Updating a public project', type: :request do
6-
let(:creator) { build(:user) }
6+
let(:creator) { build(:experience_cs_admin_user) }
77
let(:project) { create(:project, locale: 'en', project_type: Project::Types::SCRATCH) }
88
let(:headers) { { Authorization: UserProfileMock::TOKEN } }
99
let(:params) { { project: { name: 'New name' } } }
@@ -24,6 +24,15 @@
2424
expect(data).to include(name: 'New name')
2525
end
2626

27+
context 'when creator is not an experience-cs admin' do
28+
let(:creator) { build(:user) }
29+
30+
it 'responds 403 Forbidden' do
31+
put("/api/public_projects/#{project.identifier}?project_type=scratch", headers:, params:)
32+
expect(response).to have_http_status(:forbidden)
33+
end
34+
end
35+
2736
it 'responds 400 Bad Request when params are malformed' do
2837
put("/api/public_projects/#{project.identifier}?project_type=scratch", headers:, params: {})
2938
expect(response).to have_http_status(:bad_request)

spec/requests/public_projects/update_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', project_type: Project::Types::SCRATCH) }
9-
let(:creator) { build(:user) }
9+
let(:creator) { build(:experience_cs_admin_user) }
1010
let(:params) { { project: { name: 'New name' } } }
1111

1212
context 'when auth is correct' do

0 commit comments

Comments
 (0)