Fix handling of subject class for notifications [SCI-10936]

This commit is contained in:
Andrej 2024-08-01 11:38:12 +02:00
parent efd7dd8b0b
commit 52bd8c933b
4 changed files with 17 additions and 6 deletions

View file

@ -34,6 +34,10 @@ class BaseNotification < Noticed::Base
private
def subject_class
ApplicationRecord.descendants.find { |klass| klass.name == params[:subject_class] }
end
def database_notification?
# always save all notifications,
# but flag if they should display in app or not

View file

@ -16,7 +16,7 @@ class DeliveryNotification < BaseNotification
def subject
return unless params[:subject_id] && params[:subject_class]
params[:subject_class].constantize.find(params[:subject_id])
subject_class.find(params[:subject_id])
rescue ActiveRecord::RecordNotFound
NonExistantRecord.new(params[:subject_name])
end

View file

@ -14,7 +14,6 @@ class GeneralNotification < BaseNotification
end
def subject
subject_class = params[:subject_class].constantize
subject_class.find(params[:subject_id])
rescue NameError, ActiveRecord::RecordNotFound
NonExistantRecord.new(params[:subject_name])

View file

@ -25,14 +25,21 @@ module Lists
@records = @records.preload(:parent, :latest_published_version, :draft,
:protocol_keywords, user_assignments: %i(user user_role))
.joins("LEFT OUTER JOIN protocols protocol_versions " \
"ON protocol_versions.protocol_type = #{Protocol.protocol_types[:in_repository_published_version]} " \
"ON protocol_versions.protocol_type =
#{Protocol.connection.quote(
Protocol.protocol_types[:in_repository_published_version]
)} " \
"AND protocol_versions.parent_id = protocols.parent_id")
.joins("LEFT OUTER JOIN protocols protocol_originals " \
"ON protocol_originals.protocol_type = #{Protocol.protocol_types[:in_repository_published_original]} " \
"ON protocol_originals.protocol_type =
#{Protocol.connection.quote(
Protocol.protocol_types[:in_repository_published_original]
)} " \
"AND protocol_originals.id = protocols.parent_id OR " \
"(protocols.id = protocol_originals.id AND protocols.parent_id IS NULL)")
.joins("LEFT OUTER JOIN protocols linked_task_protocols " \
"ON linked_task_protocols.protocol_type = #{Protocol.protocol_types[:linked]} " \
"ON linked_task_protocols.protocol_type =
#{Protocol.connection.quote(Protocol.protocol_types[:linked])} " \
"AND (linked_task_protocols.parent_id = protocol_versions.id OR " \
"linked_task_protocols.parent_id = protocol_originals.id)")
.joins('LEFT OUTER JOIN "protocol_protocol_keywords" ' \
@ -49,7 +56,8 @@ module Lists
'"protocols".*',
'COALESCE("protocols"."parent_id", "protocols"."id") AS adjusted_parent_id',
'STRING_AGG(DISTINCT("protocol_keywords"."name"), \', \') AS "protocol_keywords_str"',
"CASE WHEN protocols.protocol_type = #{Protocol.protocol_types[:in_repository_draft]} " \
"CASE WHEN protocols.protocol_type =
#{Protocol.connection.quote(Protocol.protocol_types[:in_repository_draft])} " \
"THEN 0 ELSE COUNT(DISTINCT(\"protocol_versions\".\"id\")) + 1 " \
"END AS nr_of_versions",
'COUNT(DISTINCT("linked_task_protocols"."id")) AS nr_of_linked_tasks',