metamaps--metamaps/lib/tasks/emails.rake
Connor Turland b740fef8fe daily map activity emails (#1081)
* data prepared, task setup

* add the basics of the email template

* cover granular permissions

* unfollow this map

* break out permissions tests better

* rename so test runs
2017-03-06 22:42:22 -05:00

20 lines
714 B
Ruby

namespace :metamaps do
desc "delivers recent map activity digest emails to users"
task deliver_map_activity_emails: :environment do
summarize_map_activity
end
def summarize_map_activity
Follow.where(followed_type: 'Map').find_each do |follow|
map = follow.followed
user = follow.user
# add logging and rescue-ing
# and a notification of failure
next unless MapPolicy.new(user, map).show? # just in case the permission changed
next unless user.emails_allowed
summary_data = MapActivityService.summarize_data(map, user)
next if summary_data[:stats].blank?
MapActivityMailer.daily_summary(user, map, summary_data).deliver_later
end
end
end