sexy multipart emails pulled from the mailers and re-rendered by mailboxer
This commit is contained in:
parent
93af2ec84e
commit
f010bbe6c9
5 changed files with 32 additions and 17 deletions
|
@ -22,12 +22,10 @@ class AccessController < ApplicationController
|
||||||
request = AccessRequest.create(user: current_user, map: @map)
|
request = AccessRequest.create(user: current_user, map: @map)
|
||||||
# what about push notification to map owner?
|
# what about push notification to map owner?
|
||||||
mail = MapMailer.access_request_email(request, @map)
|
mail = MapMailer.access_request_email(request, @map)
|
||||||
@map.user.notify(mail.subject, mail.body.parts[1].body.to_s)
|
@map.user.notify(mail.subject, 'access request', request, true, MAILBOXER_CODE_ACCESS_REQUEST)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json { head :ok }
|
||||||
head :ok
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,14 +38,12 @@ class AccessController < ApplicationController
|
||||||
# who we then send an email to
|
# who we then send an email to
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
mail = MapMailer.invite_to_edit_email(@map, current_user, User.find(user_id))
|
mail = MapMailer.invite_to_edit_email(@map, current_user, User.find(user_id))
|
||||||
user.notify(mail.subject, mail.body.parts[1].body.to_s)
|
user.notify(mail.subject, 'invite to edit', @map, true, MAILBOXER_CODE_INVITED_TO_EDIT)
|
||||||
end
|
end
|
||||||
@map.remove_old_collaborators(user_ids)
|
@map.remove_old_collaborators(user_ids)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json { head :ok }
|
||||||
head :ok
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,4 +6,16 @@ class ApplicationMailer < ActionMailer::Base
|
||||||
def deliver
|
def deliver
|
||||||
raise NotImplementedError('Please use Mailboxer to send your emails.')
|
raise NotImplementedError('Please use Mailboxer to send your emails.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
def mail_for_notification(notification)
|
||||||
|
if notification.notification_code == MAILBOXER_CODE_ACCESS_REQUEST
|
||||||
|
request = notification.notified_object
|
||||||
|
MapMailer.access_request_email(request, request.map)
|
||||||
|
elsif notification.notification_code == MAILBOXER_CODE_INVITED_TO_EDIT
|
||||||
|
map = notification.notified_object
|
||||||
|
MapMailer.invite_to_edit_email(map, map.user, 'TODO invited user')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<% mail = ApplicationMailer.mail_for_notification(@notification) %>
|
||||||
<head>
|
<% @notification.update(body: mail.html_part&.body&.decoded) %>
|
||||||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
<%= raw mail.html_part&.body&.decoded %>
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<%= raw @notification.body %>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
<%= @notification.body.html_safe? ? @notification.body : strip_tags(@notification.body) %>
|
<% mail = ApplicationMailer.mail_for_notification(@notification) %>
|
||||||
|
<%= mail.text_part&.body&.decoded %>
|
||||||
|
|
|
@ -1,4 +1,15 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# notification codes to differentiate different types of notifications
|
||||||
|
# e.g. a notification might have {
|
||||||
|
# notified_object_type: 'Map',
|
||||||
|
# notified_object_id: 1,
|
||||||
|
# notification_code: MAILBOXER_CODE_ACCESS_REQUEST
|
||||||
|
# },
|
||||||
|
# which would imply that this is an access request to Map.find(1)
|
||||||
|
MAILBOXER_CODE_ACCESS_REQUEST = 'ACCESS_REQUEST'
|
||||||
|
MAILBOXER_CODE_INVITED_TO_EDIT = 'INVITED_TO_EDIT'
|
||||||
|
|
||||||
Mailboxer.setup do |config|
|
Mailboxer.setup do |config|
|
||||||
# Configures if your application uses or not email sending for Notifications and Messages
|
# Configures if your application uses or not email sending for Notifications and Messages
|
||||||
config.uses_emails = true
|
config.uses_emails = true
|
||||||
|
|
Loading…
Add table
Reference in a new issue