diff --git a/config/telescope.php b/config/telescope.php index 086252d4f..1fed214ae 100644 --- a/config/telescope.php +++ b/config/telescope.php @@ -80,19 +80,6 @@ Authorize::class, ], - /* - |-------------------------------------------------------------------------- - | Telescope Avatar Service - |-------------------------------------------------------------------------- - | - | This option may be used to control how to show an avatar for authorized - | users. 'gravatar' will lookup an avatar by the user's email address. - | 'custom' requires registering a callback via Telescope::avatar(). - | - */ - - 'avatar_driver' => 'gravatar', - /* |-------------------------------------------------------------------------- | Ignored Paths & Commands diff --git a/src/Avatar.php b/src/Avatar.php index a6c0a8d59..536bc3d10 100644 --- a/src/Avatar.php +++ b/src/Avatar.php @@ -17,7 +17,7 @@ class Avatar /** * Get an avatar URL for an entry user. * - * @param array $user User payload from the EntryResult. + * @param array $user * @return string|null */ public static function url(array $user) @@ -26,16 +26,11 @@ public static function url(array $user) return; } - switch (config('telescope.avatar_driver', 'gravatar')) { - case 'custom': - return static::resolve($user); - case 'gravatar': - $hash = md5(Str::lower($user['email'])); - - return "https://www.gravatar.com/avatar/{$hash}?s=200"; - default: - break; + if (isset(static::$callback)) { + return static::resolve($user); } + + return "https://www.gravatar.com/avatar/".md5(Str::lower($user['email']))."?s=200"; } /** diff --git a/src/Telescope.php b/src/Telescope.php index 0d715c9b3..dbd7e5ca9 100644 --- a/src/Telescope.php +++ b/src/Telescope.php @@ -688,12 +688,13 @@ public static function night() * Register the Telescope user avatar callback. * * @param \Closure $callback + * @return static */ public static function avatar(Closure $callback) { - if (config('telescope.avatar_driver') === 'custom') { - Avatar::register($callback); - } + Avatar::register($callback); + + return new static; } /** diff --git a/stubs/TelescopeServiceProvider.stub b/stubs/TelescopeServiceProvider.stub index f444a92bb..a9ddad224 100644 --- a/stubs/TelescopeServiceProvider.stub +++ b/stubs/TelescopeServiceProvider.stub @@ -31,10 +31,6 @@ class TelescopeServiceProvider extends TelescopeApplicationServiceProvider $entry->isScheduledTask() || $entry->hasMonitoredTag(); }); - - Telescope::avatar(function ($id, $email) { - // - }); } /** diff --git a/tests/Http/AvatarTest.php b/tests/Http/AvatarTest.php index e332d4ec9..002e289ee 100644 --- a/tests/Http/AvatarTest.php +++ b/tests/Http/AvatarTest.php @@ -48,8 +48,6 @@ public function it_can_register_custom_avatar_path() ]); }); - $this->app->get('config')->set('telescope.avatar_driver', 'custom'); - Telescope::avatar(function ($id) { return "/images/{$id}.jpg"; }); @@ -74,88 +72,6 @@ public function it_can_register_custom_avatar_path() ], ]); } - - /** - * @test - */ - public function it_will_not_register_custom_avatar_path_when_not_configured() - { - $user = null; - - Telescope::withoutRecording(function () use (&$user) { - $this->loadLaravelMigrations(); - - $user = UserEloquent::create([ - 'id' => 1, - 'name' => 'Telescope', - 'email' => 'telescope@laravel.com', - 'password' => 'secret', - ]); - }); - - Telescope::avatar(function ($id) { - return "/images/{$id}.jpg"; - }); - - $this->actingAs($user); - - $this->app->get(LoggerInterface::class)->error('Avatar path will default to Gravatar.', [ - 'exception' => 'Some error message', - ]); - - $entry = $this->loadTelescopeEntries()->first(); - - $this->get("/telescope/telescope-api/logs/{$entry->uuid}") - ->assertOk() - ->assertJson([ - 'entry' => [ - 'content' => [ - 'user' => [ - 'avatar' => 'https://www.gravatar.com/avatar/dac001a0dfeebe3b320cefa9f3a7d813?s=200', - ], - ], - ], - ]); - } - - /** - * @test - */ - public function it_will_not_set_avatar_path_when_the_configuration_is_empty() - { - $user = null; - - Telescope::withoutRecording(function () use (&$user) { - $this->loadLaravelMigrations(); - - $user = UserEloquent::create([ - 'id' => 1, - 'name' => 'Telescope', - 'email' => 'telescope@laravel.com', - 'password' => 'secret', - ]); - }); - - $this->app->get('config')->set('telescope.avatar_driver', ''); - - Telescope::avatar(function ($id) { - return "/images/{$id}.jpg"; - }); - - $this->actingAs($user); - - $this->app->get(LoggerInterface::class)->error('Avatar path will not be generated.', [ - 'exception' => 'Some error message', - ]); - - $entry = $this->loadTelescopeEntries()->first(); - - $json = $this->get("/telescope/telescope-api/logs/{$entry->uuid}") - ->assertOk() - ->json(); - - $this->assertArrayNotHasKey('avatar', $json['entry']['content']['user']); - } } class UserEloquent extends Model implements Authenticatable