mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 17:36:33 +08:00
Add missing base controller
This commit is contained in:
parent
57408e9f4f
commit
b7e78f567c
1 changed files with 37 additions and 0 deletions
37
app/controllers/step_components/base_controller.rb
Normal file
37
app/controllers/step_components/base_controller.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module StepComponents
|
||||
class BaseController < ApplicationController
|
||||
before_action :load_step_and_protocol
|
||||
before_action :check_manage_permissions
|
||||
|
||||
private
|
||||
|
||||
def load_step_and_protocol
|
||||
@step = Step.find_by(id: params[:step_id])
|
||||
return render_404 unless @step
|
||||
|
||||
@protocol = @step.protocol
|
||||
end
|
||||
|
||||
def check_manage_permissions
|
||||
render_403 unless can_manage_step?(@step)
|
||||
end
|
||||
|
||||
def create_in_step!(step, new_orderable)
|
||||
ActiveRecord::Base.transaction do
|
||||
new_orderable.save!
|
||||
|
||||
step.step_orderable_elements.create!(
|
||||
position: step.step_orderable_elements.length,
|
||||
orderable: new_orderable
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def render_step_orderable_element(orderable)
|
||||
step_orderable_element = orderable.step_orderable_elements.find_by!(step: @step)
|
||||
render json: step_orderable_element, serializer: StepOrderableElementSerializer, user: current_user
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue