Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 11, 2020
1 parent f967dd8 commit 94a3952
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 114 deletions.
13 changes: 0 additions & 13 deletions config/telescope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions src/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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";
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Telescope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
4 changes: 0 additions & 4 deletions stubs/TelescopeServiceProvider.stub
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
$entry->isScheduledTask() ||
$entry->hasMonitoredTag();
});

Telescope::avatar(function ($id, $email) {
//
});
}

/**
Expand Down
84 changes: 0 additions & 84 deletions tests/Http/AvatarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
});
Expand All @@ -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
Expand Down

0 comments on commit 94a3952

Please sign in to comment.