From f2b885fe1d66f8064193e63b46f36b6274e6f652 Mon Sep 17 00:00:00 2001 From: Al Imran Ahmed Date: Thu, 12 Sep 2024 19:42:42 +0200 Subject: [PATCH] #187: All unncessary backend controllers replaced by full page component --- app/Http/Controllers/ArticleController.php | 7 + .../Controllers/Backend/ArticleController.php | 34 --- .../Backend/CategoryController.php | 14 -- .../Controllers/Backend/CommentController.php | 25 --- .../Controllers/Backend/ConfigController.php | 14 -- .../Backend/DashboardController.php | 14 -- .../Backend/FeedbackController.php | 14 -- .../Controllers/Backend/KeywordController.php | 17 -- .../Backend/SubscriberController.php | 13 -- app/Http/Controllers/HomeController.php | 8 +- app/Http/Controllers/UserController.php | 40 ---- app/Livewire/Backend/Article/Form.php | 7 + app/Livewire/Backend/Category/Index.php | 1 + app/Livewire/Backend/Comment/Edit.php | 38 ++-- app/Livewire/Backend/Comment/Index.php | 2 + app/Livewire/Backend/Feedback/Index.php | 2 + app/Livewire/Backend/Subscriber/Index.php | 2 + app/Livewire/Backend/User/Index.php | 2 + app/Livewire/Backend/User/Profile.php | 17 ++ app/Models/Article.php | 2 +- app/Models/Category.php | 3 + app/Models/Comment.php | 4 + config/telescope.php | 205 ++++++++++++++++++ ..._162739_create_telescope_entries_table.php | 70 ++++++ .../views/backend/articles/create.blade.php | 3 - .../views/backend/articles/edit.blade.php | 3 - .../views/backend/categories/index.blade.php | 3 - .../views/backend/comments/edit.blade.php | 3 - .../views/backend/comments/index.blade.php | 3 - .../views/backend/comments/show.blade.php | 3 - .../views/backend/config/index.blade.php | 3 - .../views/backend/feedback/index.blade.php | 3 - .../views/backend/keywords/index.blade.php | 3 - .../views/backend/subscribers/index.blade.php | 3 - .../backend/users/edit_password.blade.php | 4 +- resources/views/backend/users/index.blade.php | 3 - .../views/frontend/articles/index.blade.php | 4 +- .../frontend/articles/search_result.blade.php | 4 +- .../views/frontend/articles/show.blade.php | 4 +- .../views/frontend/contact/create.blade.php | 4 +- .../views/frontend/pages/about.blade.php | 4 +- .../livewire/backend/comment/edit.blade.php | 8 +- .../livewire/backend/user/profile.blade.php | 47 ++++ routes/backend.php | 45 ++-- .../Controllers/ArticleControllerTest.php | 7 +- .../Backend/ArticleControllerTest.php | 58 ----- .../Backend/CategoryControllerTest.php | 35 --- .../Backend/CommentControllerTest.php | 67 ------ .../Backend/ConfigControllerTest.php | 28 --- .../Backend/DashboardControllerTest.php | 28 --- .../Backend/FeedbackControllerTest.php | 28 --- .../Backend/KeywordControllerTest.php | 29 --- .../Backend/SubscriberControllerTest.php | 28 --- .../Backend/UserControllerTest.php | 66 ------ .../Controllers/HomeControllerTest.php | 2 +- .../Livewire/Backend/Article/FormTest.php | 11 +- .../Livewire/Backend/Article/IndexTest.php | 4 +- .../Livewire/Backend/Comment/EditTest.php | 5 +- .../Livewire/Backend/Comment/IndexTest.php | 22 +- .../Livewire/Backend/Feedback/IndexTest.php | 7 + .../Livewire/Backend/Subscriber/IndexTest.php | 9 +- 61 files changed, 478 insertions(+), 668 deletions(-) delete mode 100644 app/Http/Controllers/Backend/ArticleController.php delete mode 100644 app/Http/Controllers/Backend/CategoryController.php delete mode 100644 app/Http/Controllers/Backend/CommentController.php delete mode 100644 app/Http/Controllers/Backend/ConfigController.php delete mode 100644 app/Http/Controllers/Backend/DashboardController.php delete mode 100644 app/Http/Controllers/Backend/FeedbackController.php delete mode 100644 app/Http/Controllers/Backend/KeywordController.php delete mode 100644 app/Http/Controllers/Backend/SubscriberController.php delete mode 100644 app/Http/Controllers/UserController.php create mode 100644 app/Livewire/Backend/User/Profile.php create mode 100644 config/telescope.php create mode 100644 database/migrations/2024_09_12_162739_create_telescope_entries_table.php delete mode 100644 resources/views/backend/articles/create.blade.php delete mode 100644 resources/views/backend/articles/edit.blade.php delete mode 100644 resources/views/backend/categories/index.blade.php delete mode 100644 resources/views/backend/comments/edit.blade.php delete mode 100644 resources/views/backend/comments/index.blade.php delete mode 100644 resources/views/backend/comments/show.blade.php delete mode 100644 resources/views/backend/config/index.blade.php delete mode 100644 resources/views/backend/feedback/index.blade.php delete mode 100644 resources/views/backend/keywords/index.blade.php delete mode 100644 resources/views/backend/subscribers/index.blade.php delete mode 100644 resources/views/backend/users/index.blade.php create mode 100644 resources/views/livewire/backend/user/profile.blade.php delete mode 100644 tests/Feature/Controllers/Backend/ArticleControllerTest.php delete mode 100644 tests/Feature/Controllers/Backend/CategoryControllerTest.php delete mode 100644 tests/Feature/Controllers/Backend/CommentControllerTest.php delete mode 100644 tests/Feature/Controllers/Backend/ConfigControllerTest.php delete mode 100644 tests/Feature/Controllers/Backend/DashboardControllerTest.php delete mode 100644 tests/Feature/Controllers/Backend/FeedbackControllerTest.php delete mode 100644 tests/Feature/Controllers/Backend/KeywordControllerTest.php delete mode 100644 tests/Feature/Controllers/Backend/SubscriberControllerTest.php delete mode 100644 tests/Feature/Controllers/Backend/UserControllerTest.php diff --git a/app/Http/Controllers/ArticleController.php b/app/Http/Controllers/ArticleController.php index 431c50cd..5b0e29be 100644 --- a/app/Http/Controllers/ArticleController.php +++ b/app/Http/Controllers/ArticleController.php @@ -11,6 +11,13 @@ class ArticleController extends Controller { + public function index(Request $request): View + { + $articles = Article::getPaginated($request); + + return view('frontend.articles.index', compact('articles')); + } + public function show(string $slug): mixed { $article = Article::query() diff --git a/app/Http/Controllers/Backend/ArticleController.php b/app/Http/Controllers/Backend/ArticleController.php deleted file mode 100644 index 9eb1c2f6..00000000 --- a/app/Http/Controllers/Backend/ArticleController.php +++ /dev/null @@ -1,34 +0,0 @@ -hasAuthorization($user)) { - return redirect()->route('home')->with('errorMsg', 'Unauthorized request'); - } - - return view('backend.articles.edit', compact('article')); - } -} diff --git a/app/Http/Controllers/Backend/CategoryController.php b/app/Http/Controllers/Backend/CategoryController.php deleted file mode 100644 index 8a0979c6..00000000 --- a/app/Http/Controllers/Backend/CategoryController.php +++ /dev/null @@ -1,14 +0,0 @@ -get(); - - return view('backend.keywords.index', compact('keywords')); - } -} diff --git a/app/Http/Controllers/Backend/SubscriberController.php b/app/Http/Controllers/Backend/SubscriberController.php deleted file mode 100644 index a873e562..00000000 --- a/app/Http/Controllers/Backend/SubscriberController.php +++ /dev/null @@ -1,13 +0,0 @@ -index(); + return redirect()->route('admin-dashboard'); } else { return (new ArticleController())->index($request); } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php deleted file mode 100644 index 5c734731..00000000 --- a/app/Http/Controllers/UserController.php +++ /dev/null @@ -1,40 +0,0 @@ -where('name', '!=', 'owner')->get(); - - return view('backend.users.create', compact('roles')); - } - - public function edit(User $user): View - { - return view('backend.users.edit', compact('user')); - } - - public function editPassword(): View - { - return view('backend.users.edit_password'); - } - - public function profile(): View - { - $user = Auth::user(); - - return view('backend.users.show', compact('user')); - } -} diff --git a/app/Livewire/Backend/Article/Form.php b/app/Livewire/Backend/Article/Form.php index 2c8765e6..103fb0b9 100644 --- a/app/Livewire/Backend/Article/Form.php +++ b/app/Livewire/Backend/Article/Form.php @@ -36,6 +36,13 @@ class Form extends Component public function mount($article = null): void { if ($article?->id) { + /** @var User $user */ + $user = Auth::user(); + if (! $article->hasAuthorization($user)) { + $this->redirectRoute('home'); + return; + } + $this->originalArticle = $article; $this->articleData = $article->toArray(); $this->articleData['keywords'] = $article->keywords->pluck('name')->implode(' '); diff --git a/app/Livewire/Backend/Category/Index.php b/app/Livewire/Backend/Category/Index.php index a2b847dc..1ad06bae 100644 --- a/app/Livewire/Backend/Category/Index.php +++ b/app/Livewire/Backend/Category/Index.php @@ -7,6 +7,7 @@ use Illuminate\Contracts\View\View; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Arr; +use Livewire\Attributes\Lazy; use Livewire\Component; class Index extends Component diff --git a/app/Livewire/Backend/Comment/Edit.php b/app/Livewire/Backend/Comment/Edit.php index 59d838d7..58a62e60 100644 --- a/app/Livewire/Backend/Comment/Edit.php +++ b/app/Livewire/Backend/Comment/Edit.php @@ -6,40 +6,44 @@ use Illuminate\Contracts\View\View; use Illuminate\Http\RedirectResponse; use Illuminate\Routing\Redirector; -use Illuminate\Support\Arr; use Livewire\Component; class Edit extends Component { public array $rules = [ - 'comment.content' => 'string|required', - 'comment.is_published' => 'boolean', + 'content' => 'string|required', + 'is_published' => 'boolean', ]; - public ?Comment $comment; + public Comment $comment; + + public ?string $content; + public ?bool $is_published = false; public function mount(Comment $comment): void { $this->comment = $comment; + $this->content = $comment->content; + $this->is_published = (bool)$this->is_published; } - public function render(): View - { - return view('livewire.backend.comment.edit'); - } - - public function update(Comment $comment): RedirectResponse|Redirector + public function update(): RedirectResponse|Redirector { - $data = $this->validate(); + $this->validate(); - $comment->update([ - 'is_published' => $isPublished = Arr::get($data, 'comment.is_published', false), + $this->comment->update([ + 'is_published' => $isPublished = $this->is_published, 'published_at' => $isPublished ? now() : null, - 'content' => Arr::get($data, 'comment.content', $comment->content), - 'original_content' => $comment->count_edit ? $comment->original_content : $comment->content, - 'count_edit' => $comment->count_edit + 1, + 'content' => $this->content, + 'original_content' => $this->comment->count_edit ? $this->comment->original_content : $this->comment->content, + 'count_edit' => $this->comment->count_edit + 1, ]); - return redirect()->to(route('backend.comment.show', $comment->parent_comment_id ?? $comment->id)); + return redirect()->to(route('backend.comment.show', $comment->parent_comment_id ?? $this->comment->id)); + } + + public function render(): View + { + return view('livewire.backend.comment.edit'); } } diff --git a/app/Livewire/Backend/Comment/Index.php b/app/Livewire/Backend/Comment/Index.php index 83ce3abd..3a3b113c 100644 --- a/app/Livewire/Backend/Comment/Index.php +++ b/app/Livewire/Backend/Comment/Index.php @@ -7,10 +7,12 @@ use Illuminate\Contracts\View\View; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Facades\Auth; +use Livewire\Attributes\Lazy; use Livewire\Attributes\Url; use Livewire\Component; use Livewire\WithPagination; +#[Lazy] class Index extends Component { use WithPagination; diff --git a/app/Livewire/Backend/Feedback/Index.php b/app/Livewire/Backend/Feedback/Index.php index 1ada6b0f..30b0653e 100644 --- a/app/Livewire/Backend/Feedback/Index.php +++ b/app/Livewire/Backend/Feedback/Index.php @@ -4,9 +4,11 @@ use App\Models\Feedback; use Illuminate\Contracts\View\View; +use Livewire\Attributes\Lazy; use Livewire\Component; use Livewire\WithPagination; +#[Lazy] class Index extends Component { use WithPagination; diff --git a/app/Livewire/Backend/Subscriber/Index.php b/app/Livewire/Backend/Subscriber/Index.php index 01e38d67..251397d8 100644 --- a/app/Livewire/Backend/Subscriber/Index.php +++ b/app/Livewire/Backend/Subscriber/Index.php @@ -4,8 +4,10 @@ use App\Models\Subscriber; use Illuminate\Contracts\View\View; +use Livewire\Attributes\Lazy; use Livewire\Component; +#[Lazy] class Index extends Component { public function placeholder(): View diff --git a/app/Livewire/Backend/User/Index.php b/app/Livewire/Backend/User/Index.php index 3c5aeebc..832a74d7 100644 --- a/app/Livewire/Backend/User/Index.php +++ b/app/Livewire/Backend/User/Index.php @@ -4,10 +4,12 @@ use App\Models\User; use Illuminate\Contracts\View\View; +use Livewire\Attributes\Lazy; use Livewire\Component; use Livewire\WithPagination; use Symfony\Component\HttpFoundation\Response; +#[Lazy] class Index extends Component { use WithPagination; diff --git a/app/Livewire/Backend/User/Profile.php b/app/Livewire/Backend/User/Profile.php new file mode 100644 index 00000000..68769484 --- /dev/null +++ b/app/Livewire/Backend/User/Profile.php @@ -0,0 +1,17 @@ + env('TELESCOPE_ENABLED', true), + + /* + |-------------------------------------------------------------------------- + | Telescope Domain + |-------------------------------------------------------------------------- + | + | This is the subdomain where Telescope will be accessible from. If the + | setting is null, Telescope will reside under the same domain as the + | application. Otherwise, this value will be used as the subdomain. + | + */ + + 'domain' => env('TELESCOPE_DOMAIN'), + + /* + |-------------------------------------------------------------------------- + | Telescope Path + |-------------------------------------------------------------------------- + | + | This is the URI path where Telescope will be accessible from. Feel free + | to change this path to anything you like. Note that the URI will not + | affect the paths of its internal API that aren't exposed to users. + | + */ + + 'path' => env('TELESCOPE_PATH', 'telescope'), + + /* + |-------------------------------------------------------------------------- + | Telescope Storage Driver + |-------------------------------------------------------------------------- + | + | This configuration options determines the storage driver that will + | be used to store Telescope's data. In addition, you may set any + | custom options as needed by the particular driver you choose. + | + */ + + 'driver' => env('TELESCOPE_DRIVER', 'database'), + + 'storage' => [ + 'database' => [ + 'connection' => env('DB_CONNECTION', 'mysql'), + 'chunk' => 1000, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Telescope Queue + |-------------------------------------------------------------------------- + | + | This configuration options determines the queue connection and queue + | which will be used to process ProcessPendingUpdate jobs. This can + | be changed if you would prefer to use a non-default connection. + | + */ + + 'queue' => [ + 'connection' => env('TELESCOPE_QUEUE_CONNECTION', null), + 'queue' => env('TELESCOPE_QUEUE', null), + ], + + /* + |-------------------------------------------------------------------------- + | Telescope Route Middleware + |-------------------------------------------------------------------------- + | + | These middleware will be assigned to every Telescope route, giving you + | the chance to add your own middleware to this list or change any of + | the existing middleware. Or, you can simply stick with this list. + | + */ + + 'middleware' => [ + 'web', + Authorize::class, + ], + + /* + |-------------------------------------------------------------------------- + | Allowed / Ignored Paths & Commands + |-------------------------------------------------------------------------- + | + | The following array lists the URI paths and Artisan commands that will + | not be watched by Telescope. In addition to this list, some Laravel + | commands, like migrations and queue commands, are always ignored. + | + */ + + 'only_paths' => [ + // 'api/*' + ], + + 'ignore_paths' => [ + 'livewire*', + 'nova-api*', + 'pulse*', + ], + + 'ignore_commands' => [ + // + ], + + /* + |-------------------------------------------------------------------------- + | Telescope Watchers + |-------------------------------------------------------------------------- + | + | The following array lists the "watchers" that will be registered with + | Telescope. The watchers gather the application's profile data when + | a request or task is executed. Feel free to customize this list. + | + */ + + 'watchers' => [ + Watchers\BatchWatcher::class => env('TELESCOPE_BATCH_WATCHER', true), + + Watchers\CacheWatcher::class => [ + 'enabled' => env('TELESCOPE_CACHE_WATCHER', true), + 'hidden' => [], + ], + + Watchers\ClientRequestWatcher::class => env('TELESCOPE_CLIENT_REQUEST_WATCHER', true), + + Watchers\CommandWatcher::class => [ + 'enabled' => env('TELESCOPE_COMMAND_WATCHER', true), + 'ignore' => [], + ], + + Watchers\DumpWatcher::class => [ + 'enabled' => env('TELESCOPE_DUMP_WATCHER', true), + 'always' => env('TELESCOPE_DUMP_WATCHER_ALWAYS', false), + ], + + Watchers\EventWatcher::class => [ + 'enabled' => env('TELESCOPE_EVENT_WATCHER', true), + 'ignore' => [], + ], + + Watchers\ExceptionWatcher::class => env('TELESCOPE_EXCEPTION_WATCHER', true), + + Watchers\GateWatcher::class => [ + 'enabled' => env('TELESCOPE_GATE_WATCHER', true), + 'ignore_abilities' => [], + 'ignore_packages' => true, + 'ignore_paths' => [], + ], + + Watchers\JobWatcher::class => env('TELESCOPE_JOB_WATCHER', true), + + Watchers\LogWatcher::class => [ + 'enabled' => env('TELESCOPE_LOG_WATCHER', true), + 'level' => 'error', + ], + + Watchers\MailWatcher::class => env('TELESCOPE_MAIL_WATCHER', true), + + Watchers\ModelWatcher::class => [ + 'enabled' => env('TELESCOPE_MODEL_WATCHER', true), + 'events' => ['eloquent.*'], + 'hydrations' => true, + ], + + Watchers\NotificationWatcher::class => env('TELESCOPE_NOTIFICATION_WATCHER', true), + + Watchers\QueryWatcher::class => [ + 'enabled' => env('TELESCOPE_QUERY_WATCHER', true), + 'ignore_packages' => true, + 'ignore_paths' => [], + 'slow' => 100, + ], + + Watchers\RedisWatcher::class => env('TELESCOPE_REDIS_WATCHER', true), + + Watchers\RequestWatcher::class => [ + 'enabled' => env('TELESCOPE_REQUEST_WATCHER', true), + 'size_limit' => env('TELESCOPE_RESPONSE_SIZE_LIMIT', 64), + 'ignore_http_methods' => [], + 'ignore_status_codes' => [], + ], + + Watchers\ScheduleWatcher::class => env('TELESCOPE_SCHEDULE_WATCHER', true), + Watchers\ViewWatcher::class => env('TELESCOPE_VIEW_WATCHER', true), + ], +]; diff --git a/database/migrations/2024_09_12_162739_create_telescope_entries_table.php b/database/migrations/2024_09_12_162739_create_telescope_entries_table.php new file mode 100644 index 00000000..700a83f0 --- /dev/null +++ b/database/migrations/2024_09_12_162739_create_telescope_entries_table.php @@ -0,0 +1,70 @@ +getConnection()); + + $schema->create('telescope_entries', function (Blueprint $table) { + $table->bigIncrements('sequence'); + $table->uuid('uuid'); + $table->uuid('batch_id'); + $table->string('family_hash')->nullable(); + $table->boolean('should_display_on_index')->default(true); + $table->string('type', 20); + $table->longText('content'); + $table->dateTime('created_at')->nullable(); + + $table->unique('uuid'); + $table->index('batch_id'); + $table->index('family_hash'); + $table->index('created_at'); + $table->index(['type', 'should_display_on_index']); + }); + + $schema->create('telescope_entries_tags', function (Blueprint $table) { + $table->uuid('entry_uuid'); + $table->string('tag'); + + $table->primary(['entry_uuid', 'tag']); + $table->index('tag'); + + $table->foreign('entry_uuid') + ->references('uuid') + ->on('telescope_entries') + ->onDelete('cascade'); + }); + + $schema->create('telescope_monitoring', function (Blueprint $table) { + $table->string('tag')->primary(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + $schema = Schema::connection($this->getConnection()); + + $schema->dropIfExists('telescope_entries_tags'); + $schema->dropIfExists('telescope_entries'); + $schema->dropIfExists('telescope_monitoring'); + } +}; diff --git a/resources/views/backend/articles/create.blade.php b/resources/views/backend/articles/create.blade.php deleted file mode 100644 index e3c198b9..00000000 --- a/resources/views/backend/articles/create.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/views/backend/articles/edit.blade.php b/resources/views/backend/articles/edit.blade.php deleted file mode 100644 index 87155c09..00000000 --- a/resources/views/backend/articles/edit.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/views/backend/categories/index.blade.php b/resources/views/backend/categories/index.blade.php deleted file mode 100644 index b240977f..00000000 --- a/resources/views/backend/categories/index.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/views/backend/comments/edit.blade.php b/resources/views/backend/comments/edit.blade.php deleted file mode 100644 index a7507917..00000000 --- a/resources/views/backend/comments/edit.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/views/backend/comments/index.blade.php b/resources/views/backend/comments/index.blade.php deleted file mode 100644 index a9be6c96..00000000 --- a/resources/views/backend/comments/index.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/views/backend/comments/show.blade.php b/resources/views/backend/comments/show.blade.php deleted file mode 100644 index 57da2403..00000000 --- a/resources/views/backend/comments/show.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/views/backend/config/index.blade.php b/resources/views/backend/config/index.blade.php deleted file mode 100644 index f6ed703a..00000000 --- a/resources/views/backend/config/index.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/views/backend/feedback/index.blade.php b/resources/views/backend/feedback/index.blade.php deleted file mode 100644 index 007dd21e..00000000 --- a/resources/views/backend/feedback/index.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/views/backend/keywords/index.blade.php b/resources/views/backend/keywords/index.blade.php deleted file mode 100644 index a8b617ca..00000000 --- a/resources/views/backend/keywords/index.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/views/backend/subscribers/index.blade.php b/resources/views/backend/subscribers/index.blade.php deleted file mode 100644 index 94c4e2f0..00000000 --- a/resources/views/backend/subscribers/index.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/views/backend/users/edit_password.blade.php b/resources/views/backend/users/edit_password.blade.php index e3cda6d2..cbaf618b 100644 --- a/resources/views/backend/users/edit_password.blade.php +++ b/resources/views/backend/users/edit_password.blade.php @@ -1,3 +1,3 @@ - + - + diff --git a/resources/views/backend/users/index.blade.php b/resources/views/backend/users/index.blade.php deleted file mode 100644 index 74973d1d..00000000 --- a/resources/views/backend/users/index.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/resources/views/frontend/articles/index.blade.php b/resources/views/frontend/articles/index.blade.php index fced0909..2231f19d 100644 --- a/resources/views/frontend/articles/index.blade.php +++ b/resources/views/frontend/articles/index.blade.php @@ -1,4 +1,4 @@ - + @forelse($articles as $article) @@ -12,4 +12,4 @@ - + diff --git a/resources/views/frontend/articles/search_result.blade.php b/resources/views/frontend/articles/search_result.blade.php index dcd351b6..0ce42a9f 100644 --- a/resources/views/frontend/articles/search_result.blade.php +++ b/resources/views/frontend/articles/search_result.blade.php @@ -1,4 +1,4 @@ - +
Searched "{{$searched->query}}"
@@ -12,4 +12,4 @@ -
+ diff --git a/resources/views/frontend/articles/show.blade.php b/resources/views/frontend/articles/show.blade.php index 54afc2bb..99b80065 100644 --- a/resources/views/frontend/articles/show.blade.php +++ b/resources/views/frontend/articles/show.blade.php @@ -1,4 +1,4 @@ - +

{{$article->heading}} @@ -42,4 +42,4 @@ class="text-blue-400 hover:text-blue-600 focus:outline-none focus:text-blue-700" - + diff --git a/resources/views/frontend/contact/create.blade.php b/resources/views/frontend/contact/create.blade.php index dd398d5b..4094ae6f 100644 --- a/resources/views/frontend/contact/create.blade.php +++ b/resources/views/frontend/contact/create.blade.php @@ -1,3 +1,3 @@ - + - + diff --git a/resources/views/frontend/pages/about.blade.php b/resources/views/frontend/pages/about.blade.php index 7c67cba6..69d90019 100644 --- a/resources/views/frontend/pages/about.blade.php +++ b/resources/views/frontend/pages/about.blade.php @@ -1,4 +1,4 @@ - +
- + diff --git a/resources/views/livewire/backend/comment/edit.blade.php b/resources/views/livewire/backend/comment/edit.blade.php index 1ec6e293..df06b11a 100644 --- a/resources/views/livewire/backend/comment/edit.blade.php +++ b/resources/views/livewire/backend/comment/edit.blade.php @@ -2,15 +2,13 @@
+ wire:model="content">
- +
- + Save
diff --git a/resources/views/livewire/backend/user/profile.blade.php b/resources/views/livewire/backend/user/profile.blade.php new file mode 100644 index 00000000..ab9e10fe --- /dev/null +++ b/resources/views/livewire/backend/user/profile.blade.php @@ -0,0 +1,47 @@ +
+
+
+ {{$user->name}} + @if(!$user->roles->isEmpty()) + ({{$user->roles->pluck('name')->implode(', ')}}) + @endif + Edit +
+
Since {{$user->created_date_time_formatted}}
+
{{$user->username}}
+
{{$user->email}}
+ @if($user->is_active) +
+ Active +
+ @else +
+ Inactive +
+ @endif + @if(optional($user->reader)->is_verified) +
+ Verified +
+ @else +
+ Not Verified +
+ @endif + @if(optional($user->reader)->notify) +
+ Notify +
+ @else +
+ Don't Notify +
+ @endif +
+
diff --git a/routes/backend.php b/routes/backend.php index 73de59b7..62b49c87 100644 --- a/routes/backend.php +++ b/routes/backend.php @@ -1,52 +1,43 @@ ['auth', 'role:owner|admin|author']], function () { //profile - Route::get('profile', [UserController::class, 'profile'])->name('user-profile'); + Route::get('profile', \App\Livewire\Backend\User\Profile::class)->name('user-profile'); //dashboard - Route::get('dashboard', [DashboardController::class, 'index'])->name('admin-dashboard'); + Route::get('dashboard', Dashboard::class)->name('admin-dashboard'); //admin articles - Route::get('article', ArticleIndex::class)->name('backend.article.index'); - Route::get('article/create', [ArticleController::class, 'create'])->name('backend.article.create'); - Route::get('article/{article}/edit', [ArticleController::class, 'edit'])->name('backend.article.edit'); + Route::get('article', \App\Livewire\Backend\Article\Index::class)->name('backend.article.index'); + Route::get('article/create', \App\Livewire\Backend\Article\Form::class)->name('backend.article.create'); + Route::get('article/{article}/edit', \App\Livewire\Backend\Article\Form::class)->name('backend.article.edit'); //Admin comments - Route::get('comment', [CommentController::class, 'index'])->name('backend.comment.index'); - Route::get('comment/{comment}/edit', [CommentController::class, 'edit'])->name('backend.comment.edit'); - Route::get('comment/{comment}', [CommentController::class, 'show'])->name('backend.comment.show'); + Route::get('comment', \App\Livewire\Backend\Comment\Index::class)->name('backend.comment.index'); + Route::get('comment/{comment}/edit', \App\Livewire\Backend\Comment\Edit::class)->name('backend.comment.edit'); + Route::get('comment/{comment}', \App\Livewire\Backend\Comment\Show::class)->name('backend.comment.show'); - Route::get('feedback', [FeedbackController::class, 'index'])->name('backend.feedback.index'); + Route::get('feedback', \App\Livewire\Backend\Feedback\Index::class)->name('backend.feedback.index'); - Route::get('subscriber', [SubscriberController::class, 'index'])->name('backend.subscriber.index'); + Route::get('subscriber', \App\Livewire\Backend\Subscriber\Index::class)->name('backend.subscriber.index'); }); Route::group(['middleware' => ['auth', 'role:owner|admin']], function () { - Route::get('category', [CategoryController::class, 'index'])->name('backend.category.index'); + Route::get('category', \App\Livewire\Backend\Category\Index::class)->name('backend.category.index'); //Admin users - Route::get('user', [UserController::class, 'index'])->name('backend.user.index'); - Route::get('user/password/edit', [UserController::class, 'editPassword'])->name('backend.user.password.edit'); - Route::get('user/create', [UserController::class, 'create'])->name('backend.user.create'); - Route::get('user/{user}/edit', [UserController::class, 'edit'])->name('backend.user.edit'); + Route::get('user', \App\Livewire\Backend\User\Index::class)->name('backend.user.index'); + Route::get('user/password/edit', \App\Livewire\Backend\User\PasswordForm::class)->name('backend.user.password.edit'); + Route::get('user/create', \App\Livewire\Backend\User\Form::class)->name('backend.user.create'); + Route::get('user/{user}/edit', \App\Livewire\Backend\User\Form::class)->name('backend.user.edit'); - Route::get('keyword', [KeywordController::class, 'index'])->name('backend.keyword.index'); + Route::get('keyword', \App\Livewire\Backend\Keyword\Index::class)->name('backend.keyword.index'); }); Route::group(['middleware' => ['auth', 'role:owner']], function () { //admin config - Route::get('config', [ConfigController::class, 'index'])->name('backend.config.index'); + Route::get('config', \App\Livewire\Backend\Config\Index::class)->name('backend.config.index'); }); diff --git a/tests/Feature/Controllers/ArticleControllerTest.php b/tests/Feature/Controllers/ArticleControllerTest.php index 8092787f..2152f256 100644 --- a/tests/Feature/Controllers/ArticleControllerTest.php +++ b/tests/Feature/Controllers/ArticleControllerTest.php @@ -81,7 +81,7 @@ public function testHideShowUnpublished() ->assertDontSee('Unpublished content'); } - public function testShowById() + public function testShowByIdCorrectly() { $article = Article::factory()->published()->create([ 'heading' => 'Test Heading', @@ -92,8 +92,11 @@ public function testShowById() ]); $this->get("article/{$article->id}/{$article->heading}")->assertOk(); + } - $this->get('article/'.Str::random().time()."/{$article->heading}") + public function testShowByIdNotFound() + { + $this->get('article/'.Str::random().time()."/".Str::random().time()) ->assertRedirectToRoute('home'); } diff --git a/tests/Feature/Controllers/Backend/ArticleControllerTest.php b/tests/Feature/Controllers/Backend/ArticleControllerTest.php deleted file mode 100644 index 76de3620..00000000 --- a/tests/Feature/Controllers/Backend/ArticleControllerTest.php +++ /dev/null @@ -1,58 +0,0 @@ -user = User::factory()->create(); - $role = Role::findOrCreate('owner'); - $this->user->assignRole($role); - } - - public function testIndex() - { - $this->actingAs($this->user)->get('/admin/article') - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.articles.index'); - } - - public function testCreate() - { - $this->actingAs($this->user)->get('/admin/article/create') - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.articles.create'); - } - - public function testEdit() - { - $article = Article::factory()->create(); - - $this->actingAs($this->user)->get("/admin/article/$article->id/edit") - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.articles.edit'); - } - - public function testEditForUnauthorizedUser() - { - $reader = User::factory()->create(); - $role = Role::query()->createOrFirst(['name' => 'author']); - $reader->assignRole($role); - - $article = Article::factory()->create(); - - $this->actingAs($reader)->get("/admin/article/$article->id/edit") - ->assertRedirectToRoute('home') - ->assertSessionHas('errorMsg'); - } -} diff --git a/tests/Feature/Controllers/Backend/CategoryControllerTest.php b/tests/Feature/Controllers/Backend/CategoryControllerTest.php deleted file mode 100644 index 9d9760e7..00000000 --- a/tests/Feature/Controllers/Backend/CategoryControllerTest.php +++ /dev/null @@ -1,35 +0,0 @@ -user = User::factory()->create(); - - $role = Role::findOrCreate('owner'); - $this->user->assignRole($role); - } - - public function testIndex() - { - $this->actingAs($this->user)->get('/admin/category') - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.categories.index'); - } -} diff --git a/tests/Feature/Controllers/Backend/CommentControllerTest.php b/tests/Feature/Controllers/Backend/CommentControllerTest.php deleted file mode 100644 index d956e537..00000000 --- a/tests/Feature/Controllers/Backend/CommentControllerTest.php +++ /dev/null @@ -1,67 +0,0 @@ -user = User::factory()->create(); - - $role = Role::findOrCreate('owner'); - $this->user->assignRole($role); - - $this->category = Category::factory()->create(); - - $this->article = Article::factory()->published()->create([ - 'heading' => 'Test Heading', - 'category_id' => $this->category->id, - 'user_id' => $this->user->id, - ]); - } - - public function testIndex() - { - $this->actingAs($this->user)->get('/admin/comment') - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.comments.index'); - } - - public function testEdit() - { - $comment = Comment::factory()->create(['article_id' => $this->article->id]); - - $this->actingAs($this->user)->get("/admin/comment/{$comment->id}/edit") - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.comments.edit') - ->assertViewHas('comment', $comment); - } - - public function testShow() - { - $comment = Comment::factory()->create([ - 'article_id' => $this->article->id, - 'user_id' => $this->user->id, - ]); - - $this->actingAs($this->user)->get("/admin/comment/{$comment->id}") - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.comments.show') - ->assertViewHas('comment', $comment); - } -} diff --git a/tests/Feature/Controllers/Backend/ConfigControllerTest.php b/tests/Feature/Controllers/Backend/ConfigControllerTest.php deleted file mode 100644 index 8a429679..00000000 --- a/tests/Feature/Controllers/Backend/ConfigControllerTest.php +++ /dev/null @@ -1,28 +0,0 @@ -user = User::factory()->create(); - $role = Role::findOrCreate('owner'); - $this->user->assignRole($role); - } - - public function testIndex() - { - $this->actingAs($this->user)->get('/admin/config') - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.config.index'); - } -} diff --git a/tests/Feature/Controllers/Backend/DashboardControllerTest.php b/tests/Feature/Controllers/Backend/DashboardControllerTest.php deleted file mode 100644 index a9c0a2dd..00000000 --- a/tests/Feature/Controllers/Backend/DashboardControllerTest.php +++ /dev/null @@ -1,28 +0,0 @@ -user = User::factory()->create(); - $role = Role::findOrCreate('owner'); - $this->user->assignRole($role); - } - - public function testIndex() - { - $this->actingAs($this->user)->get('/admin/dashboard') - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.dashboard'); - } -} diff --git a/tests/Feature/Controllers/Backend/FeedbackControllerTest.php b/tests/Feature/Controllers/Backend/FeedbackControllerTest.php deleted file mode 100644 index 4d765cb9..00000000 --- a/tests/Feature/Controllers/Backend/FeedbackControllerTest.php +++ /dev/null @@ -1,28 +0,0 @@ -user = User::factory()->create(); - $role = Role::findOrCreate('owner'); - $this->user->assignRole($role); - } - - public function testIndex() - { - $this->actingAs($this->user)->get('/admin/feedback') - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.feedback.index'); - } -} diff --git a/tests/Feature/Controllers/Backend/KeywordControllerTest.php b/tests/Feature/Controllers/Backend/KeywordControllerTest.php deleted file mode 100644 index 7126af48..00000000 --- a/tests/Feature/Controllers/Backend/KeywordControllerTest.php +++ /dev/null @@ -1,29 +0,0 @@ -user = User::factory()->create(); - $role = Role::findOrCreate('owner'); - $this->user->assignRole($role); - } - - public function testIndex() - { - $this->actingAs($this->user)->get('/admin/keyword') - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.keywords.index') - ->assertViewHas('keywords'); - } -} diff --git a/tests/Feature/Controllers/Backend/SubscriberControllerTest.php b/tests/Feature/Controllers/Backend/SubscriberControllerTest.php deleted file mode 100644 index 419ee3ac..00000000 --- a/tests/Feature/Controllers/Backend/SubscriberControllerTest.php +++ /dev/null @@ -1,28 +0,0 @@ -user = User::factory()->create(); - $role = Role::findOrCreate('owner'); - $this->user->assignRole($role); - } - - public function testIndex() - { - $this->actingAs($this->user)->get('/admin/subscriber') - ->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.subscribers.index'); - } -} diff --git a/tests/Feature/Controllers/Backend/UserControllerTest.php b/tests/Feature/Controllers/Backend/UserControllerTest.php deleted file mode 100644 index 24faf6f2..00000000 --- a/tests/Feature/Controllers/Backend/UserControllerTest.php +++ /dev/null @@ -1,66 +0,0 @@ -user = User::factory()->create(); - $role = Role::findOrCreate('owner'); - $this->user->assignRole($role); - } - - public function testIndex() - { - $response = $this->actingAs($this->user)->get('/admin/user'); - $response->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.users.index'); - } - - public function testCreate() - { - $response = $this->actingAs($this->user)->get('/admin/user/create'); - $response->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.users.create') - ->assertViewHas('roles'); - } - - public function testEdit() - { - $editingUser = User::factory()->create(); - - $response = $this->actingAs($this->user) - ->get("/admin/user/{$editingUser->id}/edit"); - - $response->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.users.edit') - ->assertViewHas('user', $editingUser); - } - - public function testEditPassword() - { - $response = $this->actingAs($this->user) - ->get('/admin/user/password/edit'); - - $response->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.users.edit_password'); - } - - public function testProfile() - { - $response = $this->actingAs($this->user)->get('/admin/profile'); - $response->assertStatus(Response::HTTP_OK) - ->assertViewIs('backend.users.show') - ->assertViewHas('user', $this->user); - - } -} diff --git a/tests/Feature/Controllers/HomeControllerTest.php b/tests/Feature/Controllers/HomeControllerTest.php index 8ea17cbd..51f03f5c 100644 --- a/tests/Feature/Controllers/HomeControllerTest.php +++ b/tests/Feature/Controllers/HomeControllerTest.php @@ -56,7 +56,7 @@ public function testAdminDashboard() $this->actingAs($user) ->get('/') - ->assertViewIs('backend.dashboard'); + ->assertRedirectToRoute('admin-dashboard'); } public function testGetMessage() diff --git a/tests/Feature/Livewire/Backend/Article/FormTest.php b/tests/Feature/Livewire/Backend/Article/FormTest.php index c797a133..ab157084 100644 --- a/tests/Feature/Livewire/Backend/Article/FormTest.php +++ b/tests/Feature/Livewire/Backend/Article/FormTest.php @@ -12,11 +12,21 @@ use Illuminate\Support\Facades\Mail; use Illuminate\Support\Str; use Livewire\Livewire; +use Spatie\Permission\Models\Role; use Symfony\Component\HttpFoundation\Response; use Tests\TestCase; class FormTest extends TestCase { + protected function setUp(): void + { + parent::setUp(); + $this->user = User::factory()->create(); + $role = Role::findOrCreate('owner'); + $this->user->assignRole($role); + Auth::login($this->user); + } + public function testRender(): void { Livewire::test(Form::class) @@ -109,7 +119,6 @@ public function testStoresANewArticleCorrectly() public function testUpdatesAnExistingArticleCorrectly() { Mail::fake(); - Auth::loginUsingId(User::factory()->create()->id); $article = Article::factory()->create(); $data = [ diff --git a/tests/Feature/Livewire/Backend/Article/IndexTest.php b/tests/Feature/Livewire/Backend/Article/IndexTest.php index e3c7884a..7c648478 100644 --- a/tests/Feature/Livewire/Backend/Article/IndexTest.php +++ b/tests/Feature/Livewire/Backend/Article/IndexTest.php @@ -25,9 +25,7 @@ public function setUp(): void public function testItRendersCorrectly() { - Livewire::test(Index::class) - ->assertStatus(200) - ->assertViewIs('livewire.backend.article.index'); + Livewire::test(Index::class)->assertStatus(200); } public function testItFiltersArticlesBasedOnCategory() diff --git a/tests/Feature/Livewire/Backend/Comment/EditTest.php b/tests/Feature/Livewire/Backend/Comment/EditTest.php index f02a6765..b80ff58d 100644 --- a/tests/Feature/Livewire/Backend/Comment/EditTest.php +++ b/tests/Feature/Livewire/Backend/Comment/EditTest.php @@ -26,15 +26,14 @@ public function testUpdate() $article = Article::factory()->create(); $comment = Comment::factory(['article_id' => $article->id])->create(); $updatedComment = clone $comment; - $updatedComment->content = $this->faker->paragraph; Livewire::test(Edit::class, ['comment' => $comment]) - ->set('comment', $updatedComment) + ->set('content', $content = $this->faker->paragraph) ->call('update', $updatedComment); $this->assertDatabaseHas('comments', [ 'id' => $comment->id, - 'content' => $updatedComment->content, + 'content' => $content, ]); } } diff --git a/tests/Feature/Livewire/Backend/Comment/IndexTest.php b/tests/Feature/Livewire/Backend/Comment/IndexTest.php index 5fea31e3..18d5415d 100644 --- a/tests/Feature/Livewire/Backend/Comment/IndexTest.php +++ b/tests/Feature/Livewire/Backend/Comment/IndexTest.php @@ -13,21 +13,35 @@ class IndexTest extends TestCase { - public function testRender(): void + public User $user; + + protected function setUp(): void { - $user = User::factory()->create(); - Auth::login($user); + parent::setUp(); + $this->user = User::factory()->create(); + Auth::login($this->user); + } + public function testRender(): void + { $article = Article::factory()->create(); Comment::factory()->create([ 'article_id' => $article->id, - 'user_id' => $user->id, + 'user_id' => $this->user->id, ]); Livewire::test(Index::class) + ->assertStatus(Response::HTTP_OK); + } + + public function testPlaceholder() + { + Livewire::test(Index::class) + ->call('placeholder') ->assertStatus(Response::HTTP_OK) ->assertViewIs('livewire.backend.comment.index') ->assertViewHas('comments'); + } } diff --git a/tests/Feature/Livewire/Backend/Feedback/IndexTest.php b/tests/Feature/Livewire/Backend/Feedback/IndexTest.php index 7c0bb914..db114bba 100644 --- a/tests/Feature/Livewire/Backend/Feedback/IndexTest.php +++ b/tests/Feature/Livewire/Backend/Feedback/IndexTest.php @@ -13,6 +13,13 @@ class IndexTest extends TestCase public function testRender(): void { Livewire::test(Index::class) + ->assertStatus(Response::HTTP_OK); + } + + public function testPlaceholder() + { + Livewire::test(Index::class) + ->call('placeholder') ->assertStatus(Response::HTTP_OK) ->assertViewIs('livewire.backend.feedback.index') ->assertViewHas('feedbacks'); diff --git a/tests/Feature/Livewire/Backend/Subscriber/IndexTest.php b/tests/Feature/Livewire/Backend/Subscriber/IndexTest.php index 38d76798..1b15f338 100644 --- a/tests/Feature/Livewire/Backend/Subscriber/IndexTest.php +++ b/tests/Feature/Livewire/Backend/Subscriber/IndexTest.php @@ -9,10 +9,15 @@ class IndexTest extends TestCase { public function testRender() + { + Livewire::test(Index::class)->assertOk(); + } + + public function testPlaceholder() { Livewire::test(Index::class) + ->call('placeholder') ->assertOk() - ->assertViewIs('livewire.backend.subscriber.index') - ->assertViewHas('subscribers'); + ->assertViewIs('livewire.backend.subscriber.index'); } }