Permalink
Browse files

Resolve archivesunleashed#31; Setup mailer.

- all three background jobs now send out an email when finished
- stub email views have been created (html/text)
- updated figaro config example
- update rubocop config
  • Loading branch information...
ruebot committed Mar 10, 2018
1 parent a6913dd commit f95101a67d42cae2e945d6411d87c1dbd5777685
@@ -24,6 +24,8 @@ Metrics/BlockLength:
- app/jobs/collections_spark_job.rb
- app/jobs/wasapi_files_download_job.rb
- app/jobs/wasapi_files_populate_job.rb
- config/environments/development.rb
- config/environments/production.rb

Metrics/MethodLength:
Exclude:
@@ -5,8 +5,9 @@ class CollectionsSparkJob < ApplicationJob
queue_as :default
require 'open-uri'

def after_perform
UserMailer.notify_collection_downloaded(something)
after_perform do |job|
UserMailer.notify_collection_analyzed(job.arguments.first.id).deliver_now
logger.info 'Email sent to: ' + job.arguments.first.email.to_s
end

def perform(user_id, collection_id)
@@ -5,8 +5,9 @@ class WasapiFilesDownloadJob < ApplicationJob
queue_as :default
require 'open-uri'

def after_perform
UserMailer.notify_collection_downloaded(something)
after_perform do |job|
UserMailer.notify_collection_downloaded(job.arguments.first.id).deliver_now
logger.info 'Email sent to: ' + job.arguments.first.email.to_s
end

def perform(user_id, collection_id)
@@ -8,8 +8,9 @@ class WasapiFilesPopulateJob < ApplicationJob
WASAPI_BASE_URL = 'https://partner.archive-it.org/wasapi/v1/webdata'
AI_COLLECTION_API_URL = 'https://partner.archive-it.org/api/collection/'

def after_perform
UserMailer.notify_collection_setup(something)
after_perform do |job|
UserMailer.notify_collection_setup(job.arguments.first.id).deliver_now
logger.info 'Email sent to: ' + job.arguments.first.email.to_s
end

def perform(user)
@@ -2,6 +2,6 @@

# Application mailer methods.
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
default from: 'hist-arc@uwaterloo.ca'
layout 'mailer'
end
@@ -2,5 +2,27 @@

# Methods for User Mailer
class UserMailer < ApplicationMailer
default from: 'notifications@archivesunleashed.org'
def notify_collection_analyzed(user_id)
@user = User.find(user_id)
mail(to: @user.email, subject: 'Collection is analyzed') do |format|
format.text
format.html
end
end

def notify_collection_downloaded(user_id)
@user = User.find(user_id)
mail(to: @user.email, subject: 'Collection is downloaded') do |format|
format.text
format.html
end
end

def notify_collection_setup(user_id)
@user = User.find(user_id)
mail(to: @user.email, subject: 'Collections are setup') do |format|
format.text
format.html
end
end
end
@@ -3,7 +3,7 @@
<%= render "layouts/sidebar" %>
<main class="col-sm-9 col-md-10">
<h1><%= @collection.title %></h1>
<p><%= button_to("Analyze Collection", user_collection_download_path(@user, @collection), data: {confirm: "Download and analyze" + collection_size(@collection.id, @user) + "?"}, class: 'btn btn-primary btn-lg btn-block') %></p>
<p><%= button_to("Analyze Collection", user_collection_download_path(@user, @collection), data: {confirm: "Download and analyze " + collection_size(@collection.id, @user) + "?"}, class: 'btn btn-primary btn-lg btn-block') %></p>
<%= link_to 'Back', current_user %>
<% unless display_domains(@user.id, @collection.id, @collection.account).blank? %>
<h2>Hyperlink Diagram</h2>
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Hi, <%= @user.name %></h1>
<p>
Your Archives Unleashed Cloud job has finished,
and is available at: http://cloud.archivesunleashed.org.<br>
</p>
<p>Thanks for using the Archives Unleashed Cloud, and have a great day!</p>
</body>
</html>
@@ -0,0 +1,7 @@
Hi, <%= @user.name %>
===============================================

Your Archives Unleashed Cloud job has finished,
and is available at: http://cloud.archivesunleashed.org.

Thanks for using the Archives Unleashed Cloud, and have a great day!
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Hi, <%= @user.name %></h1>
<p>
Your Archives Unleashed Cloud collection is downloaded,
and analysis will now begin. Look out for another email from us soon!<br>
</p>
<p>Thanks for using the Archives Unleashed Cloud, and have a great day!</p>
</body>
</html>
@@ -0,0 +1,7 @@
Hi, <%= @user.name %>
===============================================

Your Archives Unleashed Cloud collection is downloaded,
and analysis will now begin. Look out for another email from us soon!

Thanks for using the Archives Unleashed Cloud, and have a great day!
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Hi, <%= @user.name %></h1>
<p>
Your Archives Unleashed Cloud collections are now setup,
and are available at: http://cloud.archivesunleashed.org.<br>
</p>
<p>Thanks for using the Archives Unleashed Cloud, and have a great day!</p>
</body>
</html>
@@ -0,0 +1,7 @@
Hi, <%= @user.name %>
===============================================

Your Archives Unleashed Cloud collections are setup,
and are available at: http://cloud.archivesunleashed.org.

Thanks for using the Archives Unleashed Cloud, and have a great day!
@@ -22,5 +22,9 @@ aut_version: 0.12.2

production:
SECRET_KEY_BASE: some secret key base
postgres_username: username
postgres_password: password
PG_USER: username
PG_PASSWORD: password
EMAIL_SERVER_NAME: smtp.something.ca
EMAIL_DOMAIN: something.ca
EMAIL_USERNAME: someuser
EMAIL_PASSWORD: somepassword
@@ -34,6 +34,17 @@

config.action_mailer.perform_caching = false

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: ENV['EMAIL_SERVER_NAME'],
port: 587,
domain: ENV['EMAIL_DOMAIN'],
user_name: ENV['EMAIL_USERNAME'],
password: ENV['EMAIL_PASSWORD'],
authentication: 'plain',
enable_starttls_auto: true
}

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

@@ -68,6 +68,16 @@
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "auk_#{Rails.env}"
config.action_mailer.perform_caching = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: ENV['EMAIL_SERVER_NAME'],
port: 587,
domain: ENV['EMAIL_DOMAIN'],
user_name: ENV['EMAIL_USERNAME'],
password: ENV['EMAIL_PASSWORD'],
authentication: 'plain',
enable_starttls_auto: true
}

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to

0 comments on commit f95101a

Please sign in to comment.