helper function and notification setup for messages from the devs to be sent to all users (#1064)
* message from devs notification type * helper function for messages from devs * don't use find_by_email * temporary fix
This commit is contained in:
parent
575a3ec8bf
commit
3706cd83e7
3 changed files with 21 additions and 3 deletions
|
@ -1,5 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class NotificationService
|
class NotificationService
|
||||||
|
# for strip_tags
|
||||||
|
include ActionView::Helpers::SanitizeHelper
|
||||||
|
|
||||||
def self.renderer
|
def self.renderer
|
||||||
renderer ||= ApplicationController.renderer.new(
|
renderer ||= ApplicationController.renderer.new(
|
||||||
http_host: ENV['MAILER_DEFAULT_URL'],
|
http_host: ENV['MAILER_DEFAULT_URL'],
|
||||||
|
@ -14,7 +17,7 @@ class NotificationService
|
||||||
|
|
||||||
def self.access_approved(request)
|
def self.access_approved(request)
|
||||||
body = renderer.render(template: 'map_mailer/access_approved_email', locals: { map: request.map }, layout: false)
|
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, true, request.map.user)
|
request.user.notify(request.approved_text, body, request, false, MAILBOXER_CODE_ACCESS_APPROVED, true, request.map.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.invite_to_edit(map, inviter, invited)
|
def self.invite_to_edit(map, inviter, invited)
|
||||||
|
@ -23,6 +26,17 @@ class NotificationService
|
||||||
invited.notify(map.invited_text, body, user_map, false, MAILBOXER_CODE_INVITE_TO_EDIT, true, inviter)
|
invited.notify(map.invited_text, body, user_map, false, MAILBOXER_CODE_INVITE_TO_EDIT, true, inviter)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# note: this is a global function, probaobly called from the rails console with some html body
|
||||||
|
def self.message_from_devs(subject, body, opts = {})
|
||||||
|
users = opts[:users] || User.all
|
||||||
|
obj = opts[:obj] || nil
|
||||||
|
sanitize_text = opts[:sanitize_text] || false
|
||||||
|
notification_code = opts[:notification_code] || MAILBOXER_CODE_MESSAGE_FROM_DEVS
|
||||||
|
send_mail = opts[:send_mail] || true
|
||||||
|
sender = opts[:sender] || User.find_by(email: 'ishanshapiro@gmail.com')
|
||||||
|
Mailboxer::Notification.notify_all(users, subject, body, obj, sanitize_text, notification_code, send_mail, sender)
|
||||||
|
end
|
||||||
|
|
||||||
def self.text_for_notification(notification)
|
def self.text_for_notification(notification)
|
||||||
if notification.notification_code == MAILBOXER_CODE_ACCESS_REQUEST
|
if notification.notification_code == MAILBOXER_CODE_ACCESS_REQUEST
|
||||||
map = notification.notified_object.map
|
map = notification.notified_object.map
|
||||||
|
@ -33,6 +47,8 @@ class NotificationService
|
||||||
elsif notification.notification_code == MAILBOXER_CODE_INVITE_TO_EDIT
|
elsif notification.notification_code == MAILBOXER_CODE_INVITE_TO_EDIT
|
||||||
map = notification.notified_object.map
|
map = notification.notified_object.map
|
||||||
'gave you edit access to map <span class="in-bold">' + map.name + '</span>'
|
'gave you edit access to map <span class="in-bold">' + map.name + '</span>'
|
||||||
|
elsif notification.notification_code == MAILBOXER_CODE_MESSAGE_FROM_DEVS
|
||||||
|
notification.subject
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
<h2 class="title">Notifications</h4>
|
<h2 class="title">Notifications</h4>
|
||||||
</header>
|
</header>
|
||||||
<ul class="notifications">
|
<ul class="notifications">
|
||||||
<% @notifications.each do |notification| %>
|
<% notifications = @notifications.to_a.delete_if{|n| n.notified_object.nil? || n.notified_object.map.nil? }%>
|
||||||
|
<% notifications.each do |notification| %>
|
||||||
<% receipt = @receipts.find_by(notification_id: notification.id) %>
|
<% receipt = @receipts.find_by(notification_id: notification.id) %>
|
||||||
<li class="notification <%= receipt.is_read? ? 'read' : 'unread' %>" id="notification-<%= notification.id %>">
|
<li class="notification <%= receipt.is_read? ? 'read' : 'unread' %>" id="notification-<%= notification.id %>">
|
||||||
<%= link_to notification_path(notification.id) do %>
|
<%= link_to notification_path(notification.id) do %>
|
||||||
|
@ -32,7 +33,7 @@
|
||||||
<div class="clearfloat"></div>
|
<div class="clearfloat"></div>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if @notifications.count == 0 %>
|
<% if notifications.count == 0 %>
|
||||||
<div class="emptyInbox">
|
<div class="emptyInbox">
|
||||||
You have no notifications. More time for dancing.
|
You have no notifications. More time for dancing.
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
MAILBOXER_CODE_ACCESS_REQUEST = 'ACCESS_REQUEST'
|
MAILBOXER_CODE_ACCESS_REQUEST = 'ACCESS_REQUEST'
|
||||||
MAILBOXER_CODE_ACCESS_APPROVED = 'ACCESS_APPROVED'
|
MAILBOXER_CODE_ACCESS_APPROVED = 'ACCESS_APPROVED'
|
||||||
MAILBOXER_CODE_INVITE_TO_EDIT = 'INVITE_TO_EDIT'
|
MAILBOXER_CODE_INVITE_TO_EDIT = 'INVITE_TO_EDIT'
|
||||||
|
MAILBOXER_CODE_MESSAGE_FROM_DEVS = 'MESSAGE_FROM_DEVS'
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue