Change the logic for topic-links

This commit is contained in:
Visman 2021-01-22 22:45:41 +07:00
parent 00208dc197
commit 9e4d9078e4
3 changed files with 14 additions and 9 deletions

View file

@ -103,8 +103,7 @@ class Post extends Page
$topic = $this->c->topics->load((int) $args['id']);
if (
empty($topic)
|| $topic->moved_to
! $topic instanceof Topic
|| ! $topic->canReply
) {
return $this->c->Message->message('Bad request');

View file

@ -93,15 +93,16 @@ class Topic extends Page
$topic = $this->c->topics->load((int) $args['id']);
}
if (
! $topic instanceof TopicModel
|| ! $topic->last_post_id
) {
if (! $topic instanceof TopicModel) {
return $this->c->Message->message('Bad request');
}
if ($topic->moved_to) {
return $this->c->Redirect->page('Topic', ['id' => $topic->moved_to]);
return $this->c->Redirect->url($topic->link);
}
if (! $topic->last_post_id) {
return $this->c->Message->message('Bad request');
}
switch ($type) {

View file

@ -53,7 +53,9 @@ class Model extends DataModel
*/
protected function getcanReply(): bool
{
if ($this->c->user->isAdmin) {
if ($this->moved_to) {
return false;
} elseif ($this->c->user->isAdmin) {
return true;
} elseif (
$this->closed
@ -117,7 +119,10 @@ class Model extends DataModel
*/
protected function getlinkLast(): ?string
{
if ($this->moved_to) {
if (
$this->moved_to
|| $this->last_post_id < 1
) {
return null;
} else {
return $this->c->Router->link(