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

🧹 [i1020] - ga4 follow up #2311

Merged
merged 6 commits into from
Sep 4, 2024
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 Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ GIT

GIT
remote: https://github.com/samvera/hyrax.git
revision: 69f0b81ff7bdbe5dff9620306ee542668ac86425
revision: e1160bbbb1b917640515f8db1f3ad3dcdc376c47
branch: main
specs:
hyrax (5.0.1)
Expand Down
4 changes: 2 additions & 2 deletions app/assets/stylesheets/hyku.scss
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ div#collapse-citations {
}

@media (min-width: 576px) {
.citations-button .download-pdf-button {
.citations-button .file_download {
max-width: 300px;
}
}
Expand Down Expand Up @@ -552,7 +552,7 @@ span.constraint-value p, .facet-values p {
}
}

#download-pdf-button {
#file_download {
margin: 10px 0 10px 0;
}

Expand Down
2 changes: 2 additions & 0 deletions app/jobs/depositor_email_notification_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def perform
statistics = user.statistics_for
next if statistics.nil?

next if statistics[:new_work_views].zero? && statistics[:new_file_downloads].zero?

HykuMailer.depositor_email(user, statistics, current_account).deliver_now
end
DepositorEmailNotificationJob.set(wait_until: (Time.zone.now + 1.month).beginning_of_month).perform_later
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/hyku_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def summary_email(user, messages, account)
@messages = messages || []
@account = account
@url = notifications_url_for(@account)
@application_name = account.sites.application_name
@application_name = account.sites.application_name || account.name.humanize

mail(to: @user.email,
subject: "You have #{@messages.count} new message(s) on #{@application_name}",
Expand All @@ -25,7 +25,7 @@ def depositor_email(user, statistics, account)
@statistics = statistics
@account = account
@url = dashboard_url_for(@account)
@application_name = account.sites.application_name
@application_name = account.sites.application_name || account.name.humanize

mail(to: @user.email,
subject: "Monthly Downloads Summary for #{@application_name}",
Expand Down
60 changes: 30 additions & 30 deletions app/views/hyku_mailer/depositor_email.html.erb
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<!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 <%= pluralize(@statistics[:new_file_downloads], 'download') %> in <%= Date.today.prev_month.strftime("%B %Y") %> across your <%= pluralize(@statistics[:new_work_views], 'work') %> in <%= @application_name %>. Your current readership:</p>
<ul>
<li><%= pluralize(@statistics[:total_file_downloads], 'Total File Download') %></li>
<li><%= pluralize(@statistics[:total_work_views], 'Total Work View') %></li>
</ul>
<a href="<%= @url %>" class="button">VISIT MY DASHBOARD</a>
<div class="footer">
<p>These monthly reports are provided to you on behalf of <%= @application_name %>. For questions, comments, or to add more content and increase your readership and visibility as an author, please contact your repository administrator.</p>
<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_file_downloads]} new files downloaded" %> in <%= Date.today.prev_month.strftime("%B %Y") %> and <%= "#{@statistics[:new_work_views]} new works viewed" %> in <%= @application_name %>. Your current readership:</p>
<ul>
<li><%= pluralize(@statistics[:total_file_downloads], 'Total File Download') %></li>
<li><%= pluralize(@statistics[:total_work_views], 'Total Work View') %></li>
</ul>
<a href="<%= @url %>" class="button">VISIT MY DASHBOARD</a>
<div class="footer">
<p>These monthly reports are provided to you on behalf of <%= @application_name %>. 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>
</div>
</body>
</body>
</html>
4 changes: 2 additions & 2 deletions app/views/hyrax/base/_download_pdf.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<div class="download-pdf-controls">
<% if @presenter.representative_presenter.present? && presenter.file_set_presenters.any?(&:pdf?) %>
<%= button_tag type: 'button',
id: "download-pdf-button",
id: "file_download",
data: { label: @presenter.representative_presenter.id,
path: hyrax.download_path(presenter.representative_presenter) },
class: "btn btn-success btn-block download-pdf-button center-block",
class: "btn btn-success btn-block file_download center-block",
onclick: "window.open(this.dataset.path, '_blank');" do %>
Download PDF
<% end %>
Expand Down
15 changes: 15 additions & 0 deletions spec/jobs/depositor_email_notification_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
end
end

context 'when the user has zero new counts in statistics' do
let(:statistics) { { new_file_downloads: 0, new_work_views: 0, total_file_downloads: 6, total_file_views: 7, total_work_views: 16 } }

before do
allow(User).to receive(:all).and_return([user])
allow(user).to receive(:statistics_for).and_return(statistics)
end

it 'does not send emails to users' do
switch!(account)
described_class.perform_now
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
end

context 'when the user has no new statistics' do
let(:statistics) { nil }

Expand Down
Loading