From 7d890ee39b85b15641cf38e7a45f047c178f0148 Mon Sep 17 00:00:00 2001 From: Simon Getahun Date: Tue, 29 Oct 2024 21:35:16 -0400 Subject: [PATCH 1/3] modification to email --- app/models/team.rb | 19 +++++++++++++------ .../_dual_role_added_to_team_html.html.erb | 11 +++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 app/views/mailer/partials/_dual_role_added_to_team_html.html.erb diff --git a/app/models/team.rb b/app/models/team.rb index 9298e1b32d7..f2d4a06e210 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -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 diff --git a/app/views/mailer/partials/_dual_role_added_to_team_html.html.erb b/app/views/mailer/partials/_dual_role_added_to_team_html.html.erb new file mode 100644 index 00000000000..e28a835e1c1 --- /dev/null +++ b/app/views/mailer/partials/_dual_role_added_to_team_html.html.erb @@ -0,0 +1,11 @@ +Hi <%= @first_name %>, +
+

+ You have been added to Team '<%= @team %>' for the Assignment '<%= @assignment %>' on Expertiza. +

+

+ Please note that you are assigned both as a mentor and a participant for this team. +

+

+ Expertiza Team +

From 2db26cf638a8b5b4403490bb2313de34780f6074 Mon Sep 17 00:00:00 2001 From: Simon Getahun Date: Tue, 29 Oct 2024 21:43:50 -0400 Subject: [PATCH 2/3] added test for new feature --- spec/models/team_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb index 51d5af72776..c7adab57cc6 100644 --- a/spec/models/team_spec.rb +++ b/spec/models/team_spec.rb @@ -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)) @@ -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 From a93285cbd5426c49b00e7b0167505f8eab24476f Mon Sep 17 00:00:00 2001 From: Simon Getahun Date: Tue, 29 Oct 2024 21:57:56 -0400 Subject: [PATCH 3/3] changed model to handle dual case --- app/models/mentored_team.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/models/mentored_team.rb b/app/models/mentored_team.rb index e009d8948e2..a43feca21e7 100644 --- a/app/models/mentored_team.rb +++ b/app/models/mentored_team.rb @@ -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