-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabling SMTP feature to send emails via ActionMailer (#584)
* Enabling SMTP feature to send emails via ActionMailer * fixing rubocop offenses - TrailingEmptyLines * Linting Issues on .Vue files * SMTP controller logic modified to welcome project,component users; Created Instance Variables to Avoid DB Model access from views * Removed project reference as this is related to a component * reduced db round trips --------- Co-authored-by: Sai Pavan Marlakunta <smarlakunta@vmware.com>
- Loading branch information
1 parent
cdf09a8
commit ac486ee
Showing
13 changed files
with
319 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# frozen_string_literal: true | ||
|
||
# Sends Email Notifications to users if Vulcan is configured to use an SMTP server | ||
class UserMailer < ApplicationMailer | ||
def welcome_project_member(*args) | ||
parse_mailer_welcome_user_args(*args) | ||
begin | ||
mail( | ||
to: @user.email, | ||
cc: @project_admins, | ||
subject: "Vulcan Project Access - #{@project.name}", | ||
from: Settings.smtp.settings.user_name | ||
) | ||
rescue StandardError => e | ||
Rails.logger.error("Error delivering welcome email to user #{@user.name}: #{e.message}") | ||
end | ||
end | ||
|
||
def welcome_component_member(*args) | ||
parse_mailer_welcome_user_args(*args) | ||
begin | ||
mail( | ||
to: @user.email, | ||
cc: @project_admins, | ||
subject: "Vulcan Component Access - #{@component.name}", | ||
from: Settings.smtp.settings.user_name | ||
) | ||
rescue StandardError => e | ||
Rails.logger.error("Error delivering welcome email to user #{@user.name}: #{e.message}") | ||
end | ||
end | ||
|
||
def request_review(*args) | ||
parse_mailer_review_args(*args) | ||
begin | ||
mail( | ||
to: @project_admins, | ||
cc: @current_user.email, | ||
subject: "Review Requested - #{@stig_id}", | ||
from: Settings.smtp.settings.user_name | ||
) | ||
rescue StandardError => e | ||
Rails.logger.error("Error delivering request_review by user #{@current_user.name}: #{e.message}") | ||
end | ||
end | ||
|
||
def approve_review(*args) | ||
parse_mailer_review_args(*args) | ||
@latest_review_user = find_latest_request_review(@rule, @component_id) | ||
begin | ||
mail( | ||
to: @latest_review_user.email, | ||
cc: @project_admins, | ||
subject: "Review Approved - #{@stig_id}", | ||
from: Settings.smtp.settings.user_name | ||
) | ||
rescue StandardError => e | ||
Rails.logger.error("Error delivering approve_review by user #{@current_user.name}: #{e.message}") | ||
end | ||
end | ||
|
||
def revoke_review(*args) | ||
parse_mailer_review_args(*args) | ||
@latest_review_user = find_latest_request_review(@rule, @component_id) | ||
begin | ||
mail( | ||
to: @latest_review_user.email, | ||
cc: @project_admins, | ||
subject: "Review Revoked - #{@stig_id}", | ||
from: Settings.smtp.settings.user_name | ||
) | ||
rescue StandardError => e | ||
Rails.logger.error("Error delivering revoke_review_request by user #{@current_user.name}: #{e.message}") | ||
end | ||
end | ||
|
||
def request_review_changes(*args) | ||
parse_mailer_review_args(*args) | ||
@latest_review_user = find_latest_request_review(@rule, @component_id) | ||
begin | ||
mail( | ||
to: @latest_review_user.email, | ||
cc: @project_admins, | ||
subject: "Requesting Changes on the Review - #{@stig_id}", | ||
from: Settings.smtp.settings.user_name | ||
) | ||
rescue StandardError => e | ||
Rails.logger.error("Error delivering request_review_changes by user #{@current_user.name}: #{e.message}") | ||
end | ||
end | ||
|
||
private | ||
|
||
def get_project_admins(project_id) | ||
Project.find(project_id).users.where(memberships: { role: 'admin' }).pluck(:email) | ||
end | ||
|
||
def parse_mailer_review_args(*args) | ||
@current_user, @component_id, @comment, @rule = args | ||
@stig_id = "#{Component.find(@component_id).prefix}-#{@rule.rule_id}" | ||
@project_id = Component.find(@component_id).project.id | ||
@project_admins = get_project_admins(@project_id) | ||
end | ||
|
||
def parse_mailer_welcome_user_args(*args) | ||
@current_user, @membership = args | ||
case @membership.membership_type | ||
when 'Project' | ||
@project_id = @membership.membership_id | ||
@project = Project.find(@project_id) | ||
when 'Component' | ||
@component_id = @membership.membership_id | ||
@component = Component.find(@component_id) | ||
@project_id = @component.project_id | ||
end | ||
@project_admins = get_project_admins(@project_id) | ||
@user = User.find(@membership.user_id) | ||
@role_assigned = @membership.role.to_s | ||
end | ||
|
||
def find_latest_request_review(rule, component_id) | ||
latest_review = Review.where( | ||
rule_id: Rule.find_by(rule_id: rule.rule_id.to_s, component_id: component_id).id, | ||
action: 'request_review' | ||
).order(updated_at: :desc).first | ||
latest_review.user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<head> | ||
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' /> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
font-size: 16px; | ||
line-height: 1.5; | ||
color: #333; | ||
background-color: #f8f8f8; | ||
padding: 20px; | ||
} | ||
|
||
h1, h2, h3, h4, h5, h6 { | ||
margin-top: 0; | ||
margin-bottom: 10px; | ||
font-family: Arial, sans-serif; | ||
font-weight: bold; | ||
color: #333; | ||
} | ||
|
||
p, blockquote { | ||
margin-top: 0; | ||
margin-bottom: 10px; | ||
font-family: Arial, sans-serif; | ||
color: #333; | ||
} | ||
|
||
a { | ||
color: #007bff; | ||
text-decoration: none; | ||
} | ||
|
||
a:hover { | ||
color: #0056b3; | ||
text-decoration: underline; | ||
} | ||
|
||
blockquote { | ||
border-left: 5px solid #007bff; | ||
padding-left: 10px; | ||
} | ||
</style> | ||
</head> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<%= render 'user_mailer/shared_styles' %> | ||
<body> | ||
<h2>Hi <%=@latest_review_user.name %>,</h2> | ||
<% if Settings.app_url.present? %> | ||
<p><%= @current_user.name %> approved review on <%= link_to @stig_id, "#{Settings.app_url}/components/#{@component_id}/#{@stig_id}" %> .</p> | ||
<% else %> | ||
<p><%= @current_user.name %> approved review on <%= @stig_id %>.</p> | ||
<% end %> | ||
<h3>The approved comments are:</h3> | ||
<blockquote> | ||
<%= @comment %> | ||
</blockquote> | ||
<br/> | ||
<br/> | ||
<p>Thank you,</p> | ||
<p>Vulcan Support</p> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<%= render 'user_mailer/shared_styles' %> | ||
<body> | ||
<h2>Hello ProjectAdmins,</h2> | ||
<% if Settings.app_url.present? %> | ||
<p><%= @current_user.name %> requested review on <%= link_to @stig_id, "#{Settings.app_url}/components/#{@component_id}/#{@stig_id}" %> .</p> | ||
<% else %> | ||
<p><%= @current_user.name %> requested review on <%= @stig_id %>.</p> | ||
<% end %> | ||
<h3>The review comment is:</h3> | ||
<blockquote> | ||
<%= @comment %> | ||
</blockquote> | ||
<br/> | ||
<br/> | ||
<p>Thank you,</p> | ||
<p>Vulcan Support</p> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<%= render 'user_mailer/shared_styles' %> | ||
<body> | ||
<h2>Hi <%=@latest_review_user.name %>,</h2> | ||
<% if Settings.app_url.present? %> | ||
<p><%= @current_user.name %> requested changes on the review <%= link_to @stig_id, "#{Settings.app_url}/components/#{@component_id}/#{@stig_id}" %> .</p> | ||
<% else %> | ||
<p><%= @current_user.name %> requested changes on the review <%= @stig_id %>.</p> | ||
<% end %> | ||
<h3>The comments are:</h3> | ||
<blockquote> | ||
<%= @comment %> | ||
</blockquote> | ||
<br/> | ||
<br/> | ||
<p>Thank you,</p> | ||
<p>Vulcan Support</p> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<%= render 'user_mailer/shared_styles' %> | ||
<body> | ||
<h2>Hi <%=@latest_review_user.name %>,</h2> | ||
<% if Settings.app_url.present? %> | ||
<p><%= @current_user.name %> revoked review on <%= link_to @stig_id, "#{Settings.app_url}/components/#{@component_id}/#{@stig_id}" %> .</p> | ||
<% else %> | ||
<p><%= @current_user.name %> revoked review on <%= @stig_id %>.</p> | ||
<% end %> | ||
<h3>The revoked comments are:</h3> | ||
<blockquote> | ||
<%= @comment %> | ||
</blockquote> | ||
<br/> | ||
<br/> | ||
<p>Thank you,</p> | ||
<p>Vulcan Support</p> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<%= render 'user_mailer/shared_styles' %> | ||
<body> | ||
<h2>Vulcan Component Access</h2> | ||
<p>Hi <%= @user.name %>,</p> | ||
<p>You have been added to the <%= @role_assigned %> role in the <%= @component.name %> component.</p> | ||
<% if Settings.app_url.present? %> | ||
<p>You can access the component at <%= link_to @component.name, "#{Settings.app_url}/components/#{@component_id}" %> .</p> | ||
<% else %> | ||
<p>You can access the component "<%= @component.name %>".</p> | ||
<% end %> | ||
<br/> | ||
<br/> | ||
<p>Thank you,</p> | ||
<p>Vulcan Support</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<%= render 'user_mailer/shared_styles' %> | ||
<body> | ||
<h2>Vulcan Project Access</h2> | ||
<p>Hi <%= @user.name %>,</p> | ||
<p>You have been added to the <%= @role_assigned %> role in the <%= @project.name %> project.</p> | ||
<% if Settings.app_url.present? %> | ||
<p>You can access the project at <%= link_to @project.name, "#{Settings.app_url}/projects/#{@project_id}" %> .</p> | ||
<% else %> | ||
<p>You can access the project "<%= @project.name %>".</p> | ||
<% end %> | ||
<br/> | ||
<br/> | ||
<p>Thank you,</p> | ||
<p>Vulcan Support</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters