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

Email test #7

Merged
merged 3 commits into from
Oct 30, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions app/models/mentored_team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ def add_member(user, _assignment_id = nil)
ExpertizaLogger.info LoggerMessage.new('Model:Team', user.name, "Added member to the team #{id}")

assignment_name = _assignment_id ? Assignment.find(_assignment_id).name.to_s : ""
if MentorManagement.user_a_mentor?(user)
MailerHelper.send_team_confirmation_mail_to_user(user, "[Expertiza] Added to a Team", "mentor_added_to_team", "#{name}", assignment_name).deliver
elsif !user.is_a?(Participant)
MailerHelper.send_team_confirmation_mail_to_user(user, "[Expertiza] Added to a Team", "user_added_to_team", "#{name}", assignment_name).deliver
end
# mentor only
if MentorManagement.user_a_mentor?(user) && !user.is_a?(Participant)
MailerHelper.send_team_confirmation_mail_to_user(user, "[Expertiza] Added to a Team", "mentor_added_to_team", "#{name}", assignment_name).deliver
# participant only
elsif !MentorManagement.user_a_mentor?(user) && user.is_a?(Participant)
MailerHelper.send_team_confirmation_mail_to_user(user, "[Expertiza] Added to a Team", "user_added_to_team", "#{name}", assignment_name).deliver
# dual case
elsif MentorManagement.user_a_mentor?(user) && user.is_a?(Participant)
MailerHelper.send_team_confirmation_mail_to_user(user, "[Expertiza] Added to a Team", "dual_role_added_to_team", "#{name}", assignment_name).deliver
end
end

if can_add_member
MentorManagement.assign_mentor(_assignment_id, id)
end
Expand Down
19 changes: 13 additions & 6 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,21 @@ def add_member(user, _assignment_id = nil)

# if assignment_id is nil, then don't send an assignment name
assignment_name = _assignment_id ? Assignment.find(_assignment_id).name.to_s : ""
# Now that a new team member has been added to a team, send an email to them letting them know
if MentorManagement.user_a_mentor?(user)

# addressing efg's comment in previous PR
# if just mentor
if MentorManagement.user_a_mentor?(user) && !user.is_a?(Participant)
MailerHelper.send_team_confirmation_mail_to_user(user, "[Expertiza] Added to a Team", "mentor_added_to_team", "#{name}", assignment_name).deliver
elsif !user.is_a?(Participant)
# If the user is a participant, then we don't went to send them emails since that class is something
# completely out of the scope of this project

# only a participant
elsif !MentorManagement.user_a_mentor?(user) && user.is_a?(Participant)
MailerHelper.send_team_confirmation_mail_to_user(user, "[Expertiza] Added to a Team", "user_added_to_team", "#{name}", assignment_name).deliver
end

# both mentor and participant
elsif MentorManagement.user_a_mentor?(user) && user.is_a?(Participant)
MailerHelper.send_team_confirmation_mail_to_user(user, "[Expertiza] Added to a Team", "dual_role_added_to_team", "#{name}", assignment_name).deliver

end

end
can_add_member
Expand Down
11 changes: 11 additions & 0 deletions app/views/mailer/partials/_dual_role_added_to_team_html.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Hi <%= @first_name %>,
<BR>
<p>
You have been added to Team '<%= @team %>' for the Assignment '<%= @assignment %>' on Expertiza.
</p>
<p>
Please note that you are assigned both as a <strong>mentor</strong> and a <strong>participant</strong> for this team.
</p>
<p>
Expertiza Team
</p>
14 changes: 13 additions & 1 deletion spec/models/team_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
expect(team.add_member(user)).to be true
end

it 'sends mail to user if user is a user' do
it 'sends mail to user if the user is a participant only' do
allow(MentorManagement).to receive(:user_a_mentor?).with(user).and_return(false)
allow(Assignment).to receive(:find).with(1).and_return(assignment)
allow(MailerHelper).to receive(:send_team_confirmation_mail_to_user).and_return(double('Mail', deliver: true))
Expand All @@ -124,6 +124,18 @@
expect(team.add_member(user)).to be true

end

it 'sends dual-role mail if the user is both a mentor and a participant' do
allow(MentorManagement).to receive(:user_a_mentor?).with(user).and_return(true)
allow(user).to receive(:is_a?).with(Participant).and_return(true)
allow(Assignment).to receive(:find).with(1).and_return(assignment)
allow(MailerHelper).to receive(:send_team_confirmation_mail_to_user).and_return(double('Mail', deliver: true))

expect(MailerHelper).to receive(:send_team_confirmation_mail_to_user).with(user, "[Expertiza] Added to a Team", "dual_role_added_to_team", "#{team.name}", "").and_return(double('Mail', deliver: true))

expect(team.add_member(user)).to be true
end

end
end
end
Expand Down