-
Notifications
You must be signed in to change notification settings - Fork 118
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
Fix VM Migrate complete email when To field is nil. #177
Fix VM Migrate complete email when To field is nil. #177
Conversation
@miq-bot add_label bug, fine/yes |
@miq-bot assign @gmcculloug |
@tinaafitz Please Review |
@tinaafitz Changes are easier to review by ignoring whitespace: https://github.com/ManageIQ/manageiq-content/pull/177/files?w=1 |
@@ -27,25 +27,30 @@ | |||
$evm.log("info", "VM Owner: #{owner.inspect}") | |||
|
|||
# to_email_address from owner.email then from model if nil | |||
to = owner.email || $evm.object['to_email_address'] | |||
to = owner.email unless owner.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billfitzgerald0120 Keep the original format and use try
to handle the nil
owner object.
to = owner.try(:email) || $evm.object['to_email_address']
dc9e767
to
cde51a9
Compare
@gmcculloug made changes as requested |
@@ -11,11 +11,21 @@ | |||
expect(GenericMailer).to receive(:deliver).with(:automation_notification, | |||
hash_including(:to => user.email, | |||
:from => "evmadmin@example.com" | |||
) | |||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billfitzgerald0120 The change in whitespace here is revealing the rubocop warnings around alignment. Please update the closing parentheses, like you did in the new test below, to remove the warnings.
) | ||
attrs = ["MiqServer::miq_server=#{miq_server.id}"] | ||
attrs << "MiqRequestTask::vm_migrate_task=#{miq_request_task.id}" | ||
attrs << "vm_migrate_task_id=#{miq_request_task.id}" | ||
MiqAeEngine.instantiate("/Infrastructure/VM/Migrate/Email/VmMigrateTask_Complete?event=vm_migrated&#{attrs.join('&')}", user) | ||
end | ||
|
||
it 'sends email to nil' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test name is misleading as you are expecting the logic to not send an email in this case. Please reword.
cde51a9
to
91a6f71
Compare
@gmcculloug Made changes as requested, please review |
@billfitzgerald0120 @tinaafitz Looks like we have this exposure in a number of email methods. Do we handle this anywhere else? Would it make more sense to send the email to someone like an administrator in this case instead of just skipping the email when someone migrates a VM? |
@gmcculloug @tinaafitz We handle this in Infrastructure and Cloud MiqProvision_Complete method. |
@@ -27,25 +27,29 @@ | |||
$evm.log("info", "VM Owner: #{owner.inspect}") | |||
|
|||
# to_email_address from owner.email then from model if nil | |||
to = owner.email || $evm.object['to_email_address'] | |||
to = owner.try(:email) || $evm.object['to_email_address'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billfitzgerald0120 - I like the try
here - so it's probably fine - but your fix works without it. The addition of your check for if to.nil?
seems to be the real fix. I'm questioning the need for the try
apart from readability.
91a6f71
to
936b0c5
Compare
@tinaafitz I added the requester_email as the second choice for the 'to' email value. |
@tinaafitz Please Review |
@tinaafitz Does the method need to change for this or can this be fixed in the schema? I recall we briefly discussed this. @billfitzgerald0120 Can you describe the condition in which this happens since the schema includes a default email address? When would the |
@gmcculloug @tinaafitz The problem was the owner.email was failing. I added the .try which fixed the problem. I added the requester.email as the second option. We talked about making sure that we send an email to someone and not just abort the email. The schema should always have a value but the requester is probably a better option. It's possible the schema has the default values for to_email_address instead of the actual requester. -to = owner.email || $evm.object['to_email_address'] |
@tinaafitz Please review |
Made change to not send email when the To field is nil. Added log message that email will not be sent. https://bugzilla.redhat.com/show_bug.cgi?id=1486461
936b0c5
to
655f095
Compare
Checked commit billfitzgerald0120@655f095 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
Fix VM Migrate complete email when To field is nil. (cherry picked from commit 07fe288) https://bugzilla.redhat.com/show_bug.cgi?id=1496937
Fine backport details:
|
Made change to not send email when the To field is nil.
Added log message that email will not be sent.
https://bugzilla.redhat.com/show_bug.cgi?id=1486461