From 428c43a4c38fa6d1a2d51cc3b0946d3901cdaa33 Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Fri, 21 Sep 2018 15:00:07 +0100 Subject: [PATCH] #4: Added an admin screen to manage comments --- .../Controllers/Admin/DefaultController.php | 3 ++ .../Admin/PhotoCommentController.php | 32 +++++++++++ app/PhotoComment.php | 5 ++ app/Providers/AuthServiceProvider.php | 4 ++ database/seeds/PermissionsSeeder.php | 8 +++ resources/lang/en/admin.php | 4 ++ resources/lang/en/navigation.php | 1 + resources/lang/en/permissions.php | 1 + .../themes/base/admin/edit_group.blade.php | 4 ++ .../themes/base/admin/list_comments.blade.php | 54 +++++++++++++++++++ .../partials/admin_manage_widget.blade.php | 4 ++ .../partials/admin_stats_widget.blade.php | 3 +- routes/web.php | 4 ++ 13 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Admin/PhotoCommentController.php create mode 100644 resources/views/themes/base/admin/list_comments.blade.php diff --git a/app/Http/Controllers/Admin/DefaultController.php b/app/Http/Controllers/Admin/DefaultController.php index 16aa63e..fb6bcdf 100644 --- a/app/Http/Controllers/Admin/DefaultController.php +++ b/app/Http/Controllers/Admin/DefaultController.php @@ -16,6 +16,7 @@ use App\Http\Requests\SaveSettingsRequest; use App\Label; use App\Mail\TestMailConfig; use App\Photo; +use App\PhotoComment; use App\Services\GiteaService; use App\Services\GithubService; use App\Services\PhotoService; @@ -140,6 +141,7 @@ class DefaultController extends Controller $photoCount = Photo::all()->count(); $groupCount = Group::all()->count(); $labelCount = Label::all()->count(); + $commentCount = PhotoComment::whereNotNull('approved_at')->count(); $userCount = User::where('is_activated', true)->count(); $minMetadataVersion = Photo::min('metadata_version'); @@ -157,6 +159,7 @@ class DefaultController extends Controller return Theme::render('admin.index', [ 'album_count' => $albumCount, 'app_version' => config('app.version'), + 'comment_count' => $commentCount, 'group_count' => $groupCount, 'label_count' => $labelCount, 'memory_limit' => ini_get('memory_limit'), diff --git a/app/Http/Controllers/Admin/PhotoCommentController.php b/app/Http/Controllers/Admin/PhotoCommentController.php new file mode 100644 index 0000000..a22be69 --- /dev/null +++ b/app/Http/Controllers/Admin/PhotoCommentController.php @@ -0,0 +1,32 @@ +middleware('auth'); + View::share('is_admin', true); + } + + public function index() + { + $this->authorizeAccessToAdminPanel(); + + $comments = PhotoComment::with('photo') + ->with('photo.album') + ->orderBy('created_at', 'desc') + ->paginate(UserConfig::get('items_per_page')); + + return Theme::render('admin.list_comments', [ + 'comments' => $comments + ]); + } +} \ No newline at end of file diff --git a/app/PhotoComment.php b/app/PhotoComment.php index 0e705cd..f78f134 100644 --- a/app/PhotoComment.php +++ b/app/PhotoComment.php @@ -61,6 +61,11 @@ class PhotoComment extends Model return $this->belongsTo(PhotoComment::class, 'parent_comment_id'); } + public function photo() + { + return $this->belongsTo(Photo::class); + } + public function textAsHtml() { $start = '

'; diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index d37e63a..556dfa2 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -54,6 +54,10 @@ class AuthServiceProvider extends ServiceProvider { return $this->userHasAdminPermission($user, 'manage-albums'); }); + Gate::define('admin:manage-comments', function ($user) + { + return $this->userHasAdminPermission($user, 'manage-comments'); + }); Gate::define('admin:manage-groups', function ($user) { return $this->userHasAdminPermission($user, 'manage-groups'); diff --git a/database/seeds/PermissionsSeeder.php b/database/seeds/PermissionsSeeder.php index 927c7e8..e5e5494 100644 --- a/database/seeds/PermissionsSeeder.php +++ b/database/seeds/PermissionsSeeder.php @@ -72,6 +72,14 @@ class PermissionsSeeder extends Seeder 'is_default' => false, 'sort_order' => 0 ]); + + // admin:manage-comments = controls if photo comments can be managed + DatabaseSeeder::createOrUpdate('permissions', [ + 'section' => 'admin', + 'description' => 'manage-comments', + 'is_default' => false, + 'sort_order' => 0 + ]); } private function seedAlbumPermissions() diff --git a/resources/lang/en/admin.php b/resources/lang/en/admin.php index 9bfc27e..902b250 100644 --- a/resources/lang/en/admin.php +++ b/resources/lang/en/admin.php @@ -62,6 +62,7 @@ return [ 'cannot_remove_own_admin' => 'You cannot remove your own administrator permissions. Please ask another administrator to remove the administrator permissions for you.', 'change_album_message' => 'Please select the album to move the photo(s) to:', 'change_album_title' => 'Move photo(s) to another album', + 'comment_summary' => ':album_name / :photo_name', 'create_album' => 'Create a photo album', 'create_album_intro' => 'Photo albums contain individual photographs together in the same way as a physical photo album or memory book.', 'create_album_intro2' => 'Complete the form below to create a photo album.', @@ -136,6 +137,8 @@ return [ 'list_albums' => 'Go to your albums', 'list_albums_intro' => 'Albums contain collections of individual photographs in the same way as a physical photo album or memory book.', 'list_albums_title' => 'Albums', + 'list_comments_intro' => 'Comments are messages left on your photos by visitors and users.', + 'list_comments_title' => 'Comments', 'list_groups_intro' => 'Organise your users into categories or types by using groups. You can assign permissions on albums to groups of users to make administration and management easier.', 'list_groups_title' => 'Groups', 'list_labels_intro' => 'Organise your photos differently using labels. Assign one or more labels to your photos and your visitors can view all photos with a specific tag in a single view.', @@ -254,6 +257,7 @@ return [ 'statistics_prefs_saved_message' => 'The statistics preferences were saved successfully.', 'stats_widget' => [ 'albums' => 'album|albums', + 'comments' => 'comment|comments', 'groups' => 'group|groups', 'labels' => 'label|labels', 'panel_header' => 'Statistics', diff --git a/resources/lang/en/navigation.php b/resources/lang/en/navigation.php index 28ce905..ff51105 100644 --- a/resources/lang/en/navigation.php +++ b/resources/lang/en/navigation.php @@ -4,6 +4,7 @@ return [ 'about' => 'About', 'admin' => 'Admin', 'albums' => 'Albums', + 'comments' => 'Comments', 'create_album' => 'Create album', 'create_group' => 'Create group', 'create_storage' => 'Create storage', diff --git a/resources/lang/en/permissions.php b/resources/lang/en/permissions.php index e32aeaf..9633200 100644 --- a/resources/lang/en/permissions.php +++ b/resources/lang/en/permissions.php @@ -4,6 +4,7 @@ return [ 'access' => 'Access the administration panel', 'configure' => 'Configure the application', 'manage-albums' => 'Manage photo albums', + 'manage-comments' => 'Manage comments', 'manage-groups' => 'Manage user groups', 'manage-labels' => 'Manage photo labels', 'manage-storage' => 'Manage storage locations', diff --git a/resources/views/themes/base/admin/edit_group.blade.php b/resources/views/themes/base/admin/edit_group.blade.php index c26f343..899c506 100644 --- a/resources/views/themes/base/admin/edit_group.blade.php +++ b/resources/views/themes/base/admin/edit_group.blade.php @@ -87,6 +87,10 @@ 'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-labels') ]) + @include(Theme::viewName('partials.permission_checkbox'), [ + 'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-comments') + ]) + @include(Theme::viewName('partials.permission_checkbox'), [ 'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-users') ]) diff --git a/resources/views/themes/base/admin/list_comments.blade.php b/resources/views/themes/base/admin/list_comments.blade.php new file mode 100644 index 0000000..229d4ba --- /dev/null +++ b/resources/views/themes/base/admin/list_comments.blade.php @@ -0,0 +1,54 @@ +@extends(Theme::viewName('layout')) +@section('title', trans('admin.list_comments_title')) + +@section('breadcrumb') +

+ + +@endsection + +@section('content') +
+
+
+

@yield('title')

+
+ @lang('admin.list_comments_intro') +
+ + @if (count($comments) == 0) +
+

@lang('admin.no_comments_title')

+

@lang('admin.no_comments_text')

+

+ @lang('admin.create_comment') +

+
+ @else + + + @foreach ($comments as $comment) + + + + + @endforeach + +
+

+ {{ $comment->name }}
+ {{ trans('admin.comment_summary', ['album_name' => $comment->photo->album->name, 'photo_name' => $comment->photo->name]) }} +

+
{!! $comment->textAsHtml() !!}
+
+ @lang('forms.delete_action') +
+ +
+ {{ $comments->links() }} +
+ @endif +
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/themes/base/partials/admin_manage_widget.blade.php b/resources/views/themes/base/partials/admin_manage_widget.blade.php index 082dcf2..a5db0f9 100644 --- a/resources/views/themes/base/partials/admin_manage_widget.blade.php +++ b/resources/views/themes/base/partials/admin_manage_widget.blade.php @@ -5,6 +5,7 @@ $canManageLabels = Auth::user()->can('admin:manage-labels'); $canManageStorage = Auth::user()->can('admin:manage-storage'); $canManageUsers = Auth::user()->can('admin:manage-users'); + $canManageComments = Auth::user()->can('admin:manage-comments'); @endphp @if ($canConfigure || $canManageAlbums || $canManageGroups || $canManageStorage || $canManageUsers) @@ -17,6 +18,9 @@ @if ($canManageLabels) @lang('navigation.breadcrumb.labels') @endif + @if ($canManageComments) + @lang('navigation.breadcrumb.comments') + @endif @if ($canManageUsers) @lang('navigation.breadcrumb.users') @endif diff --git a/resources/views/themes/base/partials/admin_stats_widget.blade.php b/resources/views/themes/base/partials/admin_stats_widget.blade.php index 3f45961..e65c6eb 100644 --- a/resources/views/themes/base/partials/admin_stats_widget.blade.php +++ b/resources/views/themes/base/partials/admin_stats_widget.blade.php @@ -2,7 +2,8 @@
@lang('admin.stats_widget.panel_header')
{{ $album_count }} {{ trans_choice('admin.stats_widget.albums', $album_count) }} · - {{ $photo_count }} {{ trans_choice('admin.stats_widget.photos', $photo_count) }}
+ {{ $photo_count }} {{ trans_choice('admin.stats_widget.photos', $photo_count) }} · + {{ $comment_count }} {{ trans_choice('admin.stats_widget.comments', $comment_count) }}
{{ $label_count }} {{ trans_choice('admin.stats_widget.labels', $label_count) }} @can('admin:access')
diff --git a/routes/web.php b/routes/web.php index ee73dd5..b1470c9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -63,6 +63,10 @@ Route::group(['prefix' => 'admin'], function () { // Group management Route::get('groups/{id}/delete', 'Admin\GroupController@delete')->name('groups.delete'); Route::resource('groups', 'Admin\GroupController'); + + // Comments management + Route::get('comments/{id}/delete', 'Admin\PhotoCommentController@delete')->name('comments.delete'); + Route::resource('comments', 'Admin\PhotoCommentController'); }); // Installation