Skip to content
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
5 changes: 5 additions & 0 deletions Web/Models/Entities/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function isClosed(): bool
return (bool) $this->getRecord()->closed;
}

public function isRestricted(): bool
{
return (bool) $this->getRecord()->restricted;
}

public function isPinned(): bool
{
return (bool) $this->getRecord()->pinned;
Expand Down
4 changes: 4 additions & 0 deletions Web/Presenters/CommentPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public function renderMakeComment(string $repo, int $eId): void
$this->flashFail("err", tr("error"), tr("forbidden"));
}

if ($entity instanceof Topic && $entity->isRestricted() && !$entity->getClub()->canBeModifiedBy($this->user->identity)) {
$this->flashFail("err", tr("error"), tr("forbidden"));
}

$flags = 0;
if ($this->postParam("as_group") === "on" && !is_null($club) && $club->canBeModifiedBy($this->user->identity)) {
$flags |= 0b10000000;
Expand Down
1 change: 1 addition & 0 deletions Web/Presenters/TopicsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public function renderEdit(int $clubId, int $topicId): void
$topic->setClosed(empty($this->postParam("close")) ? 0 : 1);

if ($topic->getClub()->canBeModifiedBy($this->user->identity)) {
$topic->setRestricted((empty($this->postParam("restrict")) || !$topic->isPostedOnBehalfOfGroup()) ? 0 : 1);
$topic->setPinned(empty($this->postParam("pin")) ? 0 : 1);
}

Expand Down
3 changes: 3 additions & 0 deletions Web/Presenters/templates/Topics/Edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<td>
{if $topic->getClub()->canBeModifiedBy($thisUser)}
<label><input type="checkbox" name="pin" n:attr="checked => $topic->isPinned()" /> {_pin_topic}</label><br />
{if $topic->isPostedOnBehalfOfGroup()}
<label><input type="checkbox" name="restrict" n:attr="checked => $topic->isRestricted()" /> {_restrict_topic}</label><br />
{/if}
{/if}
<label><input type="checkbox" name="close" n:attr="checked => $topic->isClosed()" /> {_close_topic}</label>
</td>
Expand Down
2 changes: 1 addition & 1 deletion Web/Presenters/templates/Topics/Topic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
</div>
<div style="margin-top: 20px;">
<h4>{tr("topic_messages_count", $count)}</h4>
{include "../components/comments.xml", comments => $comments, count => $count, page => $page, model => "topics", club => $club, readOnly => $topic->isClosed(), showTitle => false, parent => $topic}
{include "../components/comments.xml", comments => $comments, count => $count, page => $page, model => "topics", club => $club, readOnly => $topic->isClosed() || ($topic->isRestricted() && !$topic->getClub()->canBeModifiedBy($thisUser)), showTitle => false, parent => $topic}
</div>
{/block}
2 changes: 2 additions & 0 deletions install/sqls/00059-only-admins-topics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `topics`
ADD `restricted` TINYINT(1) NOT NULL DEFAULT '0' AFTER `closed`;
2 changes: 2 additions & 0 deletions locales/en.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,8 @@
"failed_to_change_topic" = "Failed to change topic";
"no_title_specified" = "No title specified.";

"restrict_topic" = "Only administrators can comment";

/* Errors */

"error_1" = "Incorrect query";
Expand Down
1 change: 1 addition & 0 deletions locales/ru.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,7 @@
"failed_to_create_topic" = "Не удалось создать тему";
"failed_to_change_topic" = "Не удалось изменить тему";
"no_title_specified" = "Заголовок не указан.";
"restrict_topic" = "Комментировать могут только администраторы";

/* Errors */

Expand Down