Skip to content

Commit dac19fb

Browse files
joedixonStyleCIBot
andauthored
Fix forum overview sort order (#800)
* Make last_activity_at fillable * Remove command * Prevent replies to old threads * Apply fixes from StyleCI Co-authored-by: StyleCI Bot <[email protected]>
1 parent 86e7a85 commit dac19fb

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

Diff for: app/Console/Commands/UpdateThreadActivity.php

-29
This file was deleted.

Diff for: app/Http/Requests/CreateReplyRequest.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ public function rules()
2020

2121
public function replyAble(): ReplyAble
2222
{
23-
return $this->findReplyAble($this->get('replyable_id'), $this->get('replyable_type'));
23+
$replyable = $this->findReplyAble($this->get('replyable_id'), $this->get('replyable_type'));
24+
25+
abort_if(
26+
$replyable->isConversationOld(),
27+
403,
28+
'Last activity is too old',
29+
);
30+
31+
return $replyable;
2432
}
2533

2634
private function findReplyAble(int $id, string $type): ReplyAble

Diff for: app/Models/Thread.php

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ final class Thread extends Model implements Feedable, ReplyAble, SubscriptionAbl
5555
'body',
5656
'slug',
5757
'subject',
58+
'last_activity_at',
5859
];
5960

6061
/**

Diff for: tests/Feature/ForumTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,15 @@
228228
$this->visit("/forum/tags/{$tag->slug}?filter=something-invalid")
229229
->see('href="http://localhost/forum/tags/'.$tag->slug.'?filter=recent" aria-current="page"');
230230
});
231+
232+
test('thread activity is set when a new thread is created', function () {
233+
$this->login();
234+
235+
$this->post('/forum/create-thread', [
236+
'subject' => 'How to work with Eloquent?',
237+
'body' => 'This text explains how to work with Eloquent.',
238+
'tags' => [],
239+
]);
240+
241+
$this->assertNotNull(Thread::latest('id')->first()->last_activity_at);
242+
});

Diff for: tests/Feature/ReplyTest.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
->assertForbidden();
6666
});
6767

68-
test('users cannot reply to a thread if the last reply is older than six months', function () {
68+
test('users cannot see the option to reply if the latest activity is older than six months', function () {
6969
$thread = Thread::factory()->old()->create();
7070

7171
$this->login();
@@ -77,6 +77,18 @@
7777
);
7878
});
7979

80+
test('users cannot reply to a thread if the latest activity is older than six months', function () {
81+
$thread = Thread::factory()->old()->create();
82+
83+
$this->login();
84+
85+
$this->post('/replies', [
86+
'body' => 'The first reply',
87+
'replyable_id' => $thread->id,
88+
'replyable_type' => Thread::TABLE,
89+
])->assertForbidden();
90+
});
91+
8092
test('verified users can see the reply input', function () {
8193
$thread = Thread::factory()->create();
8294

0 commit comments

Comments
 (0)