#4: Added a global setting that specifies if comments from anonymous users are allowed

This commit is contained in:
Andy Heathershaw 2018-09-19 20:23:02 +01:00
parent 97ee60cfc9
commit d1d77752b3
7 changed files with 44 additions and 7 deletions

View File

@ -99,6 +99,7 @@ class ConfigHelper
'albums_menu_parents_only' => false, 'albums_menu_parents_only' => false,
'albums_menu_number_items' => 10, 'albums_menu_number_items' => 10,
'allow_photo_comments' => false, 'allow_photo_comments' => false,
'allow_photo_comments_anonymous' => true,
'allow_self_registration' => true, 'allow_self_registration' => true,
'analytics_code' => '', 'analytics_code' => '',
'app_name' => trans('global.app_name'), 'app_name' => trans('global.app_name'),

View File

@ -232,6 +232,7 @@ class DefaultController extends Controller
$checkboxKeys = [ $checkboxKeys = [
'albums_menu_parents_only', 'albums_menu_parents_only',
'allow_photo_comments', 'allow_photo_comments',
'allow_photo_comments_anonymous',
'allow_self_registration', 'allow_self_registration',
'enable_visitor_hits', 'enable_visitor_hits',
'hotlink_protection', 'hotlink_protection',

View File

@ -9,6 +9,7 @@ use App\Http\Controllers\Controller;
use App\Http\Requests\StorePhotoCommentRequest; use App\Http\Requests\StorePhotoCommentRequest;
use App\Photo; use App\Photo;
use App\PhotoComment; use App\PhotoComment;
use App\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -29,7 +30,7 @@ class PhotoCommentController extends Controller
if (!$this->loadAlbumPhotoComment($albumUrlAlias, $photoFilename, $commentID, $album, $photo, $comment)) if (!$this->loadAlbumPhotoComment($albumUrlAlias, $photoFilename, $commentID, $album, $photo, $comment))
{ {
return; return null;
} }
if (Gate::denies('moderate-comments', $photo)) if (Gate::denies('moderate-comments', $photo))
@ -73,7 +74,13 @@ class PhotoCommentController extends Controller
if (!$this->loadAlbumPhotoComment($albumUrlAlias, $photoFilename, $commentID, $album, $photo, $comment)) if (!$this->loadAlbumPhotoComment($albumUrlAlias, $photoFilename, $commentID, $album, $photo, $comment))
{ {
return; return null;
}
if (!User::currentOrAnonymous()->can('photo:post-comment'))
{
App::abort(403);
return null;
} }
return Theme::render('partials.photo_comments_reply_form', [ return Theme::render('partials.photo_comments_reply_form', [
@ -94,7 +101,13 @@ class PhotoCommentController extends Controller
if (!$this->loadAlbumPhotoComment($albumUrlAlias, $photoFilename, 0, $album, $photo, $comment)) if (!$this->loadAlbumPhotoComment($albumUrlAlias, $photoFilename, 0, $album, $photo, $comment))
{ {
return; return null;
}
if (!User::currentOrAnonymous()->can('photo:post-comment'))
{
App::abort(403);
return null;
} }
// Validate and link the parent comment, if provided // Validate and link the parent comment, if provided

View File

@ -94,6 +94,16 @@ class AuthServiceProvider extends ServiceProvider
{ {
return UserConfig::get('public_statistics') || !$user->isAnonymous(); return UserConfig::get('public_statistics') || !$user->isAnonymous();
}); });
Gate::define('photo:post-comment', function(User $user)
{
if ($user->isAnonymous())
{
return UserConfig::get('allow_photo_comments_anonymous');
};
return true;
});
} }
private function userHasAdminPermission(User $user, $permissionDescription) private function userHasAdminPermission(User $user, $permissionDescription)

View File

@ -52,6 +52,8 @@ return [
'select' => 'Select', 'select' => 'Select',
'select_current_text' => '(current)', 'select_current_text' => '(current)',
'settings_allow_photo_comments' => 'Allow comments on photos', 'settings_allow_photo_comments' => 'Allow comments on photos',
'settings_allow_photo_comments_anonymous' => 'Allow anonymous users to comment on photos',
'settings_allow_photo_comments_anonymous_help' => 'With this option enabled, users can post comments without being logged in.',
'settings_allow_photo_comments_help' => 'With this option enabled, users can comment on individual photos.', 'settings_allow_photo_comments_help' => 'With this option enabled, users can comment on individual photos.',
'settings_photo_comments_thread_depth' => 'Maximum depth for nested comments:', 'settings_photo_comments_thread_depth' => 'Maximum depth for nested comments:',
'settings_photo_comments_thread_depth_help' => 'Set to zero to disable nested comments.', 'settings_photo_comments_thread_depth_help' => 'Set to zero to disable nested comments.',

View File

@ -488,6 +488,14 @@
</label> </label>
</div> </div>
<div class="form-check mt-3">
<input type="checkbox" class="form-check-input" id="allow-photo-comments-anonymous" name="allow_photo_comments_anonymous" @if (old('allow_photo_comments_anonymous', UserConfig::get('allow_photo_comments_anonymous')))checked="checked"@endif>
<label class="form-check-label" for="allow-photo-comments-anonymous">
<strong>@lang('forms.settings_allow_photo_comments_anonymous')</strong><br/>
@lang('forms.settings_allow_photo_comments_anonymous_help')
</label>
</div>
<div class="form-check mt-3"> <div class="form-check mt-3">
<input type="checkbox" class="form-check-input" id="photo-comments-require-login" name="photo_comments_require_login" @if (old('photo_comments_require_login', UserConfig::get('photo_comments_require_login')))checked="checked"@endif> <input type="checkbox" class="form-check-input" id="photo-comments-require-login" name="photo_comments_require_login" @if (old('photo_comments_require_login', UserConfig::get('photo_comments_require_login')))checked="checked"@endif>
<label class="form-check-label" for="photo-comments-require-login"> <label class="form-check-label" for="photo-comments-require-login">

View File

@ -2,10 +2,12 @@
<div class="col mt-4"> <div class="col mt-4">
<h2>@lang('gallery.photo_comments_heading')</h2> <h2>@lang('gallery.photo_comments_heading')</h2>
<h3>@lang('gallery.photo_comments_reply_form_heading')</h3> @if (\App\User::currentOrAnonymous()->can('photo:post-comment'))
<p>@lang('gallery.photo_comments_reply_form_p1')</p> <h3>@lang('gallery.photo_comments_reply_form_heading')</h3>
<hr/> <p>@lang('gallery.photo_comments_reply_form_p1')</p>
@include(Theme::viewName('partials.photo_comments_reply_form')) <hr/>
@include(Theme::viewName('partials.photo_comments_reply_form'))
@endif
@foreach ($photo->comments()->whereNull('parent_comment_id')->get() as $comment) @foreach ($photo->comments()->whereNull('parent_comment_id')->get() as $comment)
@if ($comment->isApproved()) @if ($comment->isApproved())