Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

material curation mail #1049

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/content_providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
16 changes: 14 additions & 2 deletions app/mailers/curation_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_providers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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' %>
Expand Down
23 changes: 23 additions & 0 deletions app/views/curation_mailer/materials_require_approval.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<p>
You are receiving this automated email because you are a curator of <%= @provider.title %> on <%= TeSS::Config.site['title_short'] %>.
</p>
<% if @materials.count.positive? %>
<p>
If any of these materials are incorrect or should not be shown, please follow the link to change them.<br/>
If a material should not be shown, disable it on the edit page instead of deleting it to prevent rescraping.<br/>
If a material needs changes, lock the changed fields to prevent your changes from being overwritten by the scraper.<br/>
</p>

<% @materials.each do |material| %>
<p>
<%= link_to material.title, material %><br/>
<strong>description:</strong> <%= material.description %><br/>
<strong>show:</strong> <%= material.visible %><br/>
</p>

<% end %>
<% else %>
<p>
There were no new materials this week.
</p>
<% end %>
17 changes: 17 additions & 0 deletions app/views/curation_mailer/materials_require_approval.text.erb
Original file line number Diff line number Diff line change
@@ -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 %>


2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241202092029_rename_event_curation_email.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameEventCurationEmail < ActiveRecord::Migration[7.0]
def change
rename_column :content_providers, :event_curation_email, :content_curation_email
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion lib/tasks/tess.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/content_providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ goblet:
node: good
content_provider_type: Portal
contact: [email protected]
event_curation_email: [email protected]
content_curation_email: [email protected]

iann:
title: iAnn
Expand Down
63 changes: 59 additions & 4 deletions test/mailers/curation_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand All @@ -127,13 +127,68 @@ 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
email.deliver_now
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
5 changes: 5 additions & 0 deletions test/mailers/previews/curation_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading