From 95bfdb59b6a1e04e474551c23c7caef619c79839 Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Thu, 19 Sep 2024 14:19:35 +0200 Subject: Topic locking --- src/application/messages/de.msg | 9 +++ src/application/mystic/forum/orm/Topic.php | 2 + src/application/views/view_post.php | 3 + src/application/views/view_search_results.php | 4 +- src/application/views/view_topic_locked.php | 4 ++ src/application/views/view_topic_start.php | 31 ++++++++- src/application/views/view_topics.php | 7 +- src/application/views/view_user.php | 4 +- src/index.php | 94 ++++++++++++++++++++++++++- 9 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 src/application/views/view_topic_locked.php diff --git a/src/application/messages/de.msg b/src/application/messages/de.msg index c2d8416..d1b2389 100644 --- a/src/application/messages/de.msg +++ b/src/application/messages/de.msg @@ -455,3 +455,12 @@ metadata({ : "Failed to send verification email" = "Konnte Bestätigungsmail nicht versenden" + +: "This topic has been locked" += "Dieses Thema wurde gesperrt" + +: "Lock topic" += "Thema sperren" + +: "Unlock topic" += "Thema entsperren" diff --git a/src/application/mystic/forum/orm/Topic.php b/src/application/mystic/forum/orm/Topic.php index 421f5ec..cfd0c78 100644 --- a/src/application/mystic/forum/orm/Topic.php +++ b/src/application/mystic/forum/orm/Topic.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace mystic\forum\orm; +use mystic\forum\attributes\DefaultValue; use mystic\forum\attributes\PrimaryKey; use mystic\forum\attributes\References; use mystic\forum\attributes\Table; @@ -13,4 +14,5 @@ class Topic extends Entity { public string $title; public \DateTimeImmutable $creationDate; #[References("public.users", onDelete: References::SET_NULL)] public ?string $createdBy; + #[DefaultValue("false")] public bool $isLocked; } diff --git a/src/application/views/view_post.php b/src/application/views/view_post.php index 62b2d18..0f86896 100644 --- a/src/application/views/view_post.php +++ b/src/application/views/view_post.php @@ -5,6 +5,7 @@ use mystic\forum\orm\Attachment; /** @var mystic\forum\orm\Post $post */ /** @var mystic\forum\orm\User $postAuthor */ +/** @var mystic\forum\orm\Topic $topic */ $isImage = fn(string $m) => str_starts_with($m, "image/") || str_starts_with($m, "video/"); @@ -16,6 +17,8 @@ $canReply = $GLOBALS["currentUser"]?->hasPermission(UserPermissions::CREATE_OWN_ $canEdit = ($GLOBALS["currentUser"]?->id === $postAuthor?->id && $postAuthor?->hasPermission(UserPermissions::EDIT_OWN_POST)) || ($GLOBALS["currentUser"]?->hasPermission(UserPermissions::EDIT_OTHER_POST)); +$canEdit = $canEdit && !$topic->isLocked; + $canDelete = ($GLOBALS["currentUser"]?->id === $postAuthor?->id && $postAuthor?->hasPermission(UserPermissions::DELETE_OWN_POST)) || ($GLOBALS["currentUser"]?->hasPermission(UserPermissions::DELETE_OTHER_POST)); diff --git a/src/application/views/view_search_results.php b/src/application/views/view_search_results.php index e21fbb8..914d2b2 100644 --- a/src/application/views/view_search_results.php +++ b/src/application/views/view_search_results.php @@ -20,7 +20,9 @@ use mystic\forum\utils\StringUtils; = __("posted by %author% on %post_date% in %topic%", [ "author" => '' . htmlentities($users[$post->authorId]?->displayName ?? __("unknown")) . '', "post_date" => '' . htmlentities($post->postDate->format("c")) . '', - "topic" => '' . htmlentities($topics[$post->topicId]?->title ?? "unknown") . '', + "topic" => '' + . ($topics[$post->topicId]?->isLocked ? ' ' : '') + . htmlentities($topics[$post->topicId]?->title ?? "unknown") . '', ]) ?> diff --git a/src/application/views/view_topic_locked.php b/src/application/views/view_topic_locked.php new file mode 100644 index 0000000..ac59fcb --- /dev/null +++ b/src/application/views/view_topic_locked.php @@ -0,0 +1,4 @@ +