From 3496078a91b3c7416a1160acbfbbff2f32a9c978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Thu, 4 Oct 2018 16:06:14 +0200 Subject: [PATCH 1/6] Fix wording --- tests/Feature/KontourServiceProviderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/KontourServiceProviderTest.php b/tests/Feature/KontourServiceProviderTest.php index e63a95f..a914734 100644 --- a/tests/Feature/KontourServiceProviderTest.php +++ b/tests/Feature/KontourServiceProviderTest.php @@ -20,7 +20,7 @@ public function test_admin_guard_can_be_resolved() $this->assertInstanceOf(\Illuminate\Contracts\Auth\Guard::class, $guard); } - public function test_menu_widget_can_resolved() + public function test_menu_widget_can_be_resolved() { $this->assertInstanceOf(MenuWidget::class, app(MenuWidget::class)); } From 69a11ea640995b3de026893abec1cbe859d9e6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Thu, 4 Oct 2018 16:10:21 +0200 Subject: [PATCH 2/6] Register UserAccountWidget --- src/Providers/KontourServiceProvider.php | 15 ++++++++++---- src/Widgets/UserAccountWidget.php | 21 ++++++++++++++++++++ tests/Feature/KontourServiceProviderTest.php | 6 ++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/Widgets/UserAccountWidget.php diff --git a/src/Providers/KontourServiceProvider.php b/src/Providers/KontourServiceProvider.php index 6ecda92..8fd291d 100644 --- a/src/Providers/KontourServiceProvider.php +++ b/src/Providers/KontourServiceProvider.php @@ -3,20 +3,21 @@ namespace Kontenta\KontourSupport\Providers; use Illuminate\Auth\AuthManager; +use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; use Kontenta\KontourSupport\AdminRouteManager; use Kontenta\KontourSupport\AdminViewManager; use Kontenta\KontourSupport\AdminWidgetManager; -use Kontenta\KontourSupport\Widgets\MenuWidget; +use Kontenta\KontourSupport\Http\Middleware\AuthenticateAdmin; +use Kontenta\KontourSupport\Http\Middleware\RedirectIfAuthenticated; use Kontenta\KontourSupport\RecentVisitsRepository; use Kontenta\KontourSupport\Widgets\ItemHistoryWidget; +use Kontenta\KontourSupport\Widgets\MenuWidget; use Kontenta\KontourSupport\Widgets\PersonalRecentVisitsWidget; use Kontenta\KontourSupport\Widgets\TeamRecentVisitsWidget; -use Kontenta\KontourSupport\Http\Middleware\AuthenticateAdmin; -use Kontenta\KontourSupport\Http\Middleware\RedirectIfAuthenticated; +use Kontenta\KontourSupport\Widgets\UserAccountWidget; use Kontenta\Kontour\Concerns\RegistersAdminRoutes; use Kontenta\Kontour\Concerns\RegistersAdminWidgets; -use Illuminate\Support\Facades\Event; class KontourServiceProvider extends ServiceProvider { @@ -77,6 +78,12 @@ function ($app) { true ); + $this->app->bindIf( + \Kontenta\Kontour\Contracts\UserAccountWidget::class, + UserAccountWidget::class, + true + ); + $this->app->bindIf( \Kontenta\Kontour\Contracts\RecentVisitsRepository::class, RecentVisitsRepository::class, diff --git a/src/Widgets/UserAccountWidget.php b/src/Widgets/UserAccountWidget.php new file mode 100644 index 0000000..ebba44f --- /dev/null +++ b/src/Widgets/UserAccountWidget.php @@ -0,0 +1,21 @@ +user(); + return View::make('kontour::widgets.userAccount', compact('user'))->render(); + } + + public function isAuthorized(Authorizable $user = null): bool + { + return true; + } +} diff --git a/tests/Feature/KontourServiceProviderTest.php b/tests/Feature/KontourServiceProviderTest.php index a914734..bd9220e 100644 --- a/tests/Feature/KontourServiceProviderTest.php +++ b/tests/Feature/KontourServiceProviderTest.php @@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Route; use Kontenta\KontourSupport\Tests\IntegrationTest; use Kontenta\Kontour\Contracts\MenuWidget; +use Kontenta\Kontour\Contracts\UserAccountWidget; class KontourServiceProviderTest extends IntegrationTest { @@ -24,4 +25,9 @@ public function test_menu_widget_can_be_resolved() { $this->assertInstanceOf(MenuWidget::class, app(MenuWidget::class)); } + + public function test_user_account_widget_can_be_resolved() + { + $this->assertInstanceOf(UserAccountWidget::class, app(UserAccountWidget::class)); + } } From 1e7d96791521e2c6fe7d62638c5132e54de04026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Thu, 4 Oct 2018 16:16:52 +0200 Subject: [PATCH 3/6] Break out menu test to own method --- tests/Feature/UserlandControllerTest.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/Feature/UserlandControllerTest.php b/tests/Feature/UserlandControllerTest.php index 6189e23..490072e 100644 --- a/tests/Feature/UserlandControllerTest.php +++ b/tests/Feature/UserlandControllerTest.php @@ -33,8 +33,7 @@ public function test_index_route() $response->assertSee('assertSee('UserlandAdminWidget'); $response->assertDontSee('UnauthorizedWidget'); - $response->assertSee('Userland Tool'); - $response->assertSee('>main<'); + Event::assertDispatched(AdminToolVisited::class, function ($e) { $now = new \DateTimeImmutable(); return $e->visit->getLink()->getUrl() == route('userland.index') and @@ -43,6 +42,15 @@ public function test_index_route() }); } + public function test_menu_widget() + { + $response = $this->actingAs($this->user)->get(route('userland.index')); + + $response->assertSee('
    '); + $response->assertSee('>main<'); + $response->assertSee('Userland Tool'); + } + public function test_recent_visits_widgets() { $otherUser = factory(User::class)->create(); @@ -86,7 +94,7 @@ public function test_item_history_widget() { $response = $this->actingAs($this->user)->get(route('userland.edit', 1)); $response->assertSee('
    '); - $response->assertSee('
  • '); - $response->assertSee('
  • '); + $response->assertSee('
  • '); + $response->assertSee('
  • '); } } From 66dd53e514596e6ccb71c0eb71f9a18676114fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Thu, 4 Oct 2018 16:24:17 +0200 Subject: [PATCH 4/6] Display UserAccountWidget in view --- resources/views/widgets/userAccount.blade.php | 2 ++ src/Providers/KontourServiceProvider.php | 1 + src/Widgets/UserAccountWidget.php | 1 + tests/Feature/UserlandControllerTest.php | 7 +++++++ 4 files changed, 11 insertions(+) create mode 100644 resources/views/widgets/userAccount.blade.php diff --git a/resources/views/widgets/userAccount.blade.php b/resources/views/widgets/userAccount.blade.php new file mode 100644 index 0000000..2cad045 --- /dev/null +++ b/resources/views/widgets/userAccount.blade.php @@ -0,0 +1,2 @@ +
    +
    diff --git a/src/Providers/KontourServiceProvider.php b/src/Providers/KontourServiceProvider.php index 8fd291d..ceabf6e 100644 --- a/src/Providers/KontourServiceProvider.php +++ b/src/Providers/KontourServiceProvider.php @@ -160,6 +160,7 @@ protected function registerEventListeners() protected function registerWidgets() { $this->registerAdminWidget($this->app->make(\Kontenta\Kontour\Contracts\MenuWidget::class), $this->app->make(\Kontenta\Kontour\Contracts\AdminViewManager::class)->navSection()); + $this->registerAdminWidget($this->app->make(\Kontenta\Kontour\Contracts\UserAccountWidget::class), $this->app->make(\Kontenta\Kontour\Contracts\AdminViewManager::class)->headerSection()); } /** diff --git a/src/Widgets/UserAccountWidget.php b/src/Widgets/UserAccountWidget.php index ebba44f..63648bc 100644 --- a/src/Widgets/UserAccountWidget.php +++ b/src/Widgets/UserAccountWidget.php @@ -3,6 +3,7 @@ namespace Kontenta\KontourSupport\Widgets; use Illuminate\Contracts\Auth\Access\Authorizable; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\View; use Kontenta\Kontour\Contracts\UserAccountWidget as UserAccountWidgetContract; diff --git a/tests/Feature/UserlandControllerTest.php b/tests/Feature/UserlandControllerTest.php index 490072e..7b7d6b2 100644 --- a/tests/Feature/UserlandControllerTest.php +++ b/tests/Feature/UserlandControllerTest.php @@ -51,6 +51,13 @@ public function test_menu_widget() $response->assertSee('Userland Tool'); } + public function test_user_account_widget() + { + $response = $this->actingAs($this->user)->get(route('userland.index')); + + $response->assertSee('
    '); + } + public function test_recent_visits_widgets() { $otherUser = factory(User::class)->create(); From 5683853898b08706c2c52d4ec2a0f9a09b28373b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Thu, 4 Oct 2018 16:33:39 +0200 Subject: [PATCH 5/6] Move logout into user account widget --- resources/views/layouts/master.blade.php | 5 ----- resources/views/widgets/userAccount.blade.php | 5 +++++ src/Widgets/UserAccountWidget.php | 2 +- tests/Feature/UserlandControllerTest.php | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/resources/views/layouts/master.blade.php b/resources/views/layouts/master.blade.php index fb6fb0f..988d3f7 100644 --- a/resources/views/layouts/master.blade.php +++ b/resources/views/layouts/master.blade.php @@ -5,11 +5,6 @@ @section('body')
    - {{-- TODO: make this logout form part of a user-widget --}} -
    - {{ csrf_field() }} - -
    @foreach($widget_manager->getWidgetsForSection($view_manager->headerSection()) as $widget) {{ $widget }} @endforeach diff --git a/resources/views/widgets/userAccount.blade.php b/resources/views/widgets/userAccount.blade.php index 2cad045..b002f8d 100644 --- a/resources/views/widgets/userAccount.blade.php +++ b/resources/views/widgets/userAccount.blade.php @@ -1,2 +1,7 @@
    + {{ $user->getDisplayName() }} +
    + {{ csrf_field() }} + +
    diff --git a/src/Widgets/UserAccountWidget.php b/src/Widgets/UserAccountWidget.php index 63648bc..e103211 100644 --- a/src/Widgets/UserAccountWidget.php +++ b/src/Widgets/UserAccountWidget.php @@ -17,6 +17,6 @@ public function toHtml() public function isAuthorized(Authorizable $user = null): bool { - return true; + return (bool) $user; } } diff --git a/tests/Feature/UserlandControllerTest.php b/tests/Feature/UserlandControllerTest.php index 7b7d6b2..1793c86 100644 --- a/tests/Feature/UserlandControllerTest.php +++ b/tests/Feature/UserlandControllerTest.php @@ -54,8 +54,9 @@ public function test_menu_widget() public function test_user_account_widget() { $response = $this->actingAs($this->user)->get(route('userland.index')); - $response->assertSee('
    '); + $response->assertSee($this->user->getDisplayName()); + $response->assertSee(''); } public function test_recent_visits_widgets() From db07a14c4e7bd1f539f520c95d76aeb9de0db014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Thu, 4 Oct 2018 16:36:18 +0200 Subject: [PATCH 6/6] Hide widgets when not logged in --- src/Widgets/ItemHistoryWidget.php | 4 ++-- src/Widgets/MenuWidget.php | 2 +- src/Widgets/PersonalRecentVisitsWidget.php | 2 +- src/Widgets/TeamRecentVisitsWidget.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Widgets/ItemHistoryWidget.php b/src/Widgets/ItemHistoryWidget.php index 4a2e652..c69eb75 100644 --- a/src/Widgets/ItemHistoryWidget.php +++ b/src/Widgets/ItemHistoryWidget.php @@ -32,7 +32,7 @@ public function addEntry(string $action, \DateTime $datetime, AdminUser $user = $this->entries->push(compact('action', 'datetime', 'user')); return $this; } - + public function addCreatedEntry(\DateTime $datetime, AdminUser $user = null): ItemHistoryWidgetContract { return $this->addEntry('created', $datetime, $user); @@ -45,6 +45,6 @@ public function addUpdatedEntry(\DateTime $datetime, AdminUser $user = null): It public function isAuthorized(Authorizable $user = null): bool { - return true; + return (bool) $user; } } diff --git a/src/Widgets/MenuWidget.php b/src/Widgets/MenuWidget.php index 4efaaa3..bdc0ba7 100644 --- a/src/Widgets/MenuWidget.php +++ b/src/Widgets/MenuWidget.php @@ -48,6 +48,6 @@ public function getHeadings(): Collection public function isAuthorized(Authorizable $user = null): bool { - return true; + return (bool) $user; } } diff --git a/src/Widgets/PersonalRecentVisitsWidget.php b/src/Widgets/PersonalRecentVisitsWidget.php index b3c0265..2414f24 100644 --- a/src/Widgets/PersonalRecentVisitsWidget.php +++ b/src/Widgets/PersonalRecentVisitsWidget.php @@ -24,7 +24,7 @@ public function toHtml() public function isAuthorized(Authorizable $user = null): bool { - return true; + return (bool) $user; } private function getVisits() diff --git a/src/Widgets/TeamRecentVisitsWidget.php b/src/Widgets/TeamRecentVisitsWidget.php index a785aa0..8b1858f 100644 --- a/src/Widgets/TeamRecentVisitsWidget.php +++ b/src/Widgets/TeamRecentVisitsWidget.php @@ -24,7 +24,7 @@ public function toHtml() public function isAuthorized(Authorizable $user = null): bool { - return true; + return (bool) $user; } private function getVisits()