forked from Silvanite/novatoolpermissions
-
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.
Merge pull request #86 from SGS-Optimisation/main
fixes Silvanite#58 flagged rule notifications
- Loading branch information
Showing
22 changed files
with
445 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Features\Rules\FlaggedCollector; | ||
use App\Models\User; | ||
use App\Notifications\FlaggedRulesReminderNotification; | ||
use Illuminate\Console\Command; | ||
|
||
class FlaggedRulesReminder extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'rules:flagged:remind'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Send reminders about flagged rules to their contributors'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle() | ||
{ | ||
$flagged_collector = (new FlaggedCollector)->handle(); | ||
|
||
foreach($flagged_collector->users_rules_dict as $user_id => $user_rules_list) { | ||
/** @var User $user */ | ||
$user = $user_rules_list['user']; | ||
$this->info('notifying ' . $user->name); | ||
|
||
$user->notify(new FlaggedRulesReminderNotification($user_rules_list['rules'])); | ||
|
||
} | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
|
||
namespace App\Features\Rules; | ||
|
||
|
||
use App\Features\BaseFeature; | ||
use App\Models\Rule; | ||
|
||
class FlaggedCollector extends BaseFeature | ||
{ | ||
public $users_rules_dict; | ||
|
||
public function handle() | ||
{ | ||
$rules = Rule::isFlagged()->with(['contributors'])->get(); | ||
$users_rules_dict = []; | ||
|
||
foreach ($rules as $rule) { | ||
foreach ($rule->contributors as $contributor) { | ||
if (!isset($users_rules_dict[$contributor->id])) { | ||
$users_rules_dict[$contributor->id] = [ | ||
'user' => $contributor, | ||
'rules' => [], | ||
]; | ||
} | ||
|
||
$users_rules_dict[$contributor->id]['rules'][] = $rule; | ||
|
||
} | ||
} | ||
|
||
$this->users_rules_dict = $users_rules_dict; | ||
|
||
return $this; | ||
} | ||
|
||
} |
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
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,76 @@ | ||
<?php | ||
|
||
namespace App\Notifications; | ||
|
||
use App\Models\Rule; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Notifications\Notification; | ||
use Illuminate\Support\HtmlString; | ||
use Illuminate\Support\Str; | ||
|
||
class FlaggedRuleNotification extends Notification | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* Create a new notification instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(public Rule $rule) | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Get the notification's delivery channels. | ||
* | ||
* @param mixed $notifiable | ||
* @return array | ||
*/ | ||
public function via($notifiable) | ||
{ | ||
return ['mail']; | ||
} | ||
|
||
/** | ||
* Get the mail representation of the notification. | ||
* | ||
* @param mixed $notifiable | ||
* @return \Illuminate\Notifications\Messages\MailMessage | ||
*/ | ||
public function toMail($notifiable) | ||
{ | ||
$rule = $this->rule; | ||
$last_reason_key = array_key_last($rule->metadata['flag_reason']); | ||
$flag_reason = $rule->metadata['flag_reason'][$last_reason_key]; | ||
|
||
$subject = 'Rule flagged: '.Str::limit($rule->name, 20); | ||
|
||
return (new MailMessage) | ||
->greeting('Hello '.$notifiable->given_name) | ||
->subject($subject) | ||
->line('The following flagged rule needs your attention:') | ||
->line(new HtmlString( | ||
sprintf('<p><a href="%s">%s</a><br>The flag reason was: "%s" (%s on %s)</p><br>', | ||
$rule->url, '['.$rule->dag_id.'] '.$rule->name, | ||
$flag_reason['reason'], $flag_reason['user'], $flag_reason['date'] | ||
) | ||
))->salutation(new HtmlString('Regards,<br>The Dagobah Team')); | ||
} | ||
|
||
/** | ||
* Get the array representation of the notification. | ||
* | ||
* @param mixed $notifiable | ||
* @return array | ||
*/ | ||
public function toArray($notifiable) | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
Oops, something went wrong.