Skip to content

Commit 497dd06

Browse files
committed
feat: LAR 10 Send a Telegram notification for articles that are submitted but neither approved nor declined.
1 parent 98a7afd commit 497dd06

16 files changed

+57
-57
lines changed

app/Console/Commands/NotifyPendingArticles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ public function handle(AnonymousNotifiable $notifiable): void
2323
$notifiable->notify(new PendingArticlesNotification($pendingArticles));
2424
}
2525
}
26-
}
26+
}

app/Console/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ protected function commands(): void
3131
{
3232
$this->load(__DIR__.'/Commands');
3333
}
34-
}
34+
}

app/Http/Kernel.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ final class Kernel extends HttpKernel
1010
{
1111
protected $middleware = [
1212
// \App\Http\Middleware\TrustHosts::class,
13-
\App\Http\Middleware\TrustProxies::class,
14-
\App\Http\Middleware\HttpsProtocol::class,
13+
Middleware\TrustProxies::class,
14+
Middleware\HttpsProtocol::class,
1515
\Illuminate\Http\Middleware\HandleCors::class,
16-
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
16+
Middleware\PreventRequestsDuringMaintenance::class,
1717
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
18-
\App\Http\Middleware\TrimStrings::class,
18+
Middleware\TrimStrings::class,
1919
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
2020
];
2121

2222
protected $middlewareGroups = [
2323
'web' => [
24-
\App\Http\Middleware\EncryptCookies::class,
24+
Middleware\EncryptCookies::class,
2525
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
2626
\Illuminate\Session\Middleware\StartSession::class,
2727
// \Illuminate\Session\Middleware\AuthenticateSession::class,
2828
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
29-
\App\Http\Middleware\VerifyCsrfToken::class,
29+
Middleware\VerifyCsrfToken::class,
3030
\Illuminate\Routing\Middleware\SubstituteBindings::class,
3131
],
3232

@@ -38,11 +38,11 @@ final class Kernel extends HttpKernel
3838
];
3939

4040
protected $routeMiddleware = [
41-
'auth' => \App\Http\Middleware\Authenticate::class,
41+
'auth' => Middleware\Authenticate::class,
4242
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
4343
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
4444
'can' => \Illuminate\Auth\Middleware\Authorize::class,
45-
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
45+
'guest' => Middleware\RedirectIfAuthenticated::class,
4646
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
4747
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
4848
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,

app/Models/Thread.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function scopeUnresolved(Builder $query): Builder
191191
* Scope for filtering threads.
192192
*
193193
* @param Builder<Thread> $builder
194-
* @param \Illuminate\Http\Request $request
194+
* @param Request $request
195195
* @param string[] $filters
196196
* @return Builder<Thread>
197197
*/

app/Models/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public function scopeHasActivity(Builder $query): Builder
353353
/**
354354
* Route notifications for the Slack channel.
355355
*
356-
* @param \Illuminate\Notifications\Notification $notification
356+
* @param Notification $notification
357357
* @return string
358358
*/
359359
public function routeNotificationForSlack(Notification $notification): string

app/Notifications/PendingArticlesNotification.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
use Illuminate\Bus\Queueable;
88
use Illuminate\Notifications\Notification;
9-
use Illuminate\Contracts\Queue\ShouldQueue;
109
use Illuminate\Database\Eloquent\Collection;
11-
use Illuminate\Notifications\Messages\MailMessage;
1210
use NotificationChannels\Telegram\TelegramChannel;
1311
use NotificationChannels\Telegram\TelegramMessage;
1412

1513
final class PendingArticlesNotification extends Notification
1614
{
1715
use Queueable;
1816

19-
public function __construct(public Collection $pendingArticles) {}
17+
public function __construct(public Collection $pendingArticles)
18+
{
19+
}
2020

2121
public function via(mixed $notifiable): array
2222
{
@@ -37,7 +37,7 @@ private function content(): string
3737
$message = __("Pending approval articles:\n");
3838
foreach ($this->pendingArticles as $article) {
3939
$url = route('articles.show', $article->slug);
40-
40+
4141
$message .= __("• Title: [:title](:url)\n", [
4242
'title' => $article->title,
4343
'url' => $url,
@@ -55,4 +55,4 @@ private function content(): string
5555

5656
return $message;
5757
}
58-
}
58+
}

app/helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ function getFilter(string $key, array $filters = [], string $default = 'recent')
9191
/**
9292
* Returns the route for the replyAble.
9393
*
94-
* @param \App\Models\Thread|\App\Models\Discussion $replyAble
94+
* @param App\Models\Thread|App\Models\Discussion $replyAble
9595
* @return string
9696
*/
9797
function route_to_reply_able(mixed $replyAble): string
9898
{
99-
return $replyAble instanceof \App\Models\Thread ?
99+
return $replyAble instanceof App\Models\Thread ?
100100
route('forum.show', $replyAble->slug()) :
101101
route('discussions.show', $replyAble->slug());
102102
}

config/gamify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
return [
66
// Model which will be having points, generally it will be User
7-
'payee_model' => \App\Models\User::class,
7+
'payee_model' => App\Models\User::class,
88

99
// Reputation model
1010
'reputation_model' => '\QCod\Gamify\Reputation',

config/livewire-ui-spotlight.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@
3131
*/
3232

3333
'commands' => [
34-
\App\Spotlight\Article::class,
35-
\App\Spotlight\Articles::class,
36-
\App\Spotlight\Discussion::class,
37-
\App\Spotlight\Discussions::class,
38-
\App\Spotlight\FAQs::class,
39-
\App\Spotlight\Forum::class,
40-
\App\Spotlight\Guides::class,
41-
\App\Spotlight\Slack::class,
42-
\App\Spotlight\Sujet::class,
43-
\App\Spotlight\Telegram::class,
44-
\App\Spotlight\User::class,
34+
App\Spotlight\Article::class,
35+
App\Spotlight\Articles::class,
36+
App\Spotlight\Discussion::class,
37+
App\Spotlight\Discussions::class,
38+
App\Spotlight\FAQs::class,
39+
App\Spotlight\Forum::class,
40+
App\Spotlight\Guides::class,
41+
App\Spotlight\Slack::class,
42+
App\Spotlight\Sujet::class,
43+
App\Spotlight\Telegram::class,
44+
App\Spotlight\User::class,
4545
],
4646

4747
/*

config/permission.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
* When permissions or roles are updated the cache is flushed automatically.
138138
*/
139139

140-
'expiration_time' => \DateInterval::createFromDateString('24 hours'),
140+
'expiration_time' => DateInterval::createFromDateString('24 hours'),
141141

142142
/*
143143
* The cache key used to store all permissions.

database/migrations/2021_09_14_172248_create_permission_tables.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public function up(): void
1616
$teams = config('permission.teams');
1717

1818
if (empty($tableNames)) {
19-
throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
19+
throw new Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
2020
}
2121
if ($teams && empty($columnNames['team_foreign_key'] ?? null)) {
22-
throw new \Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
22+
throw new Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
2323
}
2424

2525
Schema::create($tableNames['permissions'], function (Blueprint $table): void {
@@ -128,7 +128,7 @@ public function down(): void
128128
$tableNames = config('permission.table_names');
129129

130130
if (empty($tableNames)) {
131-
throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
131+
throw new Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
132132
}
133133

134134
Schema::drop($tableNames['role_has_permissions']);

database/migrations/2021_11_04_094343_create_views_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class CreateViewsTable extends Migration
1111
/**
1212
* The database schema.
1313
*
14-
* @var \Illuminate\Support\Facades\Schema
14+
* @var Schema
1515
*/
1616
protected $schema;
1717

helpers/ModelHelper.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @property \Illuminate\Support\Carbon|null $created_at
2525
* @property \Illuminate\Support\Carbon|null $updated_at
2626
* @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $subject
27-
* @property-read \App\Models\User $user
27+
* @property-read User $user
2828
* @method static \Database\Factories\ActivityFactory factory($count = null, $state = [])
2929
* @method static \Illuminate\Database\Eloquent\Builder|Activity newModelQuery()
3030
* @method static \Illuminate\Database\Eloquent\Builder|Activity newQuery()
@@ -74,7 +74,7 @@ final class IdeHelperActivity
7474
* @property-read int|null $reactions_count
7575
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Tag> $tags
7676
* @property-read int|null $tags_count
77-
* @property-read \App\Models\User $user
77+
* @property-read User $user
7878
* @property-read \Illuminate\Database\Eloquent\Collection<int, \CyrildeWit\EloquentViewable\View> $views
7979
* @property-read int|null $views_count
8080
* @method static \Illuminate\Database\Eloquent\Builder|Article approved()
@@ -176,7 +176,7 @@ final class IdeHelperChannel
176176
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activity
177177
* @property-read int|null $activity_count
178178
* @property-read int $count_all_replies_with_child
179-
* @property-read \App\Models\Reply|null $latestReply
179+
* @property-read Reply|null $latestReply
180180
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Reaction> $reactions
181181
* @property-read int|null $reactions_count
182182
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Reply> $replies
@@ -185,7 +185,7 @@ final class IdeHelperChannel
185185
* @property-read int|null $subscribes_count
186186
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Tag> $tags
187187
* @property-read int|null $tags_count
188-
* @property-read \App\Models\User $user
188+
* @property-read User $user
189189
* @property-read \Illuminate\Database\Eloquent\Collection<int, \CyrildeWit\EloquentViewable\View> $views
190190
* @property-read int|null $views_count
191191
* @method static \Illuminate\Database\Eloquent\Builder|Discussion active()
@@ -241,7 +241,7 @@ final class IdeHelperDiscussion
241241
* @property \Illuminate\Support\Carbon|null $updated_at
242242
* @property-read \Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection<int, \Spatie\MediaLibrary\MediaCollections\Models\Media> $media
243243
* @property-read int|null $media_count
244-
* @property-read \App\Models\User $owner
244+
* @property-read User $owner
245245
* @method static \Illuminate\Database\Eloquent\Builder|Enterprise certified()
246246
* @method static \Database\Factories\EnterpriseFactory factory($count = null, $state = [])
247247
* @method static \Illuminate\Database\Eloquent\Builder|Enterprise featured()
@@ -491,8 +491,8 @@ final class IdeHelperSubscription
491491
* @property \Illuminate\Support\Carbon|null $created_at
492492
* @property \Illuminate\Support\Carbon|null $updated_at
493493
* @property \Illuminate\Support\Carbon|null $deleted_at
494-
* @property-read \App\Models\Premium\Feature $feature
495-
* @property-read \App\Models\Premium\Subscription $subscription
494+
* @property-read Feature $feature
495+
* @property-read Subscription $subscription
496496
* @method static \Illuminate\Database\Eloquent\Builder|PlanSubscriptionUsage byFeatureSlug(string $featureSlug)
497497
* @method static \Illuminate\Database\Eloquent\Builder|SubscriptionUsage newModelQuery()
498498
* @method static \Illuminate\Database\Eloquent\Builder|SubscriptionUsage newQuery()
@@ -559,8 +559,8 @@ final class IdeHelperReaction
559559
* @property-read \Illuminate\Database\Eloquent\Collection<int, Reply> $replies
560560
* @property-read int|null $replies_count
561561
* @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $replyAble
562-
* @property-read \App\Models\Thread|null $solutionTo
563-
* @property-read \App\Models\User $user
562+
* @property-read Thread|null $solutionTo
563+
* @property-read User $user
564564
* @method static \Database\Factories\ReplyFactory factory($count = null, $state = [])
565565
* @method static \Illuminate\Database\Eloquent\Builder|Reply isSolution()
566566
* @method static \Illuminate\Database\Eloquent\Builder|Reply newModelQuery()
@@ -621,7 +621,7 @@ final class IdeHelperSocialAccount
621621
* @property \Illuminate\Support\Carbon|null $created_at
622622
* @property \Illuminate\Support\Carbon|null $updated_at
623623
* @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $subscribeAble
624-
* @property-read \App\Models\User $user
624+
* @property-read User $user
625625
* @method static \Illuminate\Database\Eloquent\Builder|Subscribe newModelQuery()
626626
* @method static \Illuminate\Database\Eloquent\Builder|Subscribe newQuery()
627627
* @method static \Illuminate\Database\Eloquent\Builder|Subscribe query()
@@ -684,18 +684,18 @@ final class IdeHelperTag
684684
* @property-read int|null $activity_count
685685
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Channel> $channels
686686
* @property-read int|null $channels_count
687-
* @property-read \App\Models\Reply|null $latestReply
687+
* @property-read Reply|null $latestReply
688688
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
689689
* @property-read int|null $notifications_count
690690
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Reaction> $reactions
691691
* @property-read int|null $reactions_count
692692
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Reply> $replies
693693
* @property-read int|null $replies_count
694-
* @property-read \App\Models\User|null $resolvedBy
695-
* @property-read \App\Models\Reply|null $solutionReply
694+
* @property-read User|null $resolvedBy
695+
* @property-read Reply|null $solutionReply
696696
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Subscribe> $subscribes
697697
* @property-read int|null $subscribes_count
698-
* @property-read \App\Models\User $user
698+
* @property-read User $user
699699
* @property-read \Illuminate\Database\Eloquent\Collection<int, \CyrildeWit\EloquentViewable\View> $views
700700
* @property-read int|null $views_count
701701
* @method static \Illuminate\Database\Eloquent\Builder|Thread active()
@@ -744,7 +744,7 @@ final class IdeHelperThread
744744
* @property array|null $metadata
745745
* @property \Illuminate\Support\Carbon|null $created_at
746746
* @property \Illuminate\Support\Carbon|null $updated_at
747-
* @property-read \App\Models\User $user
747+
* @property-read User $user
748748
* @method static \Illuminate\Database\Eloquent\Builder|Transaction complete()
749749
* @method static \Illuminate\Database\Eloquent\Builder|Transaction newModelQuery()
750750
* @method static \Illuminate\Database\Eloquent\Builder|Transaction newQuery()
@@ -803,7 +803,7 @@ final class IdeHelperTransaction
803803
* @property-read int|null $badges_count
804804
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Discussion> $discussions
805805
* @property-read int|null $discussions_count
806-
* @property-read \App\Models\Enterprise|null $enterprise
806+
* @property-read Enterprise|null $enterprise
807807
* @property-read \Illuminate\Database\Eloquent\Collection<int, \LaravelFeature\Model\Feature> $features
808808
* @property-read int|null $features_count
809809
* @property-read bool $is_sponsor

tests/Feature/NotifyPendingArticlesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Illuminate\Notifications\AnonymousNotifiable;
99
use Illuminate\Support\Facades\Notification;
1010

11-
beforeEach(fn() => Notification::fake());
11+
beforeEach(fn () => Notification::fake());
1212

1313
it('will send a notification when there are pending articles', function (): void {
1414
Article::factory()->createMany([
@@ -32,7 +32,7 @@
3232
Notification::assertSentTo(
3333
new AnonymousNotifiable(),
3434
PendingArticlesNotification::class,
35-
fn($notification) => $notification->pendingArticles->count() === 1
35+
fn ($notification) => $notification->pendingArticles->count() === 1
3636
);
3737

3838
Notification::assertCount(1);
@@ -55,4 +55,4 @@
5555

5656
Notification::assertNothingSent();
5757
Notification::assertCount(0);
58-
});
58+
});

tests/Integration/DiscussionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@
6969

7070
// When providing a slug with invalid url characters, a random 5 character string is returned.
7171
expect($discussion->slug())->toMatch('/\w{5}/');
72-
});
72+
});

tests/Integration/ThreadTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,4 @@ function createActiveThread(): Thread
187187
$reply->save();
188188

189189
return $thread;
190-
}
190+
}

0 commit comments

Comments
 (0)