Skip to content

Commit e872e14

Browse files
committed
Set default notification preferences for new users
Summary: We want some notifications enabled by default for users. Test Plan: - Create a new user - Ensure they have notification preferences set (currently all of them) Reviewers: sethetter Reviewed By: sethetter Differential Revision: https://phabricator.opengovfoundation.org/D180
1 parent bfbbccd commit e872e14

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

app/Models/NotificationPreference.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,13 @@ public static function removeNotificationForSponsor($event, $sponsor_id, $type =
194194
$notification->delete();
195195
}
196196
}
197+
198+
public static function setDefaultPreferences(User $user)
199+
{
200+
$events = NotificationPreference::getValidNotificationsForUser($user);
201+
202+
foreach ($events as $eventName => $eventClass) {
203+
NotificationPreference::addNotificationForUser($eventName, $user->id);
204+
}
205+
}
197206
}

app/Models/User.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use App\Models\Sponsor;
1717
use App\Models\SponsorMember;
1818
use App\Models\Role;
19+
use App\Models\NotificationPreference;
1920

2021
use DB;
2122

@@ -37,6 +38,15 @@ class User extends Authenticatable
3738
protected $fillable = ['fname', 'lname', 'email', 'password', 'token'];
3839
protected $appends = ['display_name'];
3940

41+
public static function boot()
42+
{
43+
parent::boot();
44+
45+
static::created(function($user) {
46+
NotificationPreference::setDefaultPreferences($user);
47+
});
48+
}
49+
4050
/**
4151
* getDisplayName.
4252
*

tests/Browser/UserTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ protected function notificationsSettingsViewOwnCommon($user)
171171
{
172172
$events = NotificationPreference::getValidNotificationsForUser($user);
173173

174-
foreach ($events as $eventName => $eventClass) {
175-
NotificationPreference::addNotificationForUser($eventName, $user->id);
176-
}
177-
178174
$this->browse(function ($browser) use ($user, $events) {
179175
$page = new NotificationsPage($user);
180176

0 commit comments

Comments
 (0)