Skip to content

Allow Experience CS admins to create public projects #549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5618e23
Add Api::PublicProjectsController#create
floehopper May 21, 2025
0ca3b3d
Strict param parsing for Api::PublicProjectsController
floehopper May 21, 2025
bb435d6
Extract User#parsed_roles method
floehopper May 21, 2025
260e08a
Introduce User#experience_cs_admin? method
floehopper May 21, 2025
88c836d
Introduce permission for creating public projects
floehopper May 21, 2025
d715c7a
Only experience-cs admins can create public projects
floehopper May 21, 2025
37761e6
Rename Project#check_unique_not_null -> generate_identifier
floehopper May 21, 2025
8ddea4d
Simplify example for Project#generate_identifier
floehopper May 22, 2025
97d2460
Allow skipping of identifier generation
floehopper May 22, 2025
dfa6214
Require identifier when creating public project
floehopper May 22, 2025
f509f01
Forbid creation of non-Scratch public projects
floehopper May 22, 2025
cfb532d
Introduce PhraseIdentifier::PATTERN
floehopper May 22, 2025
490e59a
Introduce PublicProject model
floehopper May 22, 2025
06ac4fa
Validate format of identifier for public project
floehopper May 22, 2025
288aeee
Validate presence of name for public project
floehopper May 22, 2025
963d8fa
Ensure Project#user_id is not set on public project
floehopper May 22, 2025
6f20092
Rename project_params in PublicProjectsController
floehopper May 23, 2025
29478e1
Add Api::PublicProjectsController#update
floehopper May 23, 2025
626b2e0
Use ProjectLoader in Api::PublicProjectsController
floehopper May 23, 2025
7a52343
Make updating public projects specs more realistic
floehopper May 23, 2025
f802d9b
Introduce permission for updating public projects
floehopper May 23, 2025
8a7adee
Only experience-cs admins can update public projects
floehopper May 23, 2025
2b6878c
Forbid updating of non-public projects
floehopper May 23, 2025
2651edd
Public project update cannot change certain attributes
floehopper May 23, 2025
1c75c8c
Use PublicProject validations in PublicProject:Update
floehopper May 23, 2025
dd4a009
Add Api::PublicProjectsController#destroy
floehopper May 23, 2025
4d86773
Introduce permission for destroying public projects
floehopper May 23, 2025
0b5c42e
Only experience-cs admins can destroy public projects
floehopper May 23, 2025
0eb3880
Make destroying public projects specs more realistic
floehopper May 23, 2025
adea633
Forbid destroying of non-public projects
floehopper May 23, 2025
1b08bbd
Prevent destruction of public project with remixes
floehopper May 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use PublicProject validations in PublicProject:Update
We can re-use the validations in the `PublicProject` wrapper class to
ensure that, in `Api::PublicProjectsController#update`, the project
identifier is updated to a non-blank value in the correct format and the
project name is updated to a non-blank value.
  • Loading branch information
floehopper committed May 24, 2025
commit 1c75c8c78bbf47579c2088622e4a25c259d905d2
5 changes: 3 additions & 2 deletions lib/concepts/public_project/operations/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ def call(project:, update_hash:)
response = OperationResponse.new

project.assign_attributes(update_hash)
project.save!
public_project = PublicProject.new(project)
public_project.save!

response[:project] = project
response[:project] = public_project.project
response
rescue StandardError => e
Sentry.capture_exception(e)
Expand Down
36 changes: 36 additions & 0 deletions spec/concepts/public_project/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,41 @@
expect(Sentry).to have_received(:capture_exception).with(kind_of(StandardError))
end
end

context 'when identifier is blank' do
let(:new_identifier) { nil }

it 'returns failure' do
expect(update_project.failure?).to be(true)
end

it 'returns error message' do
expect(update_project[:error]).to eq("Error updating project: Validation failed: Identifier can't be blank")
end
end

context 'when identifier is in invalid format' do
let(:new_identifier) { 'FooBarBaz' }

it 'returns failure' do
expect(update_project.failure?).to be(true)
end

it 'returns error message' do
expect(update_project[:error]).to eq('Error updating project: Validation failed: Identifier is invalid')
end
end

context 'when name is blank' do
let(:new_name) { '' }

it 'returns failure' do
expect(update_project.failure?).to be(true)
end

it 'returns error message' do
expect(update_project[:error]).to eq("Error updating project: Validation failed: Name can't be blank")
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@
put('/api/public_projects/another-identifier?project_type=scratch', headers:, params:)
expect(response).to have_http_status(:not_found)
end

it 'responds 422 Unprocessable Entity when params are invalid' do
put("/api/public_projects/#{project.identifier}?project_type=scratch", headers:, params: { project: { name: '' } })
expect(response).to have_http_status(:unprocessable_entity)
end
end