CSC/ECE 517 Fall 2019 - E1962. Email notification upon account creation

From Expertiza_Wiki
Jump to navigation Jump to search

E1962. Email notification upon account creation

Brief Introduction

In Expertiza, students and instructors are notified of various events by e-mail, e.g., creation of a new account, submission of a review on their work, or updating of work that they have reviewed. Students receives email whenever their account is created in system.

Background and Problem Statement

New users on Expertiza can be created by instructors directly from Users page or new user can also get created when added as an assignment participant but does not already exist in the system.


After creating an assignment, the instructor can add participants to it by two ways

  • Picking participants by their usernames OR By importing a csv file which lists the participants

If a user does not already exist in the system, then a new Expertiza account is created for the user and then added as a participant on the assignment. An email notification of account creation along with the user-ID and password must be sent to the user.


The following issue was identified in the current system

  • When students' accounts are created by importing a CSV file on the Users page, they receive e-mails with their user-ID and password.

However, if an account is created by adding them as participants to an assignment when they don't already have an account, e-mail notification is not being sent.

You can find the issue marked on github here.


Solution and code changes


File: app/models/assignment_participant.rb

The code in the below snippet previously had the flow as follows:

If user does not already exist in the system, then create new user account(if there is sufficient information about the user to create a new Expertiza account)

Add this user to the assignment as a participant.

If user already exists in the system, do nothing. If the user is already a participant on the assignment, do nothing.

The issue here was that an already existing user in the system will not get added as a participant on the assignment.


The code has been modified to facilitate the following flow:

If the user does not exist in the system, create new user account (if there is sufficient information about the user to create a new Expertiza account)

If the user already exists as a participant on the assignment, do nothing Add the user to the assignment as a participant; otherwise.

This way, the user(whether newly created or already an Expertiza user) gets added on the assignment as a participant.



File: app/models/assignment_participant.rb

Now that we have enabled the email functionality irrespective of where a new user is created from, we don't need to explicitly call the mailer from each location where new user is created.

Hence we disabled one such part of code where mailer was being called particularly at this location in the original implementation.



File: app/models/user.rb

Here, we enabled the email functionality by adding the .deliver_now method

This method invokes the mailer to deliver an email immediately.


Testing

Unit testing is not mentioned here because proposed implementation uses already existing mailer functionality for which test cases are already written. Below given file shows test cases for integration testing of this improvement.


File: spec/models/assignment_participant_spec.rb

While uploading participant list via a csv, for each new user created on expertiza, an email notification should be sent out.

This is a test case which checks the count of email after a new user has been created. The email count should be 1 in the case that a new valid user is created.



File: spec/models/participant_spec.rb


Initially, on being added to an assignment, the user would receive an email. However, no email notification was sent on new account creation.

Hence the total number of emails sent out was one, as per previous implementation.


Now that the email functionality has been added on account creation too, a total of two emails will be sent to new users added as participants - one for account creation and one for addition to assignment.

We modified the expected email count to accommodate this change.

How to test the changes

Follow these steps:-

(You can also watch the demonstration of the implementation here)


1. First, make a CSV file on your local system using the following format. You may skip the header.


2. Follow this link to the deployed application


3. Login with username 'instructor6' and password 'password'


4. Navigate to Manage -> Assignments


5. Click on 'Assignments'


6. For an assignment, select the action 'Add participants'


7. Click on import assignment participants


8. Upload the csv file created above


9. Confirm the participant list


TIP: To test fully, ensure that you have access to at least one of the email-ids mentioned in users listed in the csv. This way you can affirm the changes work when you receive an email notification as shown below.

Additional changes

In course of working on the issues listed in the scope of this project, we identified another bug in the system.

Issue: If a user already exists in the system and appears in the csv file while importing participants, then the code only checks that the user exists and moves ahead. However, the user is not added as a participant on that assignment.

Participants are being added to the assignment only when user does not exist in the system already and user is newly getting created.

Our Team

  1. Vishva Shah
  2. Urvish Vasani
  3. Hitarth Shah
  4. Sharique Khan(mentor)

Quick Links

To view the issue on github, click here

To visit our forked repo, click here

To test the implementation, click here

To view our pull request, click here

To watch a demo of the implementation, click here