diff --git a/app/controllers/content_providers_controller.rb b/app/controllers/content_providers_controller.rb index 7c9bc7271..854f29053 100644 --- a/app/controllers/content_providers_controller.rb +++ b/app/controllers/content_providers_controller.rb @@ -109,7 +109,7 @@ def content_provider_params params[:content_provider].delete :node_name permitted = [:title, :url, :image, :image_url, :description, :id, :content_provider_type, :node_id, :contact, - :event_curation_email, + :content_curation_email, { keywords: [] }, :remote_updated_date, :remote_created_date, { approved_editors: [] }, :local_updated_date, :remote_updated_date, :node_name, :user_id] diff --git a/app/mailers/curation_mailer.rb b/app/mailers/curation_mailer.rb index 6217f5c4c..1d4c8ca12 100644 --- a/app/mailers/curation_mailer.rb +++ b/app/mailers/curation_mailer.rb @@ -23,12 +23,24 @@ def source_requires_approval(source, user) def events_require_approval(provider, cut_off_time) @provider = provider - return unless @provider.event_curation_email.present? + return unless @provider.content_curation_email.present? # @events = @provider.events.where { |e| e.lmm_processed > cut_off_time } @events = @provider.events.filter { |e| e.created_at > cut_off_time } subject = t('mailer.events_require_approval.subject', site_name: TeSS::Config.site['title_short']) - mail(subject:, to: @provider.event_curation_email) do |format| + mail(subject:, to: @provider.content_curation_email) do |format| + format.html + format.text + end + end + + def materials_require_approval(provider, cut_off_time) + @provider = provider + return unless @provider.content_curation_email.present? + + @materials = @provider.materials.filter { |e| e.created_at > cut_off_time } + subject = t('mailer.materials_require_approval.subject', site_name: TeSS::Config.site['title_short']) + mail(subject:, to: @provider.content_curation_email) do |format| format.html format.text end diff --git a/app/views/content_providers/_form.html.erb b/app/views/content_providers/_form.html.erb index bcb24d916..811c882ca 100644 --- a/app/views/content_providers/_form.html.erb +++ b/app/views/content_providers/_form.html.erb @@ -23,7 +23,7 @@ <% end %> <% if current_user.is_admin? || current_user == @content_provider.user%> - <%= f.input :event_curation_email, label: 'Receive event curation emails at this address' %> + <%= f.input :content_curation_email, label: 'Receive content curation emails at this address' %> <% end %> <% if !TeSS::Config.feature['disabled'].include? 'approved_editors' %> diff --git a/app/views/curation_mailer/materials_require_approval.html.erb b/app/views/curation_mailer/materials_require_approval.html.erb new file mode 100644 index 000000000..743012378 --- /dev/null +++ b/app/views/curation_mailer/materials_require_approval.html.erb @@ -0,0 +1,23 @@ +

+ You are receiving this automated email because you are a curator of <%= @provider.title %> on <%= TeSS::Config.site['title_short'] %>. +

+<% if @materials.count.positive? %> +

+ If any of these materials are incorrect or should not be shown, please follow the link to change them.
+ If a material should not be shown, disable it on the edit page instead of deleting it to prevent rescraping.
+ If a material needs changes, lock the changed fields to prevent your changes from being overwritten by the scraper.
+

+ + <% @materials.each do |material| %> +

+ <%= link_to material.title, material %>
+ description: <%= material.description %>
+ show: <%= material.visible %>
+

+ + <% end %> +<% else %> +

+ There were no new materials this week. +

+<% end %> diff --git a/app/views/curation_mailer/materials_require_approval.text.erb b/app/views/curation_mailer/materials_require_approval.text.erb new file mode 100644 index 000000000..e834411fb --- /dev/null +++ b/app/views/curation_mailer/materials_require_approval.text.erb @@ -0,0 +1,17 @@ +You are receiving this automated email because you are a curator of <%= @provider.title %> on <%= TeSS::Config.site['title_short'] %>. +<% if @materials.count.positive? %> + If any of these materials are incorrect or should not be shown, please follow the link to change them. + If an material should not be shown, disable it on the edit page instead of deleting it to prevent rescraping. + If an material needs changes, lock the changed fields to prevent your changes from being overwritten by the scraper. + + <% @materials.each do |material| %> + <%= material.title %> (<%= url_for(material) %>) + description: <%= material.description %> + show: <%= material.visible %> + + <% end %> +<% else %> + There were no new materials this week. +<% end %> + + diff --git a/config/locales/en.yml b/config/locales/en.yml index 4adab73fc..cb1c01f21 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -801,6 +801,8 @@ en: mailer: events_require_approval: subject: "Last week's events on %{site_name}" + materials_require_approval: + subject: "Last week's materials on %{site_name}" search_query: 'Search query:' sidebar: sort: diff --git a/db/migrate/20241202092029_rename_event_curation_email.rb b/db/migrate/20241202092029_rename_event_curation_email.rb new file mode 100644 index 000000000..b29ec6bf5 --- /dev/null +++ b/db/migrate/20241202092029_rename_event_curation_email.rb @@ -0,0 +1,5 @@ +class RenameEventCurationEmail < ActiveRecord::Migration[7.0] + def change + rename_column :content_providers, :event_curation_email, :content_curation_email + end +end diff --git a/db/schema.rb b/db/schema.rb index 399305cca..25d13124a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_11_19_152528) do +ActiveRecord::Schema[7.0].define(version: 2024_12_02_092029) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -145,7 +145,7 @@ t.bigint "image_file_size" t.datetime "image_updated_at" t.string "contact" - t.string "event_curation_email" + t.string "content_curation_email" t.index ["node_id"], name: "index_content_providers_on_node_id" t.index ["slug"], name: "index_content_providers_on_slug", unique: true t.index ["user_id"], name: "index_content_providers_on_user_id" diff --git a/lib/tasks/tess.rake b/lib/tasks/tess.rake index 28d4c0680..6ab3336f5 100644 --- a/lib/tasks/tess.rake +++ b/lib/tasks/tess.rake @@ -152,9 +152,10 @@ namespace :tess do desc 'mail content providers for curation of scraped events' task event_curation_mails: :environment do cut_off_time = Time.zone.now - 1.week - providers = ContentProvider.all.filter { |provider| provider.event_curation_email.present? } + providers = ContentProvider.all.filter { |provider| provider.content_curation_email.present? } providers.each do |provider| CurationMailer.events_require_approval(provider, cut_off_time).deliver_later + CurationMailer.materials_require_approval(provider, cut_off_time).deliver_later end puts 'Curation mails sent' end diff --git a/test/fixtures/content_providers.yml b/test/fixtures/content_providers.yml index a6dd7f4d2..1e83013f8 100644 --- a/test/fixtures/content_providers.yml +++ b/test/fixtures/content_providers.yml @@ -9,7 +9,7 @@ goblet: node: good content_provider_type: Portal contact: contact@goblet.org - event_curation_email: curation@goblet.org + content_curation_email: curation@goblet.org iann: title: iAnn diff --git a/test/mailers/curation_mailer_test.rb b/test/mailers/curation_mailer_test.rb index 65acd1991..619c2cd30 100644 --- a/test/mailers/curation_mailer_test.rb +++ b/test/mailers/curation_mailer_test.rb @@ -89,7 +89,7 @@ class CurationMailerTest < ActionMailer::TestCase end assert_equal [TeSS::Config.sender_email], email.from - assert_equal [@content_provider.event_curation_email], email.to + assert_equal [@content_provider.content_curation_email], email.to assert_equal "Last week's events on #{TeSS::Config.site['title_short']}", email.subject text_body = email.text_part.body.to_s @@ -116,7 +116,7 @@ class CurationMailerTest < ActionMailer::TestCase end assert_equal [TeSS::Config.sender_email], email.from - assert_equal [@content_provider.event_curation_email], email.to + assert_equal [@content_provider.content_curation_email], email.to assert_equal "Last week's events on #{TeSS::Config.site['title_short']}", email.subject [email.text_part, email.html_part].each do |part| @@ -127,8 +127,8 @@ class CurationMailerTest < ActionMailer::TestCase test 'text events approval no mail if disabled' do @content_provider = content_providers(:goblet) @events = [events(:one), events(:scraper_user_event)] - [[nil, 0], [@content_provider.event_curation_email, 1]].each do |val, count| - @content_provider.event_curation_email = val + [[nil, 0], [@content_provider.content_curation_email, 1]].each do |val, count| + @content_provider.content_curation_email = val email = CurationMailer.events_require_approval(@content_provider, @events.pluck(:created_at).min - 1.week) assert_emails count do @@ -136,4 +136,59 @@ class CurationMailerTest < ActionMailer::TestCase end end end + + test 'text materials approval' do + @content_provider = content_providers(:goblet) + @materials = [materials(:good_material)] + email = CurationMailer.materials_require_approval(@content_provider, @materials.pluck(:created_at).min - 1.week) + + assert_emails 1 do + email.deliver_now + end + + assert_equal [TeSS::Config.sender_email], email.from + assert_equal [@content_provider.content_curation_email], email.to + assert_equal "Last week's materials on #{TeSS::Config.site['title_short']}", email.subject + + text_body = email.text_part.body.to_s + html_body = email.html_part.body.to_s + + [text_body, html_body].each do |body| + @materials.each do |material| + assert body.include?(material.title) + assert body.include?(material.description) + assert body.include?(material.visible.to_s) + end + end + end + + test 'text materials approval no materials' do + @content_provider = content_providers(:goblet) + email = CurationMailer.materials_require_approval(@content_provider, Time.zone.now) + + assert_emails 1 do + email.deliver_now + end + + assert_equal [TeSS::Config.sender_email], email.from + assert_equal [@content_provider.content_curation_email], email.to + assert_equal "Last week's materials on #{TeSS::Config.site['title_short']}", email.subject + + [email.text_part, email.html_part].each do |part| + assert part.body.to_s.include?('There were no new materials this week.') + end + end + + test 'text materials approval no mail if disabled' do + @content_provider = content_providers(:goblet) + @materials = [materials(:good_material), materials(:scraper_user_material)] + [[nil, 0], [@content_provider.content_curation_email, 1]].each do |val, count| + @content_provider.content_curation_email = val + email = CurationMailer.materials_require_approval(@content_provider, @materials.pluck(:created_at).min - 1.week) + + assert_emails count do + email.deliver_now + end + end + end end diff --git a/test/mailers/previews/curation_mailer_preview.rb b/test/mailers/previews/curation_mailer_preview.rb index e38bb30e6..8ea28620e 100644 --- a/test/mailers/previews/curation_mailer_preview.rb +++ b/test/mailers/previews/curation_mailer_preview.rb @@ -14,4 +14,9 @@ def events_need_approval provider = ContentProvider.first CurationMailer.events_require_approval(provider, Time.zone.now - 1.week) end + + def materials_need_approval + provider = ContentProvider.first + CurationMailer.materials_require_approval(provider, Time.zone.now - 1.week) + end end