Allow assigning tips during exercise create
Fixes CODEOCEAN-H6
This commit is contained in:
@ -254,11 +254,11 @@ class ExercisesController < ApplicationController
|
|||||||
|
|
||||||
private :handle_file_uploads
|
private :handle_file_uploads
|
||||||
|
|
||||||
def handle_exercise_tips
|
def handle_exercise_tips(tips_params)
|
||||||
return unless exercise_params && exercise_params[:tips]
|
return unless tips_params
|
||||||
|
|
||||||
begin
|
begin
|
||||||
exercise_tips = JSON.parse(exercise_params[:tips])
|
exercise_tips = JSON.parse(tips_params)
|
||||||
# Order is important to ensure no foreign key restraints are violated during delete
|
# Order is important to ensure no foreign key restraints are violated during delete
|
||||||
previous_exercise_tips = ExerciseTip.where(exercise: @exercise).select(:id).order(rank: :desc).ids
|
previous_exercise_tips = ExerciseTip.where(exercise: @exercise).select(:id).order(rank: :desc).ids
|
||||||
remaining_exercise_tips = update_exercise_tips exercise_tips, nil, 1
|
remaining_exercise_tips = update_exercise_tips exercise_tips, nil, 1
|
||||||
@ -429,11 +429,14 @@ class ExercisesController < ApplicationController
|
|||||||
def create
|
def create
|
||||||
@exercise = Exercise.new(exercise_params&.except(:tips))
|
@exercise = Exercise.new(exercise_params&.except(:tips))
|
||||||
authorize!
|
authorize!
|
||||||
handle_exercise_tips
|
|
||||||
collect_set_and_unset_exercise_tags
|
collect_set_and_unset_exercise_tags
|
||||||
|
tips_params = exercise_params&.dig(:tips)
|
||||||
return if performed?
|
return if performed?
|
||||||
|
|
||||||
create_and_respond(object: @exercise, params: exercise_params_with_tags)
|
create_and_respond(object: @exercise, params: exercise_params_with_tags) do
|
||||||
|
# We first need to create the exercise before handling tips
|
||||||
|
handle_exercise_tips tips_params
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def not_authorized_for_exercise(_exception)
|
def not_authorized_for_exercise(_exception)
|
||||||
@ -491,7 +494,7 @@ class ExercisesController < ApplicationController
|
|||||||
private :collect_set_and_unset_exercise_tags
|
private :collect_set_and_unset_exercise_tags
|
||||||
|
|
||||||
def update
|
def update
|
||||||
handle_exercise_tips
|
handle_exercise_tips exercise_params&.dig(:tips)
|
||||||
return if performed?
|
return if performed?
|
||||||
|
|
||||||
update_and_respond(object: @exercise, params: exercise_params_with_tags)
|
update_and_respond(object: @exercise, params: exercise_params_with_tags)
|
||||||
|
Reference in New Issue
Block a user