diff --git a/lib/ontologies_linked_data/utils/notifications.rb b/lib/ontologies_linked_data/utils/notifications.rb index 5a195784..01e6dba6 100644 --- a/lib/ontologies_linked_data/utils/notifications.rb +++ b/lib/ontologies_linked_data/utils/notifications.rb @@ -61,18 +61,9 @@ def self.remote_ontology_pull(submission) .gsub('%ontology_location%', LinkedData::Hypermedia.generate_links(ontology)['ui']) .gsub('%support_contact%', LinkedData.settings.support_contact_email) .gsub('%ui_name%', LinkedData.settings.ui_name) - recipients = [] - ontology.administeredBy.each do |user| - user.bring(:email) if user.bring?(:email) - recipients << user.email - end - if !LinkedData.settings.ontoportal_admin_emails.nil? && LinkedData.settings.ontoportal_admin_emails.kind_of?(Array) - LinkedData.settings.ontoportal_admin_emails.each do |admin_email| - recipients << admin_email - end - end - Notifier.notify_mails_grouped subject, body, [Notifier.ontology_admin_emails(ontology) + Notifier.ontoportal_admin_emails] + Notifier.notify_ontoportal_admins_grouped subject, body + Notifier.notify_administrators_grouped subject, body, ontology end def self.new_user(user) @@ -83,7 +74,6 @@ def self.new_user(user) .gsub('%email%', user.email.to_s) .gsub('%site_url%', LinkedData.settings.ui_host) .gsub('%ui_name%', LinkedData.settings.ui_name) - recipients = LinkedData.settings.ontoportal_admin_emails Notifier.notify_ontoportal_admins_grouped subject, body end @@ -98,7 +88,6 @@ def self.new_ontology(ont) .gsub('%site_url%', LinkedData.settings.ui_host) .gsub('%ont_url%', LinkedData::Hypermedia.generate_links(ont)['ui']) .gsub('%ui_name%', LinkedData.settings.ui_name) - recipients = LinkedData.settings.ontoportal_admin_emails Notifier.notify_ontoportal_admins_grouped subject, body end @@ -108,7 +97,7 @@ def self.reset_password(user, token) subject = "[#{ui_name}] User #{user.username} password reset" password_url = "https://#{LinkedData.settings.ui_host}/reset_password?tk=#{token}&em=#{CGI.escape(user.email)}&un=#{CGI.escape(user.username)}" - body = REST_PASSWORD.gsub('%ui_name%', ui_name) + body = REST_PASSWORD.gsub('%ui_name%', ui_name) .gsub('%username%', user.username.to_s) .gsub('%password_url%', password_url.to_s) @@ -212,7 +201,6 @@ def self.obofoundry_sync(missing_onts, obsolete_onts) Thanks,
%ui_name% Team HTML - end end end diff --git a/lib/ontologies_linked_data/utils/notifier.rb b/lib/ontologies_linked_data/utils/notifier.rb index aa4f1363..96d60da1 100644 --- a/lib/ontologies_linked_data/utils/notifier.rb +++ b/lib/ontologies_linked_data/utils/notifier.rb @@ -30,8 +30,12 @@ def self.notify(options = {}) }) end + def self.administrative_notifications_enabled? + LinkedData.settings.enable_administrative_notifications + end + def self.notify_ontoportal_admins_grouped(subject, body) - notify_mails_grouped subject, body, ontoportal_admin_emails if LinkedData.settings.enable_administrative_notifications + notify_mails_grouped subject, body, ontoportal_admin_emails if administrative_notifications_enabled? end def self.notify_subscribed_separately(subject, body, ontology, notification_type) @@ -59,7 +63,7 @@ def self.notify_mails_grouped(subject, body, mail) end def self.notify_ontoportal_admins(subject, body) - notify_mails_grouped subject, body, ontoportal_admin_emails if LinkedData.settings.enable_administrative_notifications + notify_mails_grouped subject, body, ontoportal_admin_emails if administrative_notifications_enabled? end def self.ontology_admin_emails(ontology) @@ -73,11 +77,8 @@ def self.ontology_admin_emails(ontology) end def self.ontoportal_admin_emails + return LinkedData.settings.ontoportal_admin_emails if LinkedData.settings.ontoportal_admin_emails.is_a?(Array) - if !LinkedData.settings.ontoportal_admin_emails.nil? && - LinkedData.settings.ontoportal_admin_emails.kind_of?(Array) - return LinkedData.settings.ontoportal_admin_emails - end [] end @@ -85,7 +86,6 @@ def self.subscribed_users_mails(ontology, notification_type) emails = [] ontology.bring(:subscriptions) if ontology.bring?(:subscriptions) ontology.subscriptions.each do |subscription| - subscription.bring(:notification_type) if subscription.bring?(:notification_type) subscription.notification_type.bring(:type) if subscription.notification_type.bring?(:notification_type) diff --git a/test/util/test_notifications.rb b/test/util/test_notifications.rb index 76b2f0ff..d20feb5b 100644 --- a/test/util/test_notifications.rb +++ b/test/util/test_notifications.rb @@ -38,6 +38,7 @@ def self.after_suite def setup LinkedData.settings.email_disable_override = true + reset_mailer end def _subscription(ont) @@ -82,13 +83,11 @@ def test_new_note_notification note.save assert_match "[#{@@ui_name} Notes]", last_email_sent.subject assert_equal [@@user.email], last_email_sent.to - reset_mailer ensure note.delete if note end def test_processing_complete_notification - reset_mailer options = { ont_count: 1, submission_count: 1, acronym: "NOTIFY" } ont = LinkedData::SampleData::Ontology.create_ontologies_and_submissions(options)[2].first subscription = _subscription(ont) @@ -114,7 +113,6 @@ def test_processing_complete_notification end def test_disable_administrative_notifications - reset_mailer LinkedData.settings.enable_administrative_notifications = false options = { ont_count: 1, submission_count: 1, acronym: "DONTNOTIFY" } ont = LinkedData::SampleData::Ontology.create_ontologies_and_submissions(options)[2].first @@ -130,7 +128,6 @@ def test_disable_administrative_notifications ont.delete if ont end - def test_remote_ontology_pull_notification recipients = ["test@example.org"] ont_count, acronyms, ontologies = LinkedData::SampleData::Ontology.create_ontologies_and_submissions(ont_count: 1, submission_count: 1, process_submission: false) @@ -153,12 +150,11 @@ def test_remote_ontology_pull_notification assert sub.valid?, sub.errors LinkedData::Utils::Notifications.remote_ontology_pull(sub) + admin_mails = LinkedData::Utils::Notifier.ontology_admin_emails(ont) + assert_includes "[#{@@ui_name}] Load from URL failure for #{ont.name}", last_email_sent.subject - recipients = @@support_mails - ont_admins.each do |user| - recipients << user.email - end - assert_equal recipients.sort, last_email_sent.to.sort + assert_equal @@support_mails, all_emails.first.to + assert_equal admin_mails, last_email_sent.to.sort ensure ont_admins.each do |user| user.delete if user