diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index aa919edb..383ab080 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true class NotificationService + # for strip_tags + include ActionView::Helpers::SanitizeHelper + def self.renderer renderer ||= ApplicationController.renderer.new( http_host: ENV['MAILER_DEFAULT_URL'], @@ -14,7 +17,7 @@ class NotificationService 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, true, request.map.user) + request.user.notify(request.approved_text, body, request, false, MAILBOXER_CODE_ACCESS_APPROVED, true, request.map.user) end 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) 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) if notification.notification_code == MAILBOXER_CODE_ACCESS_REQUEST map = notification.notified_object.map @@ -33,6 +47,8 @@ class NotificationService elsif notification.notification_code == MAILBOXER_CODE_INVITE_TO_EDIT map = notification.notified_object.map 'gave you edit access to map ' + map.name + '' + elsif notification.notification_code == MAILBOXER_CODE_MESSAGE_FROM_DEVS + notification.subject end end end diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index 6f66eccd..f27c1fef 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -7,7 +7,8 @@

Notifications