forked from source-academy/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Avenger Backlog Notifications (source-academy#932)
* Create NotificationType Model - Create Notifications module and NotificationType model - Start migration for adding notifications - No functionalities added yet only template code * Configure Oban and Bamboo for notifications system * Create NotificationConfig Model * Create TimeOption Model * Create NotificationPreference Model * Create SentNotification Model * Add Email Field to User Model * fix: Fix Oban configuration * chore: Add dependency on bamboo_phoenix for email template rendering * feat: Implement Oban job for avenger backlog emails * chore: Prevent browser from opening automatically when a local email is sent * Add migrations for notification triggers and avenger backlog notification entry * Implement notification configuration checks * Fix formatting errors * fix: Fix notifications schema typos Changes: * Replaced is_enable to is_enabled for Notification Preferences * Update default is_enabled to true for Notifcation Types * fix: Fix test configurations not being applied `import_config` must always appear at the bottom for environment specific configurations to be applied correctly. All configurations after this line will overwrite configurations that exists in the environment specific ones. * chore: remove unused controllers and views - remove auto-generated controllers and views that are not used * chore: Add tests for notifications * chore: Add test for avenger backlog email * chore: Resolve style violations * chore: Resolve style violations * chore: Resolve style violations * style: fix formatting * fix: Fix bad refactoring * fix: Fix testing environment with Oban and Bamboo * test: add tests for notification types * test: add tests for time options * chore: Update constraints and changesets for notification models * chore: Update default behaviour for no time_option in user preference If user preference has no time option, use the time_option from notification_config instead. This is so that the behaviour of these users with no preferences would always follow the default chosen by the course admin * style: fix formatting * test: add tests for sent notifications * Add tests for notifications module * fix: Fix testing with Oban Oban introduced changes to testing in v2.12, this commit changes the old test configurations to the new one recommended by official docs. * Add more tests for notifications module * test: add tests for NotificationWorker * style: fix formatting * style: fix formatting * style: fix formatting * fix: Fix tests under notification types name constraints * feat: Implement job for assessment submission mail * fix: Fix assessment submission worker * chore: Add test for assessment submission * chore: Add migration to populate existing nus users' emails Current nus users will have their email attribute populated based on their username. nus users are identified from the provider attribute. Future nus users will have their email attribute populated on creation ideally. * feat: implement sent_notifications - move mailing logic to notification worker - insert into sent_notifications when email is sent out successfully * fix: fix tests * style: fix formatting * fix: fix guard clauses - move guard clauses to prevent unnecessary querying * fix: Fix db triggers not running for assessment submission notifications --------- Co-authored-by: Goh Jun Yi <[email protected]> Co-authored-by: Martin Henz <[email protected]>
- Loading branch information
1 parent
6837435
commit ed7f772
Showing
53 changed files
with
1,892 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Cadet.Email do | ||
@moduledoc """ | ||
Contains methods for sending email notifications. | ||
""" | ||
use Bamboo.Phoenix, view: CadetWeb.EmailView | ||
import Bamboo.Email | ||
|
||
def avenger_backlog_email(template_file_name, avenger, ungraded_submissions) do | ||
if is_nil(avenger.email) do | ||
nil | ||
else | ||
base_email() | ||
|> to(avenger.email) | ||
|> assign(:avenger_name, avenger.name) | ||
|> assign(:submissions, ungraded_submissions) | ||
|> subject("Backlog for #{avenger.name}") | ||
|> render("#{template_file_name}.html") | ||
end | ||
end | ||
|
||
def assessment_submission_email(template_file_name, avenger, student, submission) do | ||
if is_nil(avenger.email) do | ||
nil | ||
else | ||
base_email() | ||
|> to(avenger.email) | ||
|> assign(:avenger_name, avenger.name) | ||
|> assign(:student_name, student.name) | ||
|> assign(:assessment_title, submission.assessment.title) | ||
|> subject("New submission for #{submission.assessment.title}") | ||
|> render("#{template_file_name}.html") | ||
end | ||
end | ||
|
||
defp base_email do | ||
new_email() | ||
|> from("[email protected]") | ||
|> put_html_layout({CadetWeb.LayoutView, "email.html"}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# credo:disable-for-this-file Credo.Check.Readability.ModuleDoc | ||
# @moduledoc is actually generated by a macro inside Quantum | ||
defmodule Cadet.Jobs.Scheduler do | ||
@moduledoc """ | ||
Quantum is used for scheduling jobs with cron jobs. | ||
""" | ||
use Quantum, otp_app: :cadet | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
defmodule Cadet.Mailer do | ||
@moduledoc """ | ||
Mailer used to sent notification emails. | ||
""" | ||
use Bamboo.Mailer, otp_app: :cadet | ||
end |
Oops, something went wrong.