-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
boilerplate is WIP. template with sample email has been created at this point but needs to be dynamic. TODO: - understand UserStats and replace placeholder data - make email dynamic, including the date, tenant name, link to dashboard, etc - Do we want to make an option for the user to not receive emails? If so - we need UI work and possibly migrations. - specs
- Loading branch information
Shana Moore
committed
May 29, 2024
1 parent
ec7566e
commit 9898968
Showing
5 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style> | ||
body { font-family: Arial, sans-serif; line-height: 1.6; } | ||
.email-container { max-width: 600px; margin: auto; padding: 20px; border: 1px solid #ccc; } | ||
.footer { font-size: 12px; color: #666; margin-top: 20px; } | ||
.highlight { color: #0056b3; } | ||
.button { | ||
display: inline-block; | ||
padding: 10px 20px; | ||
margin: 10px 0; | ||
background-color: #0056b3; | ||
color: white; | ||
text-decoration: none; | ||
border-radius: 5px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="email-container"> | ||
<p>Dear Author,</p> | ||
<p>You had <%= @statistics[:new_downloads] %> new download in December 2023 across your <%= @statistics[:papers_count] %> papers in MUShare. Your current readership:</p> | ||
<ul> | ||
<li><%= @statistics[:total_downloads] %> Total Downloads</li> | ||
</ul> | ||
<a href="url" class="button">VISIT MY DASHBOARD</a> | ||
<div class="footer"> | ||
<p>These monthly reports are provided to you by bepress on behalf of MUShare. For questions, comments, or to add more content and increase your readership and visibility as an author, please contact your repository administrator.</p> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_literal: true | ||
|
||
class DepositorEmailNotificationJob < ApplicationJob | ||
non_tenant_job | ||
|
||
after_perform do |job| | ||
reenqueue(job.arguments.first) | ||
end | ||
|
||
def perform(account) | ||
Apartment::Tenant.switch(account.tenant) do | ||
stats_period = (Date.today - 1.month).beginning_of_month..(Date.today - 1.month).end_of_month | ||
users = User.all | ||
|
||
users.each do |user| | ||
statistics = gather_statistics_for(user, stats_period) | ||
next if statistics.nil? | ||
|
||
HykuMailer.depositor_email(user, statistics, account).deliver_now | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def reenqueue(account) | ||
DepositorEmailNotificationJob.set(wait_until: Date.next_month.beginning_of_month).perform_later(account) | ||
end | ||
|
||
def gather_statistics_for(user, stats_period) | ||
# Dummy statistics - replace with actual logic to calculate view and download counts. | ||
# users.stats could be useful: https://github.com/samvera/hyrax/blob/4d2c654a8b9f144b35a6e013b31f80cb4cf47aeb/app/models/concerns/hyrax/user_usage_stats.rb#L3 | ||
# there's also this: https://github.com/samvera/hyrax/blob/main/app/presenters/hyrax/file_usage.rb | ||
# Fetching statistics for the previous month | ||
last_month_stats = user.stats.where(date: stats_period) | ||
|
||
return nil if last_month_stats.empty? | ||
|
||
{ | ||
new_file_downloads: last_month_stats.sum(:file_downloads), | ||
new_work_views: last_month_stats.sum(:work_views), | ||
total_file_views: user.total_file_views, | ||
total_file_downloads: user.total_file_downloads, | ||
total_work_views: user.total_work_views | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters