From e3de5fe587bf6dd11d019106b367d95e66e5c428 Mon Sep 17 00:00:00 2001 From: Jennifer Vendetti Date: Wed, 17 Apr 2024 17:51:54 -0700 Subject: [PATCH 1/2] Create ERB template for OBO Foundry notification --- views/emails/obofoundry_sync.erb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 views/emails/obofoundry_sync.erb diff --git a/views/emails/obofoundry_sync.erb b/views/emails/obofoundry_sync.erb new file mode 100644 index 00000000..f445b646 --- /dev/null +++ b/views/emails/obofoundry_sync.erb @@ -0,0 +1,17 @@ +<% if missing_onts.present? %> + The following OBO Foundry ontologies are missing from <%= ui_name %>:

+ <% missing_onts.each do |ont| %> + <%= ont['id'] %> (<%= ont['title'] %>)

+ <% end %> +<% end %> + +<% if obsolete_onts.present? %> + The following OBO Foundry ontologies have been deprecated:

+ <% obsolete_onts.each do |ont| %> + <%= ont['id'] %> (<%= ont['title'] %>)

+ <% end %> +<% end %> + +<% if missing_onts.blank? && obsolete_onts.blank? %> + <%= ui_name %> and the OBO Foundry are in sync. +<% end %> From bd2ad7f259053eca0f41f631706be791dea5abd9 Mon Sep 17 00:00:00 2001 From: Jennifer Vendetti Date: Wed, 17 Apr 2024 17:52:36 -0700 Subject: [PATCH 2/2] Generate notification body from template --- .../utils/notifications.rb | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/ontologies_linked_data/utils/notifications.rb b/lib/ontologies_linked_data/utils/notifications.rb index fecca046..fc28b21b 100644 --- a/lib/ontologies_linked_data/utils/notifications.rb +++ b/lib/ontologies_linked_data/utils/notifications.rb @@ -106,28 +106,16 @@ def self.reset_password(user, token) def self.obofoundry_sync(missing_onts, obsolete_onts) ui_name = LinkedData.settings.ui_name - subject = "[#{ui_name}] OBO Foundry synchronization report" - body = '' - - if missing_onts.size > 0 - body << "The following OBO Library ontologies are missing from #{ui_name}:

" - missing_onts.each do |ont| - body << "#{ont['id']} (#{ont['title']})

" - end - end - - if obsolete_onts.size > 0 - body << 'The following OBO Library ontologies have been deprecated:

' - obsolete_onts.each do |ont| - body << "#{ont['id']} (#{ont['title']})

" - end - end + gem_path = Gem.loaded_specs['ontologies_linked_data'].full_gem_path + template = File.read(File.join(gem_path, 'views/emails/obofoundry_sync.erb')) - if body.empty? - body << "#{ui_name} and the OBO Foundry are in sync.

" - end + b = binding + b.local_variable_set(:ui_name, ui_name) + b.local_variable_set(:missing_onts, missing_onts) + b.local_variable_set(:obsolete_onts, obsolete_onts) + body = ERB.new(template).result(b) - Notifier.notify_mails_separately subject, body, [LinkedData.settings.email_sender] + Notifier.notify_ontoportal_admins("[#{ui_name}] OBO Foundry synchronization report", body) end NEW_NOTE = <