Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRY - Notification email linking to notification message #2907

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/controllers/dashboard/messages_controller.rb
Expand Up @@ -27,7 +27,11 @@ def index
@messages = @notification.messages
@message = Message.new(notification: @notification, sender: current_user, recipient: recipient)

respond_to :js
# respond_to :js
respond_to do |format|
format.js
format.html
end
end

def new
Expand All @@ -45,7 +49,7 @@ def create
if @message.save
recipient = @message.recipient
@notification.set_read_by(recipient, false)
UserMailer.notification_received(recipient, @notification.sub_service_request, current_user).deliver unless recipient.email.blank?
UserMailer.notification_received(recipient, @notification.sub_service_request, current_user, @notification).deliver unless recipient.email.blank?

@messages = @notification.messages
@message = Message.new(notification: @notification, sender: current_user, recipient: recipient)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/dashboard/notifications_controller.rb
Expand Up @@ -69,7 +69,7 @@ def create
ssr = @notification.sub_service_request
@notifications = Notification.belonging_to(current_user, params[:sub_service_request_id])

UserMailer.notification_received(@recipient, ssr, current_user).deliver unless @recipient.email.blank?
UserMailer.notification_received(@recipient, ssr, current_user, @notification).deliver unless @recipient.email.blank?
flash[:success] = 'Notification Sent!'
else
@errors = @message.errors
Expand Down
3 changes: 2 additions & 1 deletion app/mailers/user_mailer.rb
Expand Up @@ -32,13 +32,14 @@ def authorized_user_changed(protocol, recipient, modified_roles, action)
t('mailer.email_title.general', email_status: "Authorized Users Update", type: "Protocol", id: @protocol.id))
end

def notification_received(user, ssr, sender)
def notification_received(user, ssr, sender, notification)
@sender_name = sender.full_name

if ssr.present?
@ssr_id = ssr.id
@protocol_id = ssr.protocol_id
@is_service_provider = user.is_service_provider?(ssr)
@notification = notification

send_email(user,
"#{t(:mailer)[:email_title][:new]} #{t('mailer.email_title.general_dashboard', email_status: Notification.model_name.human, type: Protocol.model_name.human, id: ssr.protocol.id)}")
Expand Down
21 changes: 21 additions & 0 deletions app/views/dashboard/messages/index.html.haml
@@ -0,0 +1,21 @@
-# Copyright © 2011-2020 MUSC Foundation for Research Development
-# All rights reserved.

-# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

-# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

-# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
-# disclaimer in the documentation and/or other materials provided with the distribution.

-# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
-# derived from this software without specific prior written permission.

-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
-# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

= render "dashboard/messages/index", messages: @messages, message: @message, notification: @notification
2 changes: 1 addition & 1 deletion app/views/user_mailer/notification_received.html.haml
Expand Up @@ -18,5 +18,5 @@
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

- link = @is_service_provider == 'true' ? dashboard_sub_service_request_url(@ssr_id) : dashboard_notifications_url
- link = @is_service_provider == 'true' ? dashboard_sub_service_request_url(@ssr_id) : dashboard_messages_url(notification_id: @notification.id)
= t('mailer.received', link: link, protocol_id: @protocol_id, sender_name: @sender_name).html_safe