Fix load protocol to task [SCI-8072] (#5070)

This commit is contained in:
ajugo 2023-03-06 10:53:01 +01:00 committed by GitHub
parent 78c04a3ce0
commit 9379d9a175
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 6 deletions

View file

@ -530,7 +530,7 @@ class ProtocolsController < ApplicationController
else else
@protocol.parent.parent @protocol.parent.parent
end end
@protocol.update_from_parent(current_user, source_parent.latest_published_version) @protocol.update_from_parent(current_user, source_parent.latest_published_version_or_self)
rescue StandardError rescue StandardError
transaction_error = true transaction_error = true
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
@ -813,7 +813,7 @@ class ProtocolsController < ApplicationController
# Create folder and xml file for each protocol and populate it # Create folder and xml file for each protocol and populate it
@protocols.each do |protocol| @protocols.each do |protocol|
protocol = protocol.latest_published_version || protocol protocol = protocol.latest_published_version_or_self
protocol_dir = get_guid(protocol.id).to_s protocol_dir = get_guid(protocol.id).to_s
ostream.put_next_entry("#{protocol_dir}/eln.xml") ostream.put_next_entry("#{protocol_dir}/eln.xml")
ostream.print(generate_protocol_xml(protocol)) ostream.print(generate_protocol_xml(protocol))
@ -1173,7 +1173,7 @@ class ProtocolsController < ApplicationController
def check_clone_permissions def check_clone_permissions
load_team_and_type load_team_and_type
protocol = Protocol.find_by(id: params[:ids][0]) protocol = Protocol.find_by(id: params[:ids][0])
@original = protocol.latest_published_version || protocol @original = protocol.latest_published_version_or_self
if @original.blank? || if @original.blank? ||
!can_clone_protocol_in_repository?(@original) || @type == :archive !can_clone_protocol_in_repository?(@original) || @type == :archive
@ -1251,7 +1251,7 @@ class ProtocolsController < ApplicationController
def check_load_from_repository_permissions def check_load_from_repository_permissions
@protocol = Protocol.find_by(id: params[:id]) @protocol = Protocol.find_by(id: params[:id])
@source = Protocol.find_by(id: params[:source_id])&.latest_published_version @source = Protocol.find_by(id: params[:source_id])&.latest_published_version_or_self
render_403 unless @protocol.present? && @source.present? && render_403 unless @protocol.present? && @source.present? &&
(can_manage_protocol_in_module?(@protocol) && (can_manage_protocol_in_module?(@protocol) &&

View file

@ -144,6 +144,7 @@ class ProtocolsDatatable < CustomDatatable
.select(:id) .select(:id)
published_versions = @team.protocols published_versions = @team.protocols
.where(protocol_type: Protocol.protocol_types[:in_repository_published_version]) .where(protocol_type: Protocol.protocol_types[:in_repository_published_version])
.order(:parent_id, version_number: :desc)
.select('DISTINCT ON (parent_id) id') .select('DISTINCT ON (parent_id) id')
new_drafts = @team.protocols new_drafts = @team.protocols
.where(protocol_type: Protocol.protocol_types[:in_repository_draft], parent_id: nil) .where(protocol_type: Protocol.protocol_types[:in_repository_draft], parent_id: nil)

View file

@ -260,6 +260,10 @@ class Protocol < ApplicationRecord
in_repository_draft? && parent.blank? in_repository_draft? && parent.blank?
end end
def latest_published_version_or_self
latest_published_version || self
end
def permission_parent def permission_parent
in_module? ? my_module : team in_module? ? my_module : team
end end

View file

@ -27,7 +27,7 @@ module ProtocolsExporter
envelope_xml = "<envelope xmlns=\"http://www.scinote.net\" " \ envelope_xml = "<envelope xmlns=\"http://www.scinote.net\" " \
"version=\"1.0\">\n" "version=\"1.0\">\n"
protocols.each do |protocol| protocols.each do |protocol|
protocol = protocol.latest_published_version || protocol protocol = protocol.latest_published_version_or_self
protocol_name = get_protocol_name(protocol) protocol_name = get_protocol_name(protocol)
envelope_xml << "<protocol id=\"#{protocol.id}\" " \ envelope_xml << "<protocol id=\"#{protocol.id}\" " \
"guid=\"#{get_guid(protocol.id)}\">#{protocol_name}" \ "guid=\"#{get_guid(protocol.id)}\">#{protocol_name}" \

View file

@ -9,7 +9,7 @@ module ProtocolsExporterV2
envelope_xml = "<envelope xmlns=\"http://www.scinote.net\" " \ envelope_xml = "<envelope xmlns=\"http://www.scinote.net\" " \
"version=\"1.1\">\n" "version=\"1.1\">\n"
protocols.each do |protocol| protocols.each do |protocol|
protocol = protocol.latest_published_version || protocol protocol = protocol.latest_published_version_or_self
protocol_name = get_protocol_name(protocol) protocol_name = get_protocol_name(protocol)
envelope_xml << "<protocol id=\"#{protocol.id}\" " \ envelope_xml << "<protocol id=\"#{protocol.id}\" " \
"guid=\"#{get_guid(protocol.id)}\">#{protocol_name}" \ "guid=\"#{get_guid(protocol.id)}\">#{protocol_name}" \