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 new file mode 100644 index 0000000..b002f8d --- /dev/null +++ b/resources/views/widgets/userAccount.blade.php @@ -0,0 +1,7 @@ +
+ {{ $user->getDisplayName() }} +
+ {{ csrf_field() }} + +
+
diff --git a/src/Providers/KontourServiceProvider.php b/src/Providers/KontourServiceProvider.php index 6ecda92..ceabf6e 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, @@ -153,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/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() diff --git a/src/Widgets/UserAccountWidget.php b/src/Widgets/UserAccountWidget.php new file mode 100644 index 0000000..e103211 --- /dev/null +++ b/src/Widgets/UserAccountWidget.php @@ -0,0 +1,22 @@ +user(); + return View::make('kontour::widgets.userAccount', compact('user'))->render(); + } + + public function isAuthorized(Authorizable $user = null): bool + { + return (bool) $user; + } +} diff --git a/tests/Feature/KontourServiceProviderTest.php b/tests/Feature/KontourServiceProviderTest.php index e63a95f..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 { @@ -20,8 +21,13 @@ 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)); } + + public function test_user_account_widget_can_be_resolved() + { + $this->assertInstanceOf(UserAccountWidget::class, app(UserAccountWidget::class)); + } } diff --git a/tests/Feature/UserlandControllerTest.php b/tests/Feature/UserlandControllerTest.php index 6189e23..1793c86 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,23 @@ public function test_index_route() }); } + public function test_menu_widget() + { + $response = $this->actingAs($this->user)->get(route('userland.index')); + + $response->assertSee('