diff --git a/app/controllers/api/v1/protocols_controller.rb b/app/controllers/api/v1/protocols_controller.rb index 107e1ce61..7ad7a0836 100644 --- a/app/controllers/api/v1/protocols_controller.rb +++ b/app/controllers/api/v1/protocols_controller.rb @@ -3,23 +3,26 @@ module Api module V1 class ProtocolsController < BaseController - before_action :load_team - before_action :load_project - before_action :load_experiment - before_action :load_task + include Api::V1::ExtraParams + + before_action :load_team, :load_project, :load_experiment, :load_task + before_action only: :show do + load_protocol(:id) + end def index protocols = @task.protocols .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) render jsonapi: protocols, - each_serializer: ProtocolSerializer + each_serializer: ProtocolSerializer, rte_rendering: render_rte?, team: @team end - private - - def load_protocol - @protocol = @task.protocols.find(params.require(:id)) + def show + render jsonapi: @protocol, serializer: ProtocolSerializer, + include: include_params, + rte_rendering: render_rte?, + team: @team end end end diff --git a/app/controllers/api/v1/steps_controller.rb b/app/controllers/api/v1/steps_controller.rb index b21265825..c6e8bafe8 100644 --- a/app/controllers/api/v1/steps_controller.rb +++ b/app/controllers/api/v1/steps_controller.rb @@ -16,13 +16,15 @@ module Api render jsonapi: steps, each_serializer: StepSerializer, include: include_params, - rte_rendering: render_rte? + rte_rendering: render_rte?, + team: @team end def show render jsonapi: @step, serializer: StepSerializer, include: include_params, - rte_rendering: render_rte? + rte_rendering: render_rte?, + team: @team end def create diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index 0e304f7b3..ac4696d82 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -19,11 +19,11 @@ module Api .page(params.dig(:page, :number)) .per(params.dig(:page, :size)) - render jsonapi: tasks, each_serializer: TaskSerializer, rte_rendering: render_rte? + render jsonapi: tasks, each_serializer: TaskSerializer, rte_rendering: render_rte?, team: @team end def show - render jsonapi: @task, serializer: TaskSerializer, rte_rendering: render_rte? + render jsonapi: @task, serializer: TaskSerializer, rte_rendering: render_rte?, team: @team end def create diff --git a/app/serializers/api/v1/protocol_serializer.rb b/app/serializers/api/v1/protocol_serializer.rb index 176814486..69dbeda20 100644 --- a/app/serializers/api/v1/protocol_serializer.rb +++ b/app/serializers/api/v1/protocol_serializer.rb @@ -3,6 +3,10 @@ module Api module V1 class ProtocolSerializer < ActiveModel::Serializer + include ApplicationHelper + include ActionView::Helpers::TextHelper + include InputSanitizeHelper + type :protocols attributes :id, :name, :authors, :description, :protocol_type has_many :protocol_keywords, @@ -12,6 +16,17 @@ module Api unless: -> { object.protocol_keywords.empty? } has_many :steps, serializer: StepSerializer, if: -> { object.steps.any? } belongs_to :parent, serializer: ProtocolSerializer, if: -> { object.parent.present? } + + def description + if instance_options[:rte_rendering] + custom_auto_link(object.tinymce_render(:description), + simple_format: false, + tags: %w(img), + team: instance_options[:team]) + else + object.description + end + end end end end diff --git a/app/serializers/api/v1/step_serializer.rb b/app/serializers/api/v1/step_serializer.rb index d79485f2f..a6aae74dd 100644 --- a/app/serializers/api/v1/step_serializer.rb +++ b/app/serializers/api/v1/step_serializer.rb @@ -19,7 +19,10 @@ module Api def description if instance_options[:rte_rendering] - custom_auto_link(object.tinymce_render(:description), simple_format: false, tags: %w(img)) + custom_auto_link(object.tinymce_render(:description), + simple_format: false, + tags: %w(img), + team: instance_options[:team]) else object.description end diff --git a/app/serializers/api/v1/task_serializer.rb b/app/serializers/api/v1/task_serializer.rb index ebf635928..6064c2a66 100644 --- a/app/serializers/api/v1/task_serializer.rb +++ b/app/serializers/api/v1/task_serializer.rb @@ -3,6 +3,10 @@ module Api module V1 class TaskSerializer < ActiveModel::Serializer + include ApplicationHelper + include ActionView::Helpers::TextHelper + include InputSanitizeHelper + type :tasks attributes :id, :name, :started_on, :due_date, :description, :state, :archived has_many :output_tasks, key: :outputs, @@ -22,7 +26,10 @@ module Api def description if instance_options[:rte_rendering] - custom_auto_link(object.tinymce_render(:description), simple_format: false, tags: %w(img)) + custom_auto_link(object.tinymce_render(:description), + simple_format: false, + tags: %w(img), + team: instance_options[:team]) else object.description end diff --git a/config/routes.rb b/config/routes.rb index d224e6402..71b2302cb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -716,7 +716,7 @@ Rails.application.routes.draw do resources :task_tags, only: %i(index show), path: 'tags', as: :tags - resources :protocols, only: %i(index) do + resources :protocols, only: %i(index show) do resources :steps do resources :assets, only: %i(index show create), path: 'attachments' resources :checklists, path: 'checklists' do