Skip to content

Commit

Permalink
rename event curation email to content curation email
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesndrs committed Dec 2, 2024
1 parent 8d798c6 commit 9b7afbf
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 18 deletions.
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
8 changes: 4 additions & 4 deletions app/mailers/curation_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +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.event_curation_email.present?
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.event_curation_email) do |format|
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
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
2 changes: 1 addition & 1 deletion lib/tasks/tess.rake
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ 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
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: contact@goblet.org
event_curation_email: curation@goblet.org
content_curation_email: curation@goblet.org

iann:
title: iAnn
Expand Down
16 changes: 8 additions & 8 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,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
Expand All @@ -147,7 +147,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 materials on #{TeSS::Config.site['title_short']}", email.subject

text_body = email.text_part.body.to_s
Expand All @@ -171,7 +171,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 materials on #{TeSS::Config.site['title_short']}", email.subject

[email.text_part, email.html_part].each do |part|
Expand All @@ -182,8 +182,8 @@ class CurationMailerTest < ActionMailer::TestCase
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.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.materials_require_approval(@content_provider, @materials.pluck(:created_at).min - 1.week)

assert_emails count do
Expand Down

0 comments on commit 9b7afbf

Please sign in to comment.