Skip to content

Conversation

@SahiruWithanage
Copy link

@SahiruWithanage SahiruWithanage commented Apr 28, 2025

Description

Important Note:
This pull request depends on PR #56 (Staff Grant Extension).
The first few commits are from PR #56.
Please review only the changes related to the Notification System feature.

⚠️ This PR has been rebased onto the latest 9.x branch.


This pull request implements the backend notification system for the Staff Grant Extension feature in OnTrack.

When a tutor grants extensions to students through the Staff Grant Extension endpoint:

  • Students who have opted in to receive notifications are emailed about the task extension.
  • The tutor receives a summary email listing all affected students and the related task information.

The Staff Grant Extension API also returns additional notification-related information in its response, allowing the frontend to display in-platform notifications to students if preferred.

This enhancement improves communication between staff and students and prepares the system for frontend notification display.

The functionality was tested through a new test file: notifications_mailer_test.rb.

Related project: Staff Grant Extension - Backend Notification System

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactor (internal restructuring without changing behavior)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (update or new)

How Has This Been Tested?

The following tests have been written and run to verify correct behavior:

  • Tests in notifications_mailer_test.rb
  • Verified that emails are only sent to students who have opted in for notifications.
  • Verified that tutors receive the correct summary email with student list and task information.
  • Confirmed behavior with different student notification preferences.

Note: This is backend-only work. Frontend integration for in-app notification display is tracked separately.

Checklist

If involving code

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • My changes generate no new warnings

If modified config files

  • I have checked the following files for changes:
    • package.json
    • astro.config.mjs
    • netlify.toml
    • docker-compose.yml
    • custom.css

Folders and Files Added/Modified

Added:

  • app/views/notifications_mailer/extension_granted.html.erb
  • app/views/notifications_mailer/extension_granted.text.erb
  • test/mailers/notifications_mailer_test.rb

Modified:

  • app/api/staff_grant_extension_api.rb
  • app/mailers/notifications_mailer.rb
  • config/environments/test.rb

Additional Notes

  • Backend notification system prepares for frontend notification feature development.
  • No database schema changes were required.
  • No new external dependencies were added.

Copy link

@samindiii samindiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work Sahiru! The code is very easy to read (thanks to the comments) and meets all the functional requirements of the task :) I found one issue but its quite minor so should be an easy fix, let me know what you think!

end

# Set default from address using class methods
default from: -> { "#{self.class.doubtfire_product_name} <#{@granted_by&.email}>" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't @granted_by an instance variable, which means it's only set inside specific methods? I think when Rails loads the notification mailer class, this block is evaluated in the context of the notification class and not in the context of an individual email being sent.

I think @granted_by will be nil for each email and it might work if you just move the logic to each method.

Maybe you can add a test to check that the from: address is set correctly in the emails.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review, will be making these changes !!

@JoeMacl
Copy link

JoeMacl commented May 6, 2025

Everything looks great Sahiru! The backend notification system is well thought out and clearly tested. I only have one minor suggestion :)

params[:student_ids].count,
results[:failed],
true # is_staff_grant = true
).deliver_later
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To help with debugging failed emails, it might help to wrap this in a begin...rescue block and logging any errors in case deliver_later fails :)

Copy link
Author

@SahiruWithanage SahiruWithanage May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review, A good suggestion, I will make these changes!!

Sahiru Withanage and others added 4 commits May 11, 2025 14:05
Enable staff to grant extensions to multiple students without formal requests.
Reuse existing student extension logic through a new service for consistency.
Supports flexible academic support and streamlines staff workflows.

Relates to the OnTrack Staff Grant Extension design documentation.
…rpolated strings

This aligns the test file with the string formatting convention used in the rest of the codebase.
Single quotes are preferred when string interpolation is not needed, improving consistency.

Reviewed as part of peer feedback.
Linked extension_comments_api (student-requested extensions) to use the
shared ExtensionService, previously set up for staff-granted extensions.

This refactor ensures both student and staff extension flows use the
same logic, improving consistency and reducing duplication.
Implemented backend logic to send emails to tutor and student when extensions are granted. Also enable it so the front end can use the returned information from the api to display notifications.
@SahiruWithanage SahiruWithanage force-pushed the feature/extension-notification-system branch from dfb4e36 to c454932 Compare May 11, 2025 09:15
@SahiruWithanage
Copy link
Author

⚠️ Update: This PR has been rebased onto the latest 9.x branch.

A comment line change made in the staff grant extension feature branch that hasn't been updated here. Changing to keep the consistency.
@SahiruWithanage
Copy link
Author

@samindiii @JoeMacl Changes suggested have been made and tested. Thank you :)

@aNebula
Copy link

aNebula commented Jun 17, 2025

LGTM!
@SahiruWithanage Please open an upstream PR with these changes against doubtfire-lms/doubtfire-api 9.x branch.
Remember to include description and link the previous upstream PR (upstream of #56).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants