2022-05-27 18:22:14 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-05-30 19:45:51 +08:00
|
|
|
module StepElements
|
2022-05-27 18:22:14 +08:00
|
|
|
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)
|
2022-07-21 15:57:14 +08:00
|
|
|
step_orderable_element = orderable.step_orderable_element
|
2022-05-27 18:22:14 +08:00
|
|
|
render json: step_orderable_element, serializer: StepOrderableElementSerializer, user: current_user
|
|
|
|
end
|
2022-06-02 17:15:32 +08:00
|
|
|
|
|
|
|
def log_step_activity(element_type_of, message_items)
|
2022-06-07 18:10:10 +08:00
|
|
|
message_items[:my_module] = @protocol.my_module.id if @protocol.in_module?
|
|
|
|
|
2022-06-02 17:15:32 +08:00
|
|
|
Activities::CreateActivityService.call(
|
2022-06-07 18:10:10 +08:00
|
|
|
activity_type: "#{!@step.protocol.in_module? ? 'protocol_step_' : 'task_step_'}#{element_type_of}",
|
2022-06-02 17:15:32 +08:00
|
|
|
owner: current_user,
|
2022-11-24 22:19:17 +08:00
|
|
|
team: @protocol.team,
|
|
|
|
project: @protocol.in_module? ? @protocol.my_module.project : nil,
|
2022-06-02 17:15:32 +08:00
|
|
|
subject: @protocol,
|
|
|
|
message_items: {
|
|
|
|
step: @step.id,
|
|
|
|
step_position: {
|
|
|
|
id: @step.id,
|
|
|
|
value_for: 'position_plus_one'
|
|
|
|
},
|
|
|
|
}.merge(message_items)
|
|
|
|
)
|
|
|
|
end
|
2022-05-27 18:22:14 +08:00
|
|
|
end
|
|
|
|
end
|