make notifications always work
This commit is contained in:
parent
87cb620d1b
commit
999414fffc
16 changed files with 103 additions and 42 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
26
app/services/notification_service.rb
Normal file
26
app/services/notification_service.rb
Normal 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
|
|
@ -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>
|
||||
|
|
8
app/views/map_mailer/access_approved_email.html.erb
Normal file
8
app/views/map_mailer/access_approved_email.html.erb
Normal 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 %>
|
4
app/views/map_mailer/access_approved_email.text.erb
Normal file
4
app/views/map_mailer/access_approved_email.text.erb
Normal 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) %>]
|
|
@ -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 %>
|
||||
|
|
|
@ -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) %>]
|
||||
|
||||
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -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) %>]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue