Skip to content

Fix forum overview sort order #800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions app/Console/Commands/UpdateThreadActivity.php

This file was deleted.

10 changes: 9 additions & 1 deletion app/Http/Requests/CreateReplyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ public function rules()

public function replyAble(): ReplyAble
{
return $this->findReplyAble($this->get('replyable_id'), $this->get('replyable_type'));
$replyable = $this->findReplyAble($this->get('replyable_id'), $this->get('replyable_type'));

abort_if(
$replyable->isConversationOld(),
403,
'Last activity is too old',
);

return $replyable;
}

private function findReplyAble(int $id, string $type): ReplyAble
Expand Down
1 change: 1 addition & 0 deletions app/Models/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ final class Thread extends Model implements Feedable, ReplyAble, SubscriptionAbl
'body',
'slug',
'subject',
'last_activity_at',
];

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/Feature/ForumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,15 @@
$this->visit("/forum/tags/{$tag->slug}?filter=something-invalid")
->see('href="http://localhost/forum/tags/'.$tag->slug.'?filter=recent" aria-current="page"');
});

test('thread activity is set when a new thread is created', function () {
$this->login();

$this->post('/forum/create-thread', [
'subject' => 'How to work with Eloquent?',
'body' => 'This text explains how to work with Eloquent.',
'tags' => [],
]);

$this->assertNotNull(Thread::latest('id')->first()->last_activity_at);
});
14 changes: 13 additions & 1 deletion tests/Feature/ReplyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
->assertForbidden();
});

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

$this->login();
Expand All @@ -77,6 +77,18 @@
);
});

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

$this->login();

$this->post('/replies', [
'body' => 'The first reply',
'replyable_id' => $thread->id,
'replyable_type' => Thread::TABLE,
])->assertForbidden();
});

test('verified users can see the reply input', function () {
$thread = Thread::factory()->create();

Expand Down