Skip to content

Commit 4e76e24

Browse files
committed
address comments
1 parent 24cfdd7 commit 4e76e24

4 files changed

Lines changed: 13 additions & 18 deletions

File tree

app/controllers/api/projects_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def show_context
6363
private
6464

6565
def set_auth_cookie_for_scratch
66-
return unless @project.project_type == Project::Types::CODE_EDITOR_SCRATCH
66+
return unless @project.scratch_project?
6767
return unless Flipper.enabled?(:cat_mode, school)
6868

6969
cookies[:scratch_auth] = {

app/controllers/api/scratch/projects_controller.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def create
1818
return render json: { error: I18n.t('errors.admin.unauthorized') }, status: :unauthorized unless current_ability.can?(:show, original_project)
1919

2020
remix_params = create_params
21-
return render json: { error: I18n.t('errors.project.remixing.invalid_params') }, status: :bad_request if remix_params[:scratch_component].blank?
21+
return render json: { error: I18n.t('errors.project.remixing.invalid_params') }, status: :bad_request if remix_params.dig(:scratch_component, :content).blank?
2222

2323
remix_origin = request.origin || request.referer
2424

@@ -55,30 +55,25 @@ def source_project_identifier
5555
end
5656

5757
def create_params
58-
{}.tap do |hash|
59-
hash[:identifier] = source_project_identifier
60-
scratch_content = scratch_content_params
61-
hash[:scratch_component] = { content: scratch_content } if scratch_content.present?
62-
end
58+
{
59+
identifier: source_project_identifier,
60+
scratch_component: { content: scratch_content_params }
61+
}
6362
end
6463

6564
def load_original_project(identifier)
6665
project_loader = ProjectLoader.new(identifier, [params[:locale]])
6766
original_project = project_loader.load
6867

6968
raise ActiveRecord::RecordNotFound, I18n.t('errors.project.not_found') unless original_project
70-
raise ActiveRecord::RecordNotFound, I18n.t('errors.project.not_found') unless valid_original_project?(original_project)
69+
raise ActiveRecord::RecordNotFound, I18n.t('errors.project.not_found') unless original_project.scratch_project?
7170

7271
original_project
7372
end
7473

7574
def scratch_content_params
7675
params.slice(:meta, :targets, :monitors, :extensions).to_unsafe_h
7776
end
78-
79-
def valid_original_project?(project)
80-
project.project_type == Project::Types::CODE_EDITOR_SCRATCH
81-
end
8277
end
8378
end
8479
end

app/models/project.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ def media
8282
images + videos + audio
8383
end
8484

85+
def scratch_project?
86+
project_type == Types::CODE_EDITOR_SCRATCH
87+
end
88+
8589
private
8690

8791
def check_unique_not_null

lib/concepts/project/operations/create_remix.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def validate_params(response, params, user_id, original_project, remix_origin)
2323
end
2424

2525
def remix_project(response, params, user_id, original_project, remix_origin)
26-
response[:project] = if scratch_project?(original_project)
26+
response[:project] = if original_project.scratch_project?
2727
create_scratch_remix(original_project, params, user_id, remix_origin)
2828
else
2929
create_remix(original_project, params, user_id, remix_origin)
@@ -57,7 +57,7 @@ def create_remix(original_project, params, user_id, remix_origin)
5757
def create_scratch_remix(original_project, params, user_id, remix_origin)
5858
remix = format_project(original_project, params, user_id, remix_origin)
5959
scratch_component = params.fetch(:scratch_component)
60-
remix.build_scratch_component(content: scratch_component[:content] || scratch_component['content'])
60+
remix.build_scratch_component(content: scratch_component[:content])
6161

6262
remix
6363
end
@@ -73,10 +73,6 @@ def format_project(original_project, params, user_id, remix_origin)
7373
proj.lesson_id = nil # Only the original can have a lesson id
7474
end
7575
end
76-
77-
def scratch_project?(project)
78-
project.project_type == Project::Types::CODE_EDITOR_SCRATCH
79-
end
8076
end
8177
end
8278
end

0 commit comments

Comments
 (0)