mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-11 23:54:43 +08:00
Fix handling of subject class for notifications [SCI-10936]
This commit is contained in:
parent
efd7dd8b0b
commit
52bd8c933b
4 changed files with 17 additions and 6 deletions
|
@ -34,6 +34,10 @@ class BaseNotification < Noticed::Base
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def subject_class
|
||||||
|
ApplicationRecord.descendants.find { |klass| klass.name == params[:subject_class] }
|
||||||
|
end
|
||||||
|
|
||||||
def database_notification?
|
def database_notification?
|
||||||
# always save all notifications,
|
# always save all notifications,
|
||||||
# but flag if they should display in app or not
|
# but flag if they should display in app or not
|
||||||
|
|
|
@ -16,7 +16,7 @@ class DeliveryNotification < BaseNotification
|
||||||
def subject
|
def subject
|
||||||
return unless params[:subject_id] && params[:subject_class]
|
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
|
rescue ActiveRecord::RecordNotFound
|
||||||
NonExistantRecord.new(params[:subject_name])
|
NonExistantRecord.new(params[:subject_name])
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,6 @@ class GeneralNotification < BaseNotification
|
||||||
end
|
end
|
||||||
|
|
||||||
def subject
|
def subject
|
||||||
subject_class = params[:subject_class].constantize
|
|
||||||
subject_class.find(params[:subject_id])
|
subject_class.find(params[:subject_id])
|
||||||
rescue NameError, ActiveRecord::RecordNotFound
|
rescue NameError, ActiveRecord::RecordNotFound
|
||||||
NonExistantRecord.new(params[:subject_name])
|
NonExistantRecord.new(params[:subject_name])
|
||||||
|
|
|
@ -25,14 +25,21 @@ module Lists
|
||||||
@records = @records.preload(:parent, :latest_published_version, :draft,
|
@records = @records.preload(:parent, :latest_published_version, :draft,
|
||||||
:protocol_keywords, user_assignments: %i(user user_role))
|
:protocol_keywords, user_assignments: %i(user user_role))
|
||||||
.joins("LEFT OUTER JOIN protocols protocol_versions " \
|
.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")
|
"AND protocol_versions.parent_id = protocols.parent_id")
|
||||||
.joins("LEFT OUTER JOIN protocols protocol_originals " \
|
.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 " \
|
"AND protocol_originals.id = protocols.parent_id OR " \
|
||||||
"(protocols.id = protocol_originals.id AND protocols.parent_id IS NULL)")
|
"(protocols.id = protocol_originals.id AND protocols.parent_id IS NULL)")
|
||||||
.joins("LEFT OUTER JOIN protocols linked_task_protocols " \
|
.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 " \
|
"AND (linked_task_protocols.parent_id = protocol_versions.id OR " \
|
||||||
"linked_task_protocols.parent_id = protocol_originals.id)")
|
"linked_task_protocols.parent_id = protocol_originals.id)")
|
||||||
.joins('LEFT OUTER JOIN "protocol_protocol_keywords" ' \
|
.joins('LEFT OUTER JOIN "protocol_protocol_keywords" ' \
|
||||||
|
@ -49,7 +56,8 @@ module Lists
|
||||||
'"protocols".*',
|
'"protocols".*',
|
||||||
'COALESCE("protocols"."parent_id", "protocols"."id") AS adjusted_parent_id',
|
'COALESCE("protocols"."parent_id", "protocols"."id") AS adjusted_parent_id',
|
||||||
'STRING_AGG(DISTINCT("protocol_keywords"."name"), \', \') AS "protocol_keywords_str"',
|
'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 " \
|
"THEN 0 ELSE COUNT(DISTINCT(\"protocol_versions\".\"id\")) + 1 " \
|
||||||
"END AS nr_of_versions",
|
"END AS nr_of_versions",
|
||||||
'COUNT(DISTINCT("linked_task_protocols"."id")) AS nr_of_linked_tasks',
|
'COUNT(DISTINCT("linked_task_protocols"."id")) AS nr_of_linked_tasks',
|
||||||
|
|
Loading…
Add table
Reference in a new issue