Skip to content
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

#541 - Disable comments #593

Merged
merged 4 commits into from
Dec 7, 2017
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
8 changes: 7 additions & 1 deletion app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,19 @@ public function show($bookSlug, $pageSlug)
$page->html = $this->entityRepo->renderPage($page);
$sidebarTree = $this->entityRepo->getBookChildren($page->book);
$pageNav = $this->entityRepo->getPageNav($page->html);
$page->load(['comments.createdBy']);

// check if the comment's are enabled
$areCommentsEnabled = !setting('app-disable-comments');
if ($areCommentsEnabled) {
$page->load(['comments.createdBy']);
}

Views::add($page);
$this->setPageTitle($page->getShortName());
return view('pages/show', [
'page' => $page,'book' => $page->book,
'current' => $page, 'sidebarTree' => $sidebarTree,
'commentsEnabled' => $areCommentsEnabled,
'pageNav' => $pageNav]);
}

Expand Down
2 changes: 2 additions & 0 deletions resources/lang/de/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'app_logo_desc' => "Dieses Bild sollte 43px hoch sein.\nGrößere Bilder werden verkleinert.",
'app_primary_color' => 'Primäre Anwendungsfarbe',
'app_primary_color_desc' => "Dies sollte ein HEX Wert sein.\nWenn Sie nicht eingeben, wird die Anwendung auf die Standardfarbe zurückgesetzt.",
'app_disable_comments' => 'Kommentare deaktivieren',
'app_disable_comments_desc' => 'Deaktiviert Kommentare über alle Seiten in der Anwendung. Vorhandene Kommentare werden nicht angezeigt.',

/**
* Registration settings
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
'app_homepage' => 'Application Homepage',
'app_homepage_desc' => 'Select a page to show on the homepage instead of the default view. Page permissions are ignored for selected pages.',
'app_homepage_default' => 'Default homepage view chosen',
'app_disable_comments' => 'Disable comments',
'app_disable_comments_desc' => 'Disable comments across all pages in the application. Existing comments are not shown.',

/**
* Registration settings
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/es/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'app_logo_desc' => 'Esta imagen debería de ser 43px en altura. <br>Iágenes grandes seán escaladas.',
'app_primary_color' => 'Color primario de la aplicación',
'app_primary_color_desc' => 'Esto debería ser un valor hexadecimal. <br>Deje el valor vaío para reiniciar al valor por defecto.',
'app_disable_comments' => 'Deshabilitar comentarios',
'app_disable_comments_desc' => 'Deshabilita los comentarios en todas las páginas de la aplicación. Los comentarios existentes no se muestran. ',

/**
* Registration settings
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/fr/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
'app_logo_desc' => 'Cette image doit faire 43px de hauteur. <br>Les images plus larges seront réduites.',
'app_primary_color' => 'Couleur principale de l\'application',
'app_primary_color_desc' => 'Cela devrait être une valeur hexadécimale. <br>Laisser vide pour rétablir la couleur par défaut.',

'app_disable_comments' => 'Désactiver les commentaires',
'app_disable_comments_desc' => 'Désactive les commentaires sur toutes les pages de l\'application. Les commentaires existants ne sont pas affichés.',
/**
* Registration settings
*/
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/it/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
'app_homepage' => 'Homepage Applicazione',
'app_homepage_desc' => 'Seleziona una pagina da mostrare nella home anzichè quella di default. I permessi della pagina sono ignorati per quella selezionata.',
'app_homepage_default' => 'Homepage di default scelta',
'app_disable_comments' => 'Disattiva commenti',
'app_disable_comments_desc' => 'Disabilita i commenti su tutte le pagine nell\'applicazione. I commenti esistenti non sono mostrati. ',

/**
* Registration settings
*/

'reg_settings' => 'Impostazioni Registrazione',
'reg_allow' => 'Consentire Registrazione?',
'reg_default_role' => 'Ruolo predefinito dopo la registrazione',
Expand Down
4 changes: 3 additions & 1 deletion resources/lang/ja/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'app_logo_desc' => '高さ43pxで表示されます。これを上回る場合、自動で縮小されます。',
'app_primary_color' => 'プライマリカラー',
'app_primary_color_desc' => '16進数カラーコードで入力します。空にした場合、デフォルトの色にリセットされます。',
'app_disable_comments' => 'コメントを無効にする',
'app_disable_comments_desc' => 'アプリケーション内のすべてのページのコメントを無効にします。既存のコメントは表示されません。',

/**
* Registration settings
Expand Down Expand Up @@ -108,5 +110,5 @@
'users_social_disconnect' => 'アカウントを接続解除',
'users_social_connected' => '「:socialAccount」がプロフィールに接続されました。',
'users_social_disconnected' => '「:socialAccount」がプロフィールから接続解除されました。'

];
2 changes: 2 additions & 0 deletions resources/lang/nl/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'app_logo_desc' => 'De afbeelding moet 43px hoog zijn. <br>Grotere afbeeldingen worden geschaald.',
'app_primary_color' => 'Applicatie hoofdkleur',
'app_primary_color_desc' => 'Geef een hexadecimale waarde. <br>Als je niks invult wordt de standaardkleur gebruikt.',
'app_disable_comments' => 'Reacties uitschakelen',
'app_disable_comments_desc' => 'Schakel opmerkingen uit op alle pagina\'s in de applicatie. Bestaande opmerkingen worden niet getoond.',

/**
* Registration settings
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/pl/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'app_logo_desc' => 'Ten obrazek powinien mieć nie więcej niż 43px w pionie. <br>Większe obrazki będą skalowane w dół.',
'app_primary_color' => 'Podstawowy kolor aplikacji',
'app_primary_color_desc' => 'To powinna być wartość HEX. <br>Zostaw to pole puste, by powrócić do podstawowego koloru.',
'app_disable_comments' => 'Wyłącz komentarze',
'app_disable_comments_desc' => 'Wyłącz komentarze na wszystkich stronach w aplikacji. Istniejące komentarze nie są pokazywane.',

/**
* Registration settings
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/pt_BR/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
'app_homepage' => 'Página incial',
'app_homepage_desc' => 'Selecione a página para ser usada como página inicial em vez da padrão. Permissões da página serão ignoradas.',
'app_homepage_default' => 'Escolhida página inicial padrão',
'app_disable_comments' => 'Desativar comentários',
'app_disable_comments_desc' => 'Desativar comentários em todas as páginas no aplicativo. Os comentários existentes não são exibidos.',

/**
* Registration settings
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/ru/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
'app_homepage' => 'Домашняя страница приложения',
'app_homepage_desc' => 'Выберите страницу, которая будет отображаться на главной странице вместо стандартной. Права на страницы игнорируются для выбранных страниц.',
'app_homepage_default' => 'Выбрана домашняя страница по-умолчанию',
'app_disable_comments' => 'Отключить комментарии',
'app_disable_comments_desc' => 'Отключить комментарии на всех страницах приложения. Существующие комментарии не отображаются.',

/**
* Registration
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/sk/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'app_logo_desc' => 'Tento obrázok by mal mať 43px na výšku. <br>Veľké obrázky budú preškálované na menší rozmer.',
'app_primary_color' => 'Primárna farba pre aplikáciu',
'app_primary_color_desc' => 'Toto by mala byť hodnota v hex tvare. <br>Nechajte prázdne ak chcete použiť prednastavenú farbu.',
'app_disable_comments' => 'Zakázať komentáre',
'app_disable_comments_desc' => 'Zakázať komentáre na všetkých stránkach aplikácie. Existujúce komentáre sa nezobrazujú.',

/**
* Registration settings
Expand Down
11 changes: 6 additions & 5 deletions resources/views/pages/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
</div>

@include('partials/book-tree', ['book' => $book, 'sidebarTree' => $sidebarTree])

@stop

@section('body')
Expand All @@ -148,10 +148,11 @@
@include('pages/page-display')

</div>

<div class="container small nopad">
@include('comments/comments', ['page' => $page])
</div>
@if ($commentsEnabled)
<div class="container small nopad">
@include('comments/comments', ['page' => $page])
</div>
@endif
@stop

@section('scripts')
Expand Down
5 changes: 5 additions & 0 deletions resources/views/settings/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<p class="small">{{ trans('settings.app_secure_images_desc') }}</p>
@include('components.toggle-switch', ['name' => 'setting-app-secure-images', 'value' => setting('app-secure-images')])
</div>
<div class="form-group">
<label>{{ trans('settings.app_disable_comments') }}</label>
<p class="small">{{ trans('settings.app_disable_comments_desc') }}</p>
@include('components.toggle-switch', ['name' => 'setting-app-disable-comments', 'value' => setting('app-disable-comments')])
</div>
<div class="form-group">
<label for="setting-app-editor">{{ trans('settings.app_editor') }}</label>
<p class="small">{{ trans('settings.app_editor_desc') }}</p>
Expand Down
28 changes: 28 additions & 0 deletions tests/Entity/CommentSettingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php namespace Tests;

class CommentSettingTest extends BrowserKitTest {
protected $page;

public function setUp() {
parent::setUp();
$this->page = \BookStack\Page::first();
}

public function test_comment_disable () {
$this->asAdmin();

$this->setSettings(['app-disable-comments' => 'true']);

$this->asAdmin()->visit($this->page->getUrl())
->pageNotHasElement('.comments-list');
}

public function test_comment_enable () {
$this->asAdmin();

$this->setSettings(['app-disable-comments' => 'false']);

$this->asAdmin()->visit($this->page->getUrl())
->pageHasElement('.comments-list');
}
}