CSC/ECE 517 Fall 2019 - E1940. Improving email notification

From Expertiza_Wiki
Revision as of 03:48, 7 November 2019 by Atrived (talk | contribs) (→‎Issue 3)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

E1940 Improving e-mail notification

Brief Introduction

  • E1940 Improving e-mail notification.
  • The forked git repository for this project can be found [1]


Problem Statement

The following tasks were accomplished in this project:

  • Issue1: Send new account welcome email to user, when imported from CSV through assignment page.
  • Issue2: Don't send email to reviewers for a new submission after review deadline has passed.
  • Issue3: Adding relevant links to reminder emails.

Issue 1 (717) - New user email

app/models/assignment_participant.rb

  • Call method to send mail after user imported successfully.
    password = user.reset_password
    MailerHelper.send_mail_to_user(user, "Your Expertiza account has been created.", "user_welcome", password).deliver

Issue2 (345)- No submission email to reviewer after deadline

  • Before fixing this issue, we had to write the logic to send emails to reviewers on submissions.


app/controllers/submitted_content_controller.rb

  • Added the logic to check for last review date to the function submit_hyperlink
      # get current date and time
      cur_date = Time.now
      # get the last due date for the review
      max_due_date = DueDate.where(parent_id: @participant.assignment.id,deadline_type_id: 2).maximum("due_at")

      # send mail only if the last due date has not passed
      if cur_date <= max_due_date
        email_submission_reviewers(@participant)
      end
  • Function to identify the reviewers and send mails.
  def email_submission_reviewers(participant)
    if participant.reviewers.length != 0
      participant.reviewers.each do |reviewer|
        rev_res_map = ReviewResponseMap.where(['reviewer_id = ? and reviewee_id = ?', reviewer.id, participant.team.id]).first
        all_responses = Response.where(:map_id => rev_res_map.id).order("updated_at DESC").first

        user = User.find(reviewer.user_id)

        if user.email_on_submission?
          MailerHelper.submission_mail_to_reviewr(user,
                                             "New submission available to review.",
                                             "update").deliver
        end
      end
    end
  end

app/helpers/mailer_helper.rb

  • Helper function to mail reviewers
  def self.submission_mail_to_reviewr(user, subject, mail_partial)
    Mailer.notify_reviewer_for_new_submission ({
        to: user.email,
        subject: subject,
        body: {
            user: user,
            #first_name: ApplicationHelper.get_user_first_name(user),
            message: "",
            partial_name: mail_partial
        }
    })
  end

app/mailers/mailer.rb

  • Mailer function to send the mail.
  def notify_reviewer_for_new_submission(defn)
    @partial_name = defn[:body][:partial_name]
    @user = defn[:body][:user]
    #@first_name = defn[:body][:first_name]
    @message = defn[:body][:message]
    mail(subject: defn[:subject],
         to: defn[:to])
  end

app/views/mailer/notify_reviewer_for_new_submission.erb

  • Email template for the mail
<!DOCTYPE html>
<html>
<head>
  <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<%= render :partial => 'mailer/partials/'+@partial_name+'_html' %>
<hr>
</body>
</html>

Issue3 (111)- Adding relevant links to reminder emails.

  • Modified function email_remainder to add functionality.

app/mailers/mail_worker.rb

def email_reminder(emails, deadline_type)
    assignment = Assignment.find(self.assignment_id)
    subject = "Message regarding #{deadline_type} for assignment #{assignment.name}"
    body = "This is a reminder to complete #{deadline_type} for assignment #{assignment.name}. \
    Deadline is #{self.due_at}.If you have already done the  #{deadline_type}, Please ignore this mail."
    body = "This is a reminder to complete #{deadline_type} for assignment #{assignment.name}."

    emails.each do |mail|
      user = User.where({email: mail}).first
      participant_assignment_id = Participant.where(user_id: user.id, parent_id: self.assignment_id).id

      link_to_destination = "Please follow the lilnk: http://expertiza.ncsu.edu/student_task/view?id=#{participant_assignment_id}"
      body = body + link_to_destination + " Deadline is #{self.due_at}.If you have already done the  #{deadline_type}, Please ignore this mail.";


      @mail = Mailer.delayed_message(bcc: mail, subject: subject, body: body)
      @mail.deliver_now
      Rails.logger.info mail
    end

    @mail = Mailer.delayed_message(bcc: emails, subject: subject, body: body)
    @mail.deliver_now

  end

Test Plan

Issue 1

Step 1: Navigate to Manage --> Assignment page.

Step 2: Click on add participants for any of the assignments.

Step 3: Click "Import course participants"

Step 4: Choose a csv file to be imported (follow the format given on the website).

Step 5: The users mentioned in the csv file and don't exist on Expertiza should get a new user email.

Step 6: To check e-mail is received or not, log in with following credentials: username [ 'expertiza.development@gmail.com' ] password [ 'qwer@1234' ].

Issue 2

Step 1: Create new assignment [Manage --> Assignment --> + Button (to create new assignment)]

Step 2: Fill the details for the assignments.

Step 3: Navigate to due dates.

Step 4: Change the number of review rounds to 2.

Step 5: Select "Yes" in the dropdown for review allowed during submission and select "Yes" for submission during the review.

Step 6: Add two users to the assignment(author and reviewer).

Step 7: Log in with some user credentials (author credential).

Step 8: Make a new submission to this assignment.

Step 9: Log in with another user (reviewer).

Step 10: Submit a review of the assignment submission.

Step 11: Login as an author again.

Step 12: Edit the submission.

Step 13: After this check the mailbox of the reviewer [development mail for development].

Step 14: Reviewer should get the mail to re-review the work.

Step 15: Change the due date to some date and time which has passed.

Step 16: Now making a new submission from the author account should not send a re-review mail to the reviewer. [Repeat steps 7-15].

Issue 3

This test requires an approaching deadline scenario. Since the reminder mail goes through as a sidekiq background, the part of this issue was to fix the email link.

Create a new scenario with an approaching deadline. The email is sent already, we have added the link which was missing, directing users to visit the required page.

Team Member Details

Team members :

  • Adarsh Trivedi (atrived)
  • Dheeraj Makam (drmakam)
  • Prachi Sheoran (psheora)