scinote-web/app/serializers/protocol_serializer.rb
artoscinote 6352a4dd04
Implement protocol options dropdown [SCI-6750, SCI-6751] (#4066)
* Implement protocol options dropdown [SCI-6750, SCI-6751]

* Implement simple API error handling for step status update [SCI-6354]
2022-05-03 15:18:48 +02:00

43 lines
1 KiB
Ruby

# frozen_string_literal: true
class ProtocolSerializer < ActiveModel::Serializer
include Canaid::Helpers::PermissionsHelper
include Rails.application.routes.url_helpers
attributes :name, :id, :urls
def urls
{
load_from_repo_url: load_from_repo_url,
save_to_repo_url: save_to_repo_url,
export_url: export_url,
import_url: import_url
}
end
private
def load_from_repo_url
return unless can_manage_protocol_in_module?(object)
load_from_repository_modal_protocol_path(object, format: :json)
end
def save_to_repo_url
return unless can_read_protocol_in_module?(object) && can_create_protocols_in_repository?(object.team)
copy_to_repository_modal_protocol_path(object, format: :json)
end
def import_url
return unless can_manage_protocol_in_module?(object)
load_from_file_protocol_path(object, format: :json)
end
def export_url
return unless can_read_protocol_in_module?(object)
export_protocols_path(protocol_ids: object.id, my_module_id: object.my_module.id)
end
end