diff --git a/app/controllers/api/scratch/projects_controller.rb b/app/controllers/api/scratch/projects_controller.rb index 772056ee1..4d90722ff 100644 --- a/app/controllers/api/scratch/projects_controller.rb +++ b/app/controllers/api/scratch/projects_controller.rb @@ -62,13 +62,7 @@ def create_params end def load_original_project(identifier) - project_loader = ProjectLoader.new(identifier, [params[:locale]]) - original_project = project_loader.load - - raise ActiveRecord::RecordNotFound, I18n.t('errors.project.not_found') unless original_project - raise ActiveRecord::RecordNotFound, I18n.t('errors.project.not_found') unless original_project.scratch_project? - - original_project + Project.find_by!(identifier:, project_type: Project::Types::CODE_EDITOR_SCRATCH) end def scratch_content_params diff --git a/app/controllers/api/scratch/scratch_controller.rb b/app/controllers/api/scratch/scratch_controller.rb index c1b792141..9b1d1b187 100644 --- a/app/controllers/api/scratch/scratch_controller.rb +++ b/app/controllers/api/scratch/scratch_controller.rb @@ -18,8 +18,7 @@ def check_scratch_feature end def load_project - project_loader = ProjectLoader.new(params[:id], [params[:locale]]) - @project = project_loader.load + @project = Project.find_by!(identifier: params[:id], project_type: Project::Types::CODE_EDITOR_SCRATCH) end end end diff --git a/spec/features/scratch/showing_a_scratch_project_spec.rb b/spec/features/scratch/showing_a_scratch_project_spec.rb index 40bd25c3b..dcd760ca6 100644 --- a/spec/features/scratch/showing_a_scratch_project_spec.rb +++ b/spec/features/scratch/showing_a_scratch_project_spec.rb @@ -18,4 +18,18 @@ data = JSON.parse(response.body, symbolize_names: true) expect(data).to have_key(:targets) end + + it 'returns a 404 if project does not exist' do + get '/api/scratch/projects/non_existent_project' + + expect(response).to have_http_status(:not_found) + end + + it 'returns a 404 if project is not a scratch project' do + project = create(:project, project_type: Project::Types::PYTHON, locale: 'en') + + get "/api/scratch/projects/#{project.identifier}" + + expect(response).to have_http_status(:not_found) + end end