Skip to content

Commit 04461b5

Browse files
committed
add ExternalComplaintNotification
1 parent 2a6db8f commit 04461b5

3 files changed

Lines changed: 57 additions & 8 deletions

File tree

app/Http/Controllers/ComplaintController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Notifications\ExternalComplaintNotification;
56
use App\Notifications\ComplaintNotification;
67
use App\Rules\ReCaptchaValidation;
78
use Illuminate\Http\Request;
@@ -52,6 +53,19 @@ public function sendMessage(Request $request): \Illuminate\Http\JsonResponse
5253
)
5354
);
5455

56+
if (! empty($validated['mailAddress'])) {
57+
Notification::route('mail', [
58+
$validated['mailAddress'],
59+
])->notify(
60+
new ExternalComplaintNotification(
61+
$validated['offendingUrls'],
62+
$validated['reason'],
63+
$validated['name'],
64+
$validated['mailAddress'],
65+
)
66+
);
67+
}
68+
5569
return response()->json('Success', 200);
5670
}
5771

app/Notifications/ComplaintNotification.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ComplaintNotification extends Notification
2525
* @param string $mailAddress
2626
* @return void
2727
*/
28-
public function __construct($offendingUrls, $reason, $name='', $mailAddress='')
28+
public function __construct($offendingUrls, $reason, $name='None', $mailAddress='None')
2929
{
3030
$this->offendingUrls = $offendingUrls;
3131
$this->reason = $reason;
@@ -52,22 +52,19 @@ public function via($notifiable)
5252
*/
5353
public function toMail($notifiable)
5454
{
55-
$mailAddress = $this->mailAddress ? $this->mailAddress:'None';
56-
$name = $this->name ? $this->name:'None';
57-
5855
$mailFrom = config('app.complaint-mail-sender');
5956
$mailSubject = config('app.name') . ': Report of Illegal Content';
6057

6158
return (new MailMessage)
6259
->from($mailFrom)
6360
->subject($mailSubject)
6461
->line(Lang::get('A message via the wikibase.cloud form for reporting illegal content has been submitted.'))
65-
->line(Lang::get('Reporter name: ') . $name)
66-
->line(Lang::get('Reporter email address: ') . $mailAddress)
67-
->line(Lang::get('Reason:'))
62+
->line(Lang::get('Reporter name: ') . $this->name)
63+
->line(Lang::get('Reporter email address: ') . $this->mailAddress)
64+
->line(Lang::get('Reason why the information in question is illegal content:'))
6865
->line($this->reason)
6966
->line('---')
70-
->line(Lang::get('Reported URLs:'))
67+
->line(Lang::get('URL(s) for the content in question:'))
7168
->line($this->offendingUrls)
7269
->line('---');
7370
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\Notifications;
4+
5+
use App\Notifications\ComplaintNotification;
6+
use Illuminate\Notifications\Messages\MailMessage;
7+
use Illuminate\Support\Facades\Lang;
8+
9+
/**
10+
* A notification to be sent when the legal complaint form is being used.
11+
*/
12+
class ExternalComplaintNotification extends ComplaintNotification
13+
{
14+
/**
15+
* Build the mail representation of the notification.
16+
*
17+
* @param mixed $notifiable
18+
* @return \Illuminate\Notifications\Messages\MailMessage
19+
*/
20+
public function toMail($notifiable)
21+
{
22+
$mailFrom = config('app.complaint-mail-sender');
23+
$mailSubject = config('app.name') . ': Report of Illegal Content';
24+
25+
return (new MailMessage)
26+
->from($mailFrom)
27+
->subject($mailSubject)
28+
->line(Lang::get('Your message via the wikibase.cloud form for reporting illegal content has been submitted.'))
29+
->line(Lang::get('Name: ') . $this->name)
30+
->line(Lang::get('Email address: ') . $this->mailAddress)
31+
->line(Lang::get('Reason why the information in question is illegal content:'))
32+
->line($this->reason)
33+
->line('---')
34+
->line(Lang::get('URL(s) for the content in question:'))
35+
->line($this->offendingUrls)
36+
->line('---');
37+
}
38+
}

0 commit comments

Comments
 (0)