diff --git a/app/Http/Controllers/FeedbackController.php b/app/Http/Controllers/FeedbackController.php index 5956160d4..e9788af66 100644 --- a/app/Http/Controllers/FeedbackController.php +++ b/app/Http/Controllers/FeedbackController.php @@ -2,9 +2,11 @@ namespace App\Http\Controllers; +use anlutro\LaravelSettings\Facade as Setting; use App\Models\Feedback; use App\Models\Position; use App\Models\User; +use App\Notifications\FeedbackNotification; use Illuminate\Http\Request; class FeedbackController extends Controller @@ -16,6 +18,11 @@ class FeedbackController extends Controller */ public function create() { + + if (! Setting::get('feedbackEnabled')) { + return redirect()->route('dashboard')->withErrors('Feedback is currently disabled.'); + } + $positions = Position::all(); $controllers = User::all(); @@ -29,6 +36,11 @@ public function create() */ public function store(Request $request) { + + if (! Setting::get('feedbackEnabled')) { + return redirect()->route('dashboard')->withErrors('Feedback is currently disabled.'); + } + $data = $request->validate([ 'position' => 'nullable|exists:positions,callsign', 'controller' => 'nullable|exists:users,id', @@ -48,6 +60,11 @@ public function store(Request $request) 'reference_position_id' => isset($position) ? $position->id : null, ]); + // Forward email if configured + if (Setting::get('feedbackForwardEmail')) { + $feedback->notify(new FeedbackNotification($feedback)); + } + return redirect()->route('dashboard')->with('success', 'Feedback submitted!'); } diff --git a/app/Mail/StaffNoticeMail.php b/app/Mail/StaffNoticeMail.php index 398603131..7047f3712 100644 --- a/app/Mail/StaffNoticeMail.php +++ b/app/Mail/StaffNoticeMail.php @@ -2,7 +2,6 @@ namespace App\Mail; -use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; @@ -13,25 +12,16 @@ class StaffNoticeMail extends Mailable private $mailSubject; - private $user; - private $textLines; /** * Create a new message instance. * - * @param Endorsement $endorsement - * @param array $textLines an array of markdown lines to add - * @param string $contactMail optional contact e-mail to put in footer - * @param string $actionUrl optinal action button url - * @param string $actionText optional action button text - * @param string $actionColor optional bootstrap button color override * @return void */ - public function __construct(string $mailSubject, User $user, array $textLines) + public function __construct(string $mailSubject, array $textLines) { $this->mailSubject = $mailSubject; - $this->user = $user; $this->textLines = $textLines; } diff --git a/app/Models/Feedback.php b/app/Models/Feedback.php index 06218973c..9f1c6dc1c 100644 --- a/app/Models/Feedback.php +++ b/app/Models/Feedback.php @@ -4,10 +4,12 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Notifications\Notifiable; class Feedback extends Model { use HasFactory; + use Notifiable; protected $guarded = []; diff --git a/app/Notifications/FeedbackNotification.php b/app/Notifications/FeedbackNotification.php new file mode 100644 index 000000000..0a6fc0bcd --- /dev/null +++ b/app/Notifications/FeedbackNotification.php @@ -0,0 +1,82 @@ +feedback = $feedback; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail', 'database']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return EndorsementMail + */ + public function toMail($notifiable) + { + + if (! Setting::get('feedbackEnabled')) { + return false; + } + + $position = isset($this->feedback->referencePosition) ? $this->feedback->referencePosition->callsign : 'N/A'; + $controller = isset($this->feedback->referenceUser) ? $this->feedback->referenceUser->name : 'N/A'; + + $textLines = [ + 'New feedback has been submitted by ' . $this->feedback->submitter->name . ' (' . $this->feedback->submitter->id . ').', + '*You can reply to this email to respond directly.*', + '- **Controller**: ' . $controller, + '- **Position**: ' . $position, + '### Feedback', + $this->feedback->feedback, + + ]; + + $feedbackForward = Setting::get('feedbackForwardEmail'); + + return (new StaffNoticeMail('Feedback submited', $textLines)) + ->to($feedbackForward) + ->replyTo($this->feedback->submitter->email, $this->feedback->submitter->name); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return []; + } +} diff --git a/app/Notifications/InactiveOnlineStaffNotification.php b/app/Notifications/InactiveOnlineStaffNotification.php index 184a63f4f..8aeff90b1 100644 --- a/app/Notifications/InactiveOnlineStaffNotification.php +++ b/app/Notifications/InactiveOnlineStaffNotification.php @@ -60,7 +60,7 @@ public function toMail($notifiable) 'All admins and moderators in area in question has been notified.', ]; - return (new StaffNoticeMail('Unauthorized network logon recorded', $this->user, $textLines)) + return (new StaffNoticeMail('Unauthorized network logon recorded', $textLines)) ->to($this->sendTo->pluck('email')); }