Skip to content

Commit

Permalink
[#164082119] fix batch user emails
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Glick committed Mar 29, 2019
1 parent 4f9a692 commit c6f189e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
6 changes: 2 additions & 4 deletions app/mailers/user_mailer.rb
Expand Up @@ -21,16 +21,14 @@
class UserMailer < ActionMailer::Base
default :from => Setting.get_value("no_reply_from")

def authorized_user_changed(protocol, recipients, modified_roles, action)
def authorized_user_changed(protocol, recipient, modified_roles, action)
@protocol = protocol
@modified_roles = modified_roles
@action = action
@protocol_link = dashboard_protocol_url(@protocol)
@service_request = @protocol.service_requests.first

recipients.each do |recipient|
send_email(recipient, t('mailer.email_title.general', email_status: "Authorized Users Update", type: "Protocol", id: @protocol.id))
end
send_email(recipient, t('mailer.email_title.general', email_status: "Authorized Users Update", type: "Protocol", id: @protocol.id))
end

def notification_received(user, ssr)
Expand Down
43 changes: 43 additions & 0 deletions app/models/modified_role.rb
@@ -0,0 +1,43 @@
# Copyright © 2011-2019 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.

# This is a wrapper structure to hold Project Role information
# to avoid persistence issues within delayed jobs

class ModifiedRole

attr_accessor *ProjectRole.column_names

def initialize(project_role_attrs)
project_role_attrs.each{ |attr, value| instance_variable_set("@#{attr}", value) }
end

def identity
Identity.find(@identity_id)
end

def display_rights
case project_rights
when "none" then "Member Only"
when "view" then "View Rights"
when "approve" then "Authorize/Change Study Charges"
end
end
end
5 changes: 3 additions & 2 deletions app/models/protocol.rb
Expand Up @@ -402,9 +402,10 @@ def email_about_change_in_authorized_user(modified_roles, action)
# For example: if a SR has SSRs all with a status of 'draft', don't send emails

if Setting.get_value("send_authorized_user_emails") && self.service_requests.any?(&:previously_submitted?)
alert_users = Identity.where(id: (self.emailed_associated_users + modified_roles.reject{ |pr| pr.project_rights == 'none' }).map(&:identity_id))
alert_users = Identity.where(id: (self.emailed_associated_users + modified_roles.reject{ |pr| pr.project_rights == 'none' }).map(&:identity_id))
modified_roles = modified_roles.map{ |pr| ModifiedRole.new(pr.attributes) }

UserMailer.authorized_user_changed(self, alert_users, modified_roles, action).deliver
alert_users.each{ |u| UserMailer.delay.authorized_user_changed(self, u, modified_roles, action) }
end
end

Expand Down

0 comments on commit c6f189e

Please sign in to comment.