Skip to content

Commit

Permalink
Merge pull request #197 from ncbo/refactor/erb-notification
Browse files Browse the repository at this point in the history
Proposed refactor: convert notification bodies to ERB templates
  • Loading branch information
alexskr authored Oct 1, 2024
2 parents 7dbf782 + bd2ad7f commit 5b44098
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
28 changes: 8 additions & 20 deletions lib/ontologies_linked_data/utils/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 << "<strong>The following OBO Library ontologies are missing from #{ui_name}:</strong><br/><br/>"
missing_onts.each do |ont|
body << "<a href='#{ont['homepage']}'>#{ont['id']}</a> (#{ont['title']})<br/><br/>"
end
end

if obsolete_onts.size > 0
body << '<strong>The following OBO Library ontologies have been deprecated:</strong><br/><br/>'
obsolete_onts.each do |ont|
body << "<a href='#{ont['homepage']}'>#{ont['id']}</a> (#{ont['title']})<br/><br/>"
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.<br/><br/>"
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 = <<EOS
Expand Down
17 changes: 17 additions & 0 deletions views/emails/obofoundry_sync.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% if missing_onts.present? %>
<strong>The following OBO Foundry ontologies are missing from <%= ui_name %>:</strong><br /><br />
<% missing_onts.each do |ont| %>
<a href="<%= ont['homepage'] %>"><%= ont['id'] %></a> (<%= ont['title'] %>)<br /><br />
<% end %>
<% end %>

<% if obsolete_onts.present? %>
<strong>The following OBO Foundry ontologies have been deprecated:</strong><br /><br />
<% obsolete_onts.each do |ont| %>
<a href="<%= ont['homepage'] %>"><%= ont['id'] %></a> (<%= ont['title'] %>)<br /><br />
<% end %>
<% end %>

<% if missing_onts.blank? && obsolete_onts.blank? %>
<%= ui_name %> and the OBO Foundry are in sync.
<% end %>

0 comments on commit 5b44098

Please sign in to comment.