-
Notifications
You must be signed in to change notification settings - Fork 9
feat: notifications for new engagements (resolves #2562) #2604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a5982e4
feat: engagement notifications setting for individuals and orgs
jobara e8aaace
fix: user registration error when 'notifications_setting' not present
jobara f6e7023
fix: remove unnecessary nav section for org notifications settings page
jobara 85630b4
fix: removed commented out markup
jobara 3fb544a
feat: send notifications for new engagements
jobara 34a760a
chore: run localization
jobara 98ef7d2
style: fix analysis issues
jobara 95a821c
Merge branch 'dev' into GH-2562
jobara f84e875
test: fix randomly failing test
jobara c04ce70
Merge branch 'dev' into GH-2562
jobara 68517bd
style: remove commented code and clean up get formatting in tests
jobara a9f4c20
test: expand tests for engagement notifications and organizations
jobara 73cacd7
Merge branch 'dev' into GH-2562
jobara 305043c
Merge branch 'dev' into GH-2562
jobara 4fefb1a
feat: console command for migrating data that can't be done in a db m…
jobara e4626be
style: satisfying static analysis errors
jobara 31d9197
refactor: simplified list output and added tests
jobara 99d40a1
docs: added documentation for app:migrate-settings-data console comma…
jobara 1a24e0b
ci: run app:migrate-settings-data as part of deploy
jobara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\Organization; | ||
use App\Models\User; | ||
use Exception; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Contracts\Console\Isolatable; | ||
|
||
use function Termwind\render; | ||
|
||
class MigrateSettingsData extends Command implements Isolatable | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:migrate-settings-data | ||
{--list : lists out available migrations} | ||
{--from=1.6.0 : when running all migrations, indicate which version the application is being migrated from. Previous migrations will be skipped.} | ||
{--migration= : a specific migration to run}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Migrates settings data that is not performed by database migrations; such as modifying the contents of database fields.'; | ||
|
||
protected $migrations = [ | ||
'EnableEngagementNotifications' => [ | ||
'version' => '1.7.0', | ||
'handler' => 'enableEngagementNotificationsMigration', | ||
'description' => 'Replaces older format of notifications_settings with only ["engagements" => "1"]. Setting the engagement notifications on be default. If the notifications_settings contains a valid engagements setting, then no changes are made.', | ||
], | ||
]; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$verbose = $this->options()['verbose']; | ||
Check failure on line 45 in app/Console/Commands/MigrateSettingsData.php
|
||
|
||
if ($this->options()['list']) { | ||
|
||
$this->listMigrations($this->migrations); | ||
|
||
return 0; | ||
} | ||
|
||
if ($this->options()['migration']) { | ||
try { | ||
$migration = $this->migrations[$this->options()['migration']]; | ||
} catch (Exception $e) { | ||
$this->fail('Could not find migration: '.$this->options()['migration']); | ||
} | ||
|
||
if (isset($migration)) { | ||
$handler = $migration['handler']; | ||
$this->$handler(); | ||
|
||
return 0; | ||
} | ||
} | ||
|
||
$this->runMigrations($this->migrations, $this->options()['from'], $verbose); | ||
} | ||
|
||
public function listMigrations($migrations) | ||
{ | ||
$definitions = ''; | ||
|
||
foreach ($migrations as $name => $migration) { | ||
$version = $migration['version']; | ||
$description = $migration['description']; | ||
$definitions .= "<dt>$name</dt><dd>Version added: $version</dd><dd class=\"pb-1\">$description</dd>"; | ||
} | ||
|
||
render(<<<HTML | ||
<dl> | ||
$definitions | ||
</dl> | ||
HTML); | ||
} | ||
|
||
public function runMigrations($migrations, $from = '1.6.0', $verbose = false) | ||
{ | ||
$from = str_starts_with($from, 'v') || str_starts_with($from, 'V') ? substr($from, 1) : $from; | ||
$migrationRunCount = 0; | ||
|
||
foreach ($migrations as $name => $migration) { | ||
if (version_compare($from, $migration['version'], '<')) { | ||
if ($verbose) { | ||
$this->line("<fg=cyan>Run migration - $name</>"); | ||
} | ||
$handler = $migration['handler']; | ||
$this->$handler($verbose); | ||
$migrationRunCount++; | ||
} elseif ($verbose) { | ||
$this->comment("Skipped migration - $name"); | ||
} | ||
|
||
if ($verbose) { | ||
$this->newLine(); | ||
} | ||
} | ||
|
||
$this->line('<options=bold;fg=green>Completed '.$migrationRunCount.'</>'); | ||
$this->line('<options=bold;fg=yellow>Skipped '.(count($migrations) - $migrationRunCount).'</>'); | ||
} | ||
|
||
// Migrations | ||
|
||
public function enableEngagementNotificationsMigration($verbose = false) | ||
{ | ||
$updatedNotificationSettings = ['engagements' => '1']; | ||
|
||
if ($verbose) { | ||
$this->info(' - Migrating engagement notifications for users'); | ||
} | ||
|
||
$users = User::where('context', 'individual')->whereNull('notification_settings->engagements') | ||
->get(); | ||
|
||
$users->each(function ($user) use ($updatedNotificationSettings) { | ||
$user->notification_settings = $updatedNotificationSettings; | ||
$user->save(); | ||
}); | ||
|
||
if ($verbose) { | ||
$this->info(' - Migrated '.$users->count().' users'); | ||
$this->info(' - Migrating engagement notification settings for Organizations'); | ||
} | ||
|
||
$orgs = Organization::whereNull('notification_settings->engagements') | ||
->get(); | ||
|
||
$orgs->each(function ($organization) use ($updatedNotificationSettings) { | ||
$organization->notification_settings = $updatedNotificationSettings; | ||
$organization->save(); | ||
}); | ||
|
||
if ($verbose) { | ||
$this->info(' - Migrated '.$orgs->count().' Organizations'); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
enum YesNo: string | ||
{ | ||
case Yes = '1'; | ||
case No = '0'; | ||
|
||
public static function labels(): array | ||
{ | ||
return [ | ||
'1' => __('Yes'), | ||
'0' => __('No'), | ||
]; | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.