Feature/Staff Grant Extension - Complete Back-end work #77
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request provides the complete back‑end implementation for the Staff Grant Extension feature. It introduces a dedicated API that allows staff (tutors, convenors and admins) to grant extensions to one or more students on a given task directly from the Ontrack system. All UI/UX work is handled in a separate PR – this branch focuses on the API, model and mailer changes needed to support the new workflow.
What’s Included
New API for staff‑granted extensions
StaffGrantExtensionApiendpoint – A new Grape API mounted under/staff‑grant‑extension(and protected by existing authentication helpers). ThePOSTroute enables staff to grant extensions to multiple students without formal requests. The endpoint accepts a list of student IDs, a task identifier, the number of weeks to extend and a reason, and returns a result object listing successes and failures.ExtensionServiceoriginally used for student‑requested extensions, ensuring both staff and student flows use the same business rules and validations. This avoids duplication and keeps extension handling consistent across the codebase.Notifications system
Notificationmodel and underlying table with a relationship toUser. Notifications store a message, a target user and a read/unread status.Email delivery improvements
deliver_nowvs.deliver_later) and handle errors gracefully. A summary email is sent to the staff member listing all extensions granted and individual emails are sent to each student.config/environmentwill need to be updated with the proper SMTP details so that emails are actually sent.Refactoring and shared services
extension_comments_apito use a shared service so that both student and staff extension flows call the same business logic. This reduces duplication and improves maintainability.Type of change
Testing Checklist (the front‑end exercising this API serves as the primary way to verify functionality)
Checklist
Folders and Files Added/Modified
Added:
app/api/staff_grant_extension_api.rb– New Grape API withPOSTendpoint to grant extensions to multiple students.app/models/notification.rband associated migration – Defines theNotificationmodel and database table.app/api/notifications_api.rb– ProvidesGETandDELETEendpoints for notifications.Modified:
app/api/api_root.rb– Mounted theStaffGrantExtensionApiandNotificationsApiand added authentication hooks.app/services/extension_service.rb– Updated to support staff‑initiated extensions and reuse logic for student‑requested extensions.app/mailers/extension_mailer.rb– Corrected sender configuration, added summary email method and improved error handling.app/api/staff_grant_extension_api.rb– Updated in subsequent commits to refine email sending logic and handle race conditions.test/api/staff_grant_extension_test.rb) – Added new cases for multiple students and notifications; refactored to follow single‑quote conventions.Deleted: