Fix mailboxer + email bugs

This commit is contained in:
Connor Turland 2016-12-13 02:42:33 -05:00 committed by Devin Howard
parent 6d8392d2e7
commit 87228c27c1
25 changed files with 120 additions and 52 deletions

View file

@ -240,8 +240,9 @@
position: relative;
.unread-notifications-dot {
top: 17px;
top: 50%;
left: 0px;
margin-top: -4px;
}
}
}

View file

@ -44,6 +44,10 @@ $unread_notifications_dot_size: 8px;
margin-bottom: 0;
}
.emptyInbox {
padding-top: 15px;
}
.notification:first-child {
border-top: none;
}

View file

@ -20,9 +20,7 @@ class AccessController < ApplicationController
# POST maps/:id/access_request
def access_request
request = AccessRequest.create(user: current_user, map: @map)
# what about push notification to map owner?
mail = MapMailer.access_request_email(request, @map)
@map.user.notify(mail.subject, 'access request', request, true, MAILBOXER_CODE_ACCESS_REQUEST)
NotificationService.access_request(request)
respond_to do |format|
format.json { head :ok }
@ -35,12 +33,9 @@ class AccessController < ApplicationController
@map.add_new_collaborators(user_ids).each do |user_id|
# add_new_collaborators returns array of added users,
# who we then send an email to
# who we then send a notification to
user = User.find(user_id)
mail = MapMailer.invite_to_edit_email(@map, current_user, user)
user.notify(mail.subject, 'invite to edit',
UserMap.find_by(user: user, map: @map),
true, MAILBOXER_CODE_INVITED_TO_EDIT)
NotificationService.invite_to_edit(@map, current_user, user)
end
@map.remove_old_collaborators(user_ids)

View file

@ -11,8 +11,11 @@ class ApplicationMailer < ActionMailer::Base
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
MapMailer.access_request_email(request)
elsif notification.notification_code == MAILBOXER_CODE_ACCESS_APPROVED
request = notification.notified_object
MapMailer.access_approved_email(request)
elsif notification.notification_code == MAILBOXER_CODE_INVITE_TO_EDIT
user_map = notification.notified_object
MapMailer.invite_to_edit_email(user_map.map, user_map.map.user, user_map.user)
end

View file

@ -2,17 +2,21 @@
class MapMailer < ApplicationMailer
default from: 'team@metamaps.cc'
def access_request_email(request, map)
def access_request_email(request)
@request = request
@map = map
subject = @map.name + ' - request to edit'
mail(to: @map.user.email, subject: subject)
@map = request.map
mail(to: @map.user.email, subject: request.requested_text)
end
def access_approved_email(request)
@request = request
@map = request.map
mail(to: request.user, subject: request.approved_text)
end
def invite_to_edit_email(map, inviter, invitee)
@inviter = inviter
@map = map
subject = @map.name + ' - invitation to edit'
mail(to: invitee.email, subject: subject)
mail(to: invitee.email, subject: map.invited_text)
end
end

View file

@ -12,8 +12,7 @@ class AccessRequest < ApplicationRecord
end
user_map = UserMap.create(user: user, map: map)
mail = MapMailer.invite_to_edit_email(map, map.user, user)
user.notify(mail.subject, 'invite to edit', user_map, true, MAILBOXER_CODE_INVITED_TO_EDIT)
NotificationService.access_approved(self)
end
def deny
@ -25,4 +24,12 @@ class AccessRequest < ApplicationRecord
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
end
end
def requested_text
self.map.name + ' - request to edit'
end
def approved_text
self.map.name + ' - access approved'
end
end

View file

@ -123,4 +123,8 @@ class Map < ApplicationRecord
Topic.where(defer_to_map_id: id).update_all(permission: permission)
Synapse.where(defer_to_map_id: id).update_all(permission: permission)
end
def invited_text
self.name + ' - invited to edit'
end
end

View file

@ -0,0 +1,26 @@
# frozen_string_literal: true
class NotificationService
def self.renderer
renderer ||= ApplicationController.renderer.new(
http_host: ENV['MAILER_DEFAULT_URL'],
https: Rails.env.production? ? true : false
)
end
def self.access_request(request)
body = renderer.render(template: 'map_mailer/access_request_email', locals: { map: request.map, request: request }, layout: false)
request.map.user.notify(request.requested_text, body, request, false, MAILBOXER_CODE_ACCESS_REQUEST)
end
def self.access_approved(request)
body = renderer.render(template: 'map_mailer/access_approved_email', locals: { map: request.map }, layout: false)
receipt = request.user.notify(request.approved_text, body, request, false, MAILBOXER_CODE_ACCESS_APPROVED)
end
def self.invite_to_edit(map, inviter, invited)
user_map = UserMap.find_by(user: invited, map: map)
body = renderer.render(template: 'map_mailer/invite_to_edit_email', locals: { map: map, inviter: inviter }, layout: false)
invited.notify(map.invited_text, body, user_map, false, MAILBOXER_CODE_INVITE_TO_EDIT)
end
end

View file

@ -33,6 +33,6 @@
<% end %>
</main>
</div>
<%= render partial: 'shared/back_to_mapping' %>
<%= render partial: 'shared/go_to_maps' %>
</div>
<%= render 'script' %>

View file

@ -1,10 +1,6 @@
<!DOCTYPE html>
<% mail = ApplicationMailer.mail_for_notification(@notification) %>
<div style="padding: 16px; background: white; text-align: left;">
<% if mail %>
<% @notification.update(body: mail.html_part&.body&.decoded) %>
<%= raw mail.html_part&.body&.decoded %>
<% end %>
<%= raw @notification.body %>
<p style="font-size: 12px;">Make sense with Metamaps</p>
<%= render partial: 'shared/mailer_unsubscribe_link' %>
</div>

View file

@ -0,0 +1,8 @@
<% map = @map || map %>
<% button_style = "background-color:#4fc059;border-radius:2px;color:white;display:inline-block;font-family:Roboto,Arial,Helvetica,sans-serif;font-size:12px;font-weight:bold;min-height:29px;line-height:29px;min-width:54px;outline:0px;padding:0 8px;text-align:center;text-decoration:none" %>
<p><span style="font-weight: bold;"><%= map.user.name %></span> has responded to your access request and invited you to <span style="font-weight: bold">collaboratively edit</span> the following map:</p>
<p><%= link_to map.name, map_url(map), style: "font-size: 18px; text-decoration: none; color: #4fc059;" %></p>
<% if map.desc %>
<p style="font-size: 12px;"><%= map.desc %></p>
<% end %>
<%= link_to 'Go to Map', map_url(map), style: button_style %>

View file

@ -0,0 +1,4 @@
<% map = @map || map %>
<%= map.user.name %> has responded to your access request and invited you to collaboratively edit the following map:
<%= map.name %> [<%= map_url(map) %>]

View file

@ -1,6 +1,8 @@
<% map = @map || map %>
<% request = @request || request %>
<% button_style = "background-color:#4fc059;border-radius:2px;color:white;display:inline-block;font-family:Roboto,Arial,Helvetica,sans-serif;font-size:12px;font-weight:bold;min-height:29px;line-height:29px;min-width:54px;outline:0px;padding:0 8px;text-align:center;text-decoration:none" %>
<p><span style="font-weight: bold;"><%= @request.user.name %></span> is requesting access to <span style="font-weight: bold">collaboratively edit</span> the following map:</p>
<p><%= @map.name %></p>
<p><%= link_to "Allow", approve_access_map_url(id: @map.id, request_id: @request.id), style: "font-size: 18px; text-decoration: none; color: #4fc059;" %>
<p><%= link_to "Decline", deny_access_map_url(id: @map.id, request_id: @request.id), style: "font-size: 18px; text-decoration: none; color: #DB5D5D;" %></p>
<%= link_to 'Go to Map', map_url(@map), style: button_style %>
<p><span style="font-weight: bold;"><%= request.user.name %></span> is requesting access to <span style="font-weight: bold">collaboratively edit</span> the following map:</p>
<p><%= map.name %></p>
<p><%= link_to "Allow", approve_access_map_url(id: map.id, request_id: request.id), style: "font-size: 18px; text-decoration: none; color: #4fc059;" %>
<p><%= link_to "Decline", deny_access_map_url(id: map.id, request_id: request.id), style: "font-size: 18px; text-decoration: none; color: #DB5D5D;" %></p>
<%= link_to 'Go to Map', map_url(map), style: button_style %>

View file

@ -1,8 +1,10 @@
<%= @request.user.name %> has requested to collaboratively edit the following map:
<% map = @map || map %>
<% request = @request || request %>
<%= request.user.name %> has requested to collaboratively edit the following map:
<%= @map.name %> [<%= map_url(@map) %>]
<%= map.name %> [<%= map_url(map) %>]
Allow [<%= approve_access_map_url(id: @map.id, request_id: @request.id) %>]
Decline [<%= deny_access_map_url(id: @map.id, request_id: @request.id) %>]
Allow [<%= approve_access_map_url(id: map.id, request_id: request.id) %>]
Decline [<%= deny_access_map_url(id: map.id, request_id: request.id) %>]

View file

@ -1,7 +1,9 @@
<% map = @map || map %>
<% inviter = @inviter || inviter %>
<% button_style = "background-color:#4fc059;border-radius:2px;color:white;display:inline-block;font-family:Roboto,Arial,Helvetica,sans-serif;font-size:12px;font-weight:bold;min-height:29px;line-height:29px;min-width:54px;outline:0px;padding:0 8px;text-align:center;text-decoration:none" %>
<p><span style="font-weight: bold;"><%= @inviter.name %></span> has invited you to <span style="font-weight: bold">collaboratively edit</span> the following map:</p>
<p><%= link_to @map.name, map_url(@map), style: "font-size: 18px; text-decoration: none; color: #4fc059;" %></p>
<% if @map.desc %>
<p style="font-size: 12px;"><%= @map.desc %></p>
<p><span style="font-weight: bold;"><%= inviter.name %></span> has invited you to <span style="font-weight: bold">collaboratively edit</span> the following map:</p>
<p><%= link_to map.name, map_url(map), style: "font-size: 18px; text-decoration: none; color: #4fc059;" %></p>
<% if map.desc %>
<p style="font-size: 12px;"><%= map.desc %></p>
<% end %>
<%= link_to 'Go to Map', map_url(@map), style: button_style %>
<%= link_to 'Go to Map', map_url(map), style: button_style %>

View file

@ -1,3 +1,5 @@
<%= @inviter.name %> has invited you to collaboratively edit the following map:
<% map = @map || map %>
<% inviter = @inviter || inviter %>
<%= inviter.name %> has invited you to collaboratively edit the following map:
<%= @map.name %> [<%= map_url(@map) %>]
<%= map.name %> [<%= map_url(map) %>]

View file

@ -29,7 +29,9 @@
</li>
<% end %>
<% if @notifications.count == 0 %>
You have ZERO unread notifications. Huzzah!
<div class="emptyInbox">
You have ZERO unread notifications. Huzzah!
</div>
<% end %>
</ul>
</div>
@ -40,7 +42,7 @@
</div>
<% end %>
<%= render partial: 'shared/back_to_mapping' %>
<%= render partial: 'shared/go_to_maps' %>
</div>
<%= render partial: 'notifications/header' %>

View file

@ -13,7 +13,7 @@
<%= link_to 'Back to notifications', notifications_path %>
</div>
<%= render partial: 'shared/back_to_mapping' %>
<%= render partial: 'shared/go_to_maps' %>
</div>
<%= render partial: 'notifications/header' %>

View file

@ -1,3 +0,0 @@
<div class="centerContent withPadding back-to-mapping">
<a href="/">Back to mapping</a>
</div>

View file

@ -0,0 +1,3 @@
<div class="centerContent withPadding">
<a href="/">Go to maps</a>
</div>

View file

@ -1,3 +1,3 @@
<div class="unsubscribe-link">
<%= link_to 'Click here to unsubscribe from all Metamaps emails', unsubscribe_notifications_url %>
<%= link_to 'Click here to unsubscribe from all Metamaps emails', unsubscribe_notifications_url(protocol: Rails.env.production? ? :https : :http) %>
</div>

View file

@ -2,4 +2,4 @@
You can unsubscribe from all Metamaps emails by visiting the following link:
<%= unsubscribe_notifications_url %>
<%= unsubscribe_notifications_url(protocol: Rails.env.production? ? :https : :http) %>

View file

@ -8,7 +8,8 @@
# },
# 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_CODE_ACCESS_APPROVED = 'ACCESS_APPROVED'
MAILBOXER_CODE_INVITE_TO_EDIT = 'INVITE_TO_EDIT'
Mailboxer.setup do |config|
# Configures if your application uses or not email sending for Notifications and Messages

View file

@ -264,7 +264,7 @@ const InfoBox = {
var mapperIds = DataModel.Collaborators.models.map(function(mapper) { return mapper.id })
$.post('/maps/' + Active.Map.id + '/access', { access: mapperIds })
var name = DataModel.Collaborators.get(newCollaboratorId).get('name')
GlobalUI.notifyUser(name + ' will be notified by email')
GlobalUI.notifyUser(name + ' will be notified')
self.updateNumbers()
}

View file

@ -7,6 +7,11 @@ class MapMailerPreview < ActionMailer::Preview
def access_request_email
request = AccessRequest.first
MapMailer.access_request_email(request, request.map)
MapMailer.access_request_email(request)
end
def access_approved_email
request = AccessRequest.first
MapMailer.access_approved_email(request)
end
end