Repository navigation
fix(notifications): resolve notification settings from the notified company - #274
Merged
Merged
Conversation
…ompany NotificationRegistry::notify() read company settings from the session, but it is called from queued listeners and console commands, which have no session. Settings -> Notifications was therefore ignored whenever the queue ran in its own worker. notifyUsingDefinitionName() read the global notification_settings key, which the console never writes. Both now take the company from the notification parameters (a company, or a model with a company_uuid) and fall back to the session. Adds Setting::lookupForCompany() for looking up a company setting without a session. Closes #262 (cherry picked from commit 9c24673e7677c53d8d6adf01eb6b5ae98c40fb2c)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #274 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 7499 7506 +7
===========================================
Files 430 430
Lines 24488 24502 +14
===========================================
+ Hits 24488 24502 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merged
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #262.
Why
NotificationRegistry::notify()read the company's notification settings withSetting::lookupCompany(), which returns nothing when there is nosession('company'). Its callers have no session:Fleetbase\FleetOps\Listeners\NotifyOrderEventisShouldQueue, so it runs in the queue worker.ProcessOperationalAlertsis a console command.So whenever the queue runs as its own process (including the documented docker-compose setup), everything configured in Settings → Notifications was silently ignored.
notifyUsingDefinitionName()(used by Flespi) had a second problem: it read the globalnotification_settingskey, but the console only ever writescompany.<uuid>.notification_settings, so it never found any settings, even with a session.What changed
resolveNotificationSettings(). It takes the company from the notification parameters: aCompany, or the first model with acompany_uuid. It falls back to the session only when no parameter carries a company.Setting::lookupForCompany($companyUuid, $key, $default)for reading a company setting without a session.lookupFromCompany()now delegates to it.Verification
Companyparameter is resolved;notifyUsingDefinitionNametests move from the global key to the company-scoped one. These tests and the new ones fail without the fix.[], and the new one returned the company's settings.