Fix protocol filtering by pablished attributes and draft presence [SCI-8070] (#5099)

This commit is contained in:
Alex Kriuchykhin 2023-03-09 14:46:43 +01:00 committed by GitHub
parent 2d0a6c387c
commit 4aded6e7b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -138,7 +138,13 @@ class ProtocolsDatatable < CustomDatatable
records = records.where(protocols: { archived_by_id: params[:archived_by] }) if params[:archived_by].present?
if params[:has_draft].present?
records = records.where(protocols: { protocol_type: Protocol.protocol_types[:in_repository_draft] })
records =
records
.joins("LEFT OUTER JOIN protocols protocol_drafts " \
"ON protocol_drafts.protocol_type = #{Protocol.protocol_types[:in_repository_draft]} " \
"AND (protocol_drafts.parent_id = protocols.id OR protocol_drafts.parent_id = protocols.parent_id)")
.where('protocols.protocol_type = ? OR protocol_drafts.id IS NOT NULL',
Protocol.protocol_types[:in_repository_draft])
end
records