CSC/ECE 517 Fall 2018/E1834 Improve email notifications: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(27 intermediate revisions by the same user not shown)
Line 12: Line 12:
<li>Deadline reminders should include a link on where to go to perform the needed function.
<li>Deadline reminders should include a link on where to go to perform the needed function.


==Approach Taken To Implement Changes==
==Modified Files==
* app/models/assignment_participant.rb
* app/models/assignment.rb
* app/models/course_participant.rb
* app/controllers/submitted_content_controller.rb
* app/mailers/delayed_mailer.rb
* lib/tasks/background_email_reminder.rake
* spec/models/assignment_particpant_spec.rb
 
==Implementation approach==
 


NOTE: All the mails except the ones for the reviewer which are sent to mailinator are sent to expertiza.development@gmail.com ,as this is already set in the development environment.


'''1) Mail sent when participant added to assignment :'''
'''1) Email sent when user is added as a participant to assignment :'''


When students' accounts are created by importing a CSV file on the Users page,they receive e-mails but not when user was added as a participant to the assignment.We added a method in the assignment_participant.rb model to send mails when a participant is added to an assignment on the assignment page through a CSV file.This functionality is implemented with using the MailerHelper class.
When students' accounts are created by importing a CSV file on the Users page,they receive e-mails but not when user was added as a participant to the assignment. We added a method in the assignment_participant.rb file (model) to send mails when a participant is added to an assignment on the assignment page by importing a CSV file. We have also added a method in the course_participant.rb file(model), to send the mail when a Course participant is added by importing a CSV file. Both functionalities are implemented using the method from the MailerHelper class i.e send_mail_to_user().


  # provide import functionality for Assignment Participants
https://github.com/expertiza/expertiza/commit/c17bb25827e43940cc9f253c04ee7343878298df
  # if user does not exist, it will be created and added to this assignment
  def self.import(row_hash, _row_header = nil, session, id)
    raise ArgumentError, "No user id has been specified." if row_hash.empty?
    user = User.find_by(name: row_hash[:name])
    if user.nil?
      raise ArgumentError, "The record containing #{row_hash[:name]} does not have enough items." if row_hash.length < 4
      attributes = ImportFileHelper.define_attributes(row_hash)
      user = ImportFileHelper.create_new_user(attributes, session)
    end
    raise ImportError, "The assignment with id \"#{id.to_s}\" was not found." if Assignment.find(id).nil?
    unless AssignmentParticipant.exists?(user_id: user.id, parent_id: id)
      new_part = AssignmentParticipant.create(user_id: user.id, parent_id: id)
      new_part.set_handle
    end
    prepared_mail = MailerHelper.send_mail_to_user(user, "Your Expertiza account and password have been created.", "user_welcome", "password")
    prepared_mail.deliver
  end




We have in a similar fashion added a method in the course_participant model.
'''2) Sending email to reviewer when new submission is availble:'''


  # provide import functionality for Course Participants
Added functionality to send email to the reviewer when new submission is available by making changes in the submitted_content_controller and assignment_participant model.The method handled boundary constraints like checking whether the round was valid and disabling email notification after the last round of review.
  # if user does not exist, it will be created and added to this assignment
  def self.import(row_hash, _row_header = nil, session, id)
    raise ArgumentError, "No user id has been specified." if row_hash.empty?
    user = User.find_by(name: row_hash[:name])
    if user.nil?
      raise ArgumentError, "The record containing #{row_hash[:name]} does not have enough items." if row_hash.length < 4
      attributes = ImportFileHelper.define_attributes(row_hash)
      user = ImportFileHelper.create_new_user(attributes, session)
    end
    course = Course.find_by(id)
    raise ImportError, "The course with the id \"" + id.to_s + "\" was not found." if course.nil?
    unless CourseParticipant.exists?(user_id: user.id, parent_id: id)
      CourseParticipant.create(user_id: user.id, parent_id: id)
    end
    password = "password"#user.password
    prepared_mail = MailerHelper.send_mail_to_user(user, "Your Expertiza account and password have been created.", "user_welcome", password)
    prepared_mail.deliver
  end


Code to check if it was the valid round


'''2) Sending email to reviewer when new submission is availble:'''
In the assignment_participant.rb,
Firstly, fetched the topic_id from the SignedUpTeam class and got the next due date using the DueDate model
Finally compared the round of the Due date with the number of review rounds of the assignments, to verify if its the final round.


Added functionality to send email to the reviewer when new submission is available by making changes in the submitted_content_controller and assignment_participant model.
https://github.com/expertiza/expertiza/commit/e09761b7d8746f26485f264c7fd7936b8d956326#diff-ab934619c8e13cc78f27fbc38461a25b
The method handled boundary constraints like checking whether the round was valid and disabling email notification after the last round of review.


  #assignment_participant.rb
  def is_in_final_round?
    topic_id = SignedUpTeam.topic_id(self.parent_id, self.user_id)
    return false if topic_id.nil? and self.staggered_deadline?
    next_due_date = DueDate.get_next_due_date(self.parent_id, topic_id)
    return !!(next_due_date.round == assignment.num_review_rounds && next_due_date.deadline_type_id == 2)
  end


Extra functionality of specifying the current review round and providing the direct link to reviewer in the mail itself also implemented in the submitted_content controller using the ReviewResponseMap and Response class.
Extra functionality of specifying the current review round and providing the direct link to reviewer in the mail itself also implemented in the submitted_content controller using the ReviewResponseMap and Response class.


  #submitted_content_controller.
In the submitted_content_controller.rb,
  # Send email to reviewers to review new submission, if review_round is valid and not last.
We mapped the reviewer_id and reviewee_id, fetched from participants, using the ReviewResponseMap class.
      @participant = AssignmentParticipant.find(params[:id])
For all such mappings retrieved, we are fetching the last response id, which is then passed as the URL suffix to redirect the reviewer to the appropriate page.
      # Send email to reviewers to review new submission, if the participant is not in the last round.
 
      if !@participant.is_in_final_round?
https://github.com/expertiza/expertiza/commit/e9de954591975724e3dc549144185c00c7e5b0dd#diff-33d668958529875af7029d78e37aff60
        @participant.reviewers.each do |reviewer|
 
          map = ReviewResponseMap.where(['reviewer_id = ? and reviewee_id = ?', reviewer.id, @participant.team.id]).first
 
          responses = Response.where(:map_id => map.id)
'''3) Including a specific link for the  deadline reminders email functionality for reviewers :'''
          responses = responses.sort_by { |obj| obj.updated_at }
 
Added a review_reminder_email method and mail_reviewers method in the delayed_mailer.rb file which implemented the functionality for sending deadline reminder mails which includes a link on where to go and perform the specific task.
Prepared a hash named email_list using the email and participant_id, for each participant who is a reviewer.
Using this hash, we are calling the review_reminder_email function.
In this function, based on the due date for the deadline_type(i.e reviewer), we fetch the participant id of the same and add it as the suffix in the URL to be visited by the reviewer.
Also, the logic of the copy of mail to the instructor is also taken care.
Notice that the link in the instructor's email will contain the '?id=' field of the last participant fetched.
 
https://github.com/expertiza/expertiza/commit/95476252c1e44f7262ba76993414bdb3ab76c64a#diff-9d59b3dd49f673876917117e94433d4e
 
 
In the background_email_reminder.rake file,
Earlier only the emails for the participants were fetched, but now we are fetching the hash containing the email and response_id. The response_id field was fetched as per the below order in the code-
participants.review_mappings -> allresponsemaps -> eachresponsemap -> response.
For the reviewer assign_type, we have defined a separate method send_reminder_emails(), wherein we pass the response_id of the email_list hash, and add it as a suffix in the URL which will be accessed by the reviewer.
 
https://github.com/expertiza/expertiza/commit/95476252c1e44f7262ba76993414bdb3ab76c64a#diff-a0169176ac373c3a8222d8cba5acdac0
 
 
'''Bonus Functionality Implemented below:-'''
 
 
'''4) Including a specific link for the  deadline reminders email functionality for submissions  :'''
 
Added a submission_reminder_email method in the delayed_mailer.rb file which implemented the functionality for sending deadline reminder mails which includes a link on where to go and perform the submission.
Prepared a hash named emails in the function find_team_members_email using the email and team_member_id, for each participant who is a team member.
Using this hash, we are calling the review_reminder_email function.
In this function, based on the due date for the deadline_type(i.e submission), we fetch the participant_id of the same and add it as the suffix in the URL to be visited by the team member.
 
https://github.com/pratik-abhyankar/expertiza/commit/0a2af1a67eea4717e0e10974fba0df134aa67bf1#diff-9d59b3dd49f673876917117e94433d4e
 
 
In the background_email_reminder.rake file,
for the assign_type="submission", we fetch the assign.id which is to be passed as the suffix to the url to be sent in the mail for submission reminder.
The team members can click on this link in the email and get redirected to the submission page of the particular asssignment.
 
https://github.com/pratik-abhyankar/expertiza/commit/0a2af1a67eea4717e0e10974fba0df134aa67bf1#diff-a0169176ac373c3a8222d8cba5acdac0


          # the latest response will be the last
==Testing==
          latest_response = responses.last


          # we need to pass the id of lastest_response in the URL mentioned in the mail.
We have used Rspec for testing the email functionalities.Using the test driven development(TDD) approach, we have added an Rspec test which checks whether the mail is delivered to the expected receiver upon creation of the account for the student.
          # this will open the correct /response/edit?id=#{latest_response.id} page for the reviewer when (s)he clicks on it.
          Mailer.delayed_message(bcc: [User.find(reviewer.user_id).email],
                                subject: "You have a new submission to review",
                                body: "Please visit https://expertiza.ncsu.edu/response/edit?id=#{latest_response.id} and proceed to peer
                                reviews.").deliver_now
        end
      end


'''3) Including a specific link for the deadline reminders email functionality :'''
We have created a new assignment_particpant_ spec file for the above purpose.The spec uses double and stub features of rspec gem to fake user login.
Since the smtp setting are set to test mode all mails go to expertiza.development@gmail.com and not the actual user.Hence when an email is sent the
ActionMailer::Base.deliveries list gets updated.The last element in the deliveries list will be the email that was sent when the import method was invoked.
Then using expect object we verify whether the email was correctly sent by checking the subject, from and to field.


Added a review_reminder_email method and mail_reviewers method in the delayed_mailer.rb file which implemented the functionality for sending deadline reminder mails which includes a link on where to gon to perform the specific task.
https://github.com/expertiza/expertiza/commit/3c17dd70fcdc39e0600ad01a5953bb8adf007ffd#diff-33bbfe50bc35527232a815c6492d8fb4
  #delayed_mailer.rb
 
  def mail_reviewers
   
    email_list = []
NOTE: All the mails except the ones for the reviewer which are sent to mailinator are sent to expertiza.development@gmail.com ,as this is already set in the development environment.
    reviews = ReviewResponseMap.where(reviewed_object_id: self.assignment_id)
    reviews.each do |review|
      participant = Participant.where(parent_id: self.assignment_id, id: review.reviewer_id).first
      email_list << {'email' => participant.user.email, 'participant_id' => participant.id}
    end
    review_reminder_email(email_list, self.deadline_type) unless email_list.empty?
  end


  def review_reminder_email(email_list, deadline_type)
==Additional Links==
    assignment = Assignment.find(self.assignment_id)
    subject = "Message regarding #{deadline_type} for assignment #{assignment.name}"
    for item in email_list
      body = "This is a reminder to complete #{deadline_type} for assignment #{assignment.name}. \
              Deadline is #{self.due_at}. Please visit https://expertiza.ncsu.edu/student_review/list?id=#{item.participant_id}\
              If you have already done the  #{deadline_type}, please ignore this mail."
      Rails.logger.info item.email
      @mail = Mailer.delayed_message(bcc: [item.email], subject: subject, body: body)
      @mail.deliver_now
    end


    @count += 1
*Git pull link: https://github.com/expertiza/expertiza/pull/1253
    if @count % 3 == 0
*VCL deployment: http://152.46.18.165:8080/
      if assignment.instructor.copy_of_emails
        # if email is sent to instructor, notice that the link in that email will contain the '?id=' field of the last participant
        @mail = Mailer.delayed_message(bcc: [assignment.instructor.email], subject: subject, body: body)
        @mail.deliver_now
      end
    end
  end


Corresponding changes in the background_email_reminder.rake file implemented.
==References==
A method named send_reminder_mails implemented.
#[https://github.com/expertiza/expertiza Expertiza on GitHub]
#[https://github.com/WintersLt/expertiza GitHub Project Repository Fork]
#[http://expertiza.ncsu.edu/ The live Expertiza website]
#[https://relishapp.com/rspec Rspec Documentation]


  def send_reminder_emails(email_list, assign_name, due_date, assign_type)
==Team==
    due_date_string = due_date.due_at.to_s
[mailto:ahshah4@ncsu.edu Aditya Shah]<br>
    subject = "Message regarding #{assign_type} for #{assign_name}"
[mailto:ananava@ncsu.edu Ankit Nanavaty]<br>
    for item in email_list
[mailto:paabhyan@ncsu.edu Pratik Abhyankar]
      body = "This is a reminder to complete #{assign_type} for assignment #{assign_name}. " +
          "Deadline is #{due_date_string}. " +
          "Please visit https://expertiza.ncsu.edu/response/edit?id=#{item.response_id}"
      Mailer.deliver_message({ :bcc => [item.email], :subject => subject, :body => body })
    end
  end

Latest revision as of 04:47, 10 November 2018

This page provides a description of the Expertiza based OSS project.

About Expertiza

Expertiza is an open source project developed using Ruby on Rails framework.Expertiza allows the instructor to create new assignments and customize new or existing assignments.The application allows students to submit and peer-review learning objects (articles, code, web sites, etc)[1].Expertiza supports submission across various document types, including the URLs and wiki pages.

Problem Statement

  • When students' accounts are created by importing a CSV file on the Users page, they receive e-mails with their user-ID and password. But if an account is created by adding them as participants to an assignment when they don't already have an account, e-mail is not sent. Students should receive e-mails upon account creation, regardless of how their account is created. So this involves adding a call to the e-mailer … or, perhaps, moving an email call from the Users controller to the point where an account is actually created.
  • Second, evidently if a submission is revised after review, the system e-mails the reviewer saying to revise the review. This is just fine ... except if the last round of review is in progress.The message telling reviewers to revise their reviews should not be sent after the last review deadline has passed. It would also be nice to fix the message so it tells which review (Review 1, Review 2, etc.) has been revised, and gives the reviewer a link directly to it.
  • Deadline reminders should include a link on where to go to perform the needed function.

    Modified Files

    • app/models/assignment_participant.rb
    • app/models/assignment.rb
    • app/models/course_participant.rb
    • app/controllers/submitted_content_controller.rb
    • app/mailers/delayed_mailer.rb
    • lib/tasks/background_email_reminder.rake
    • spec/models/assignment_particpant_spec.rb

    Implementation approach

    1) Email sent when user is added as a participant to assignment :

    When students' accounts are created by importing a CSV file on the Users page,they receive e-mails but not when user was added as a participant to the assignment. We added a method in the assignment_participant.rb file (model) to send mails when a participant is added to an assignment on the assignment page by importing a CSV file. We have also added a method in the course_participant.rb file(model), to send the mail when a Course participant is added by importing a CSV file. Both functionalities are implemented using the method from the MailerHelper class i.e send_mail_to_user().

    https://github.com/expertiza/expertiza/commit/c17bb25827e43940cc9f253c04ee7343878298df


    2) Sending email to reviewer when new submission is availble:

    Added functionality to send email to the reviewer when new submission is available by making changes in the submitted_content_controller and assignment_participant model.The method handled boundary constraints like checking whether the round was valid and disabling email notification after the last round of review.

    Code to check if it was the valid round

    In the assignment_participant.rb, Firstly, fetched the topic_id from the SignedUpTeam class and got the next due date using the DueDate model Finally compared the round of the Due date with the number of review rounds of the assignments, to verify if its the final round.

    https://github.com/expertiza/expertiza/commit/e09761b7d8746f26485f264c7fd7936b8d956326#diff-ab934619c8e13cc78f27fbc38461a25b


    Extra functionality of specifying the current review round and providing the direct link to reviewer in the mail itself also implemented in the submitted_content controller using the ReviewResponseMap and Response class.

    In the submitted_content_controller.rb, We mapped the reviewer_id and reviewee_id, fetched from participants, using the ReviewResponseMap class. For all such mappings retrieved, we are fetching the last response id, which is then passed as the URL suffix to redirect the reviewer to the appropriate page.

    https://github.com/expertiza/expertiza/commit/e9de954591975724e3dc549144185c00c7e5b0dd#diff-33d668958529875af7029d78e37aff60


    3) Including a specific link for the deadline reminders email functionality for reviewers  :

    Added a review_reminder_email method and mail_reviewers method in the delayed_mailer.rb file which implemented the functionality for sending deadline reminder mails which includes a link on where to go and perform the specific task. Prepared a hash named email_list using the email and participant_id, for each participant who is a reviewer. Using this hash, we are calling the review_reminder_email function. In this function, based on the due date for the deadline_type(i.e reviewer), we fetch the participant id of the same and add it as the suffix in the URL to be visited by the reviewer. Also, the logic of the copy of mail to the instructor is also taken care. Notice that the link in the instructor's email will contain the '?id=' field of the last participant fetched.

    https://github.com/expertiza/expertiza/commit/95476252c1e44f7262ba76993414bdb3ab76c64a#diff-9d59b3dd49f673876917117e94433d4e


    In the background_email_reminder.rake file, Earlier only the emails for the participants were fetched, but now we are fetching the hash containing the email and response_id. The response_id field was fetched as per the below order in the code- participants.review_mappings -> allresponsemaps -> eachresponsemap -> response. For the reviewer assign_type, we have defined a separate method send_reminder_emails(), wherein we pass the response_id of the email_list hash, and add it as a suffix in the URL which will be accessed by the reviewer.

    https://github.com/expertiza/expertiza/commit/95476252c1e44f7262ba76993414bdb3ab76c64a#diff-a0169176ac373c3a8222d8cba5acdac0


    Bonus Functionality Implemented below:-


    4) Including a specific link for the deadline reminders email functionality for submissions  :

    Added a submission_reminder_email method in the delayed_mailer.rb file which implemented the functionality for sending deadline reminder mails which includes a link on where to go and perform the submission. Prepared a hash named emails in the function find_team_members_email using the email and team_member_id, for each participant who is a team member. Using this hash, we are calling the review_reminder_email function. In this function, based on the due date for the deadline_type(i.e submission), we fetch the participant_id of the same and add it as the suffix in the URL to be visited by the team member.

    https://github.com/pratik-abhyankar/expertiza/commit/0a2af1a67eea4717e0e10974fba0df134aa67bf1#diff-9d59b3dd49f673876917117e94433d4e


    In the background_email_reminder.rake file, for the assign_type="submission", we fetch the assign.id which is to be passed as the suffix to the url to be sent in the mail for submission reminder. The team members can click on this link in the email and get redirected to the submission page of the particular asssignment.

    https://github.com/pratik-abhyankar/expertiza/commit/0a2af1a67eea4717e0e10974fba0df134aa67bf1#diff-a0169176ac373c3a8222d8cba5acdac0

    Testing

    We have used Rspec for testing the email functionalities.Using the test driven development(TDD) approach, we have added an Rspec test which checks whether the mail is delivered to the expected receiver upon creation of the account for the student.


    We have created a new assignment_particpant_ spec file for the above purpose.The spec uses double and stub features of rspec gem to fake user login. Since the smtp setting are set to test mode all mails go to expertiza.development@gmail.com and not the actual user.Hence when an email is sent the ActionMailer::Base.deliveries list gets updated.The last element in the deliveries list will be the email that was sent when the import method was invoked. Then using expect object we verify whether the email was correctly sent by checking the subject, from and to field.

    https://github.com/expertiza/expertiza/commit/3c17dd70fcdc39e0600ad01a5953bb8adf007ffd#diff-33bbfe50bc35527232a815c6492d8fb4


    NOTE: All the mails except the ones for the reviewer which are sent to mailinator are sent to expertiza.development@gmail.com ,as this is already set in the development environment.

    Additional Links

    References

    1. Expertiza on GitHub
    2. GitHub Project Repository Fork
    3. The live Expertiza website
    4. Rspec Documentation

    Team

    Aditya Shah
    Ankit Nanavaty
    Pratik Abhyankar