Add filters for avatar
This commit is contained in:
parent
3e249a9902
commit
591b9969aa
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\View\Composers;
|
||||
|
||||
use App\Services\Filter;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
@ -10,20 +11,25 @@ class UserMenuComposer
|
||||
/** @var Request */
|
||||
protected $request;
|
||||
|
||||
public function __construct(Request $request)
|
||||
/** @var Filter */
|
||||
protected $filter;
|
||||
|
||||
public function __construct(Request $request, Filter $filter)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->filter = $filter;
|
||||
}
|
||||
|
||||
public function compose(View $view)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$email = base64_encode($user->email);
|
||||
$avatar = $user->avatar;
|
||||
$avatar = $this->filter->apply(
|
||||
'user_avatar',
|
||||
url('avatar/25/'.$email.'.png?tid='.$user->avatar),
|
||||
[$user]
|
||||
);
|
||||
|
||||
$view->with([
|
||||
'user' => $user,
|
||||
'avatar' => url('avatar/25/'.$email.'.png?tid='.$avatar),
|
||||
]);
|
||||
$view->with(compact('user', 'avatar'));
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\View\Composers;
|
||||
|
||||
use App\Services\Filter;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\View\View;
|
||||
|
||||
@ -10,15 +11,23 @@ class UserPanelComposer
|
||||
/** @var Dispatcher */
|
||||
protected $dispatcher;
|
||||
|
||||
public function __construct(Dispatcher $dispatcher)
|
||||
/** @var Filter */
|
||||
protected $filter;
|
||||
|
||||
public function __construct(Dispatcher $dispatcher, Filter $filter)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->filter = $filter;
|
||||
}
|
||||
|
||||
public function compose(View $view)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$avatar = url('avatar/45/'.base64_encode($user->email).'.png?tid='.$user->avatar);
|
||||
$avatar = $this->filter->apply(
|
||||
'user_avatar',
|
||||
url('avatar/45/'.base64_encode($user->email).'.png?tid='.$user->avatar),
|
||||
[$user]
|
||||
);
|
||||
|
||||
$badges = [];
|
||||
if (auth()->user()->isAdmin()) {
|
||||
@ -26,10 +35,6 @@ class UserPanelComposer
|
||||
}
|
||||
$this->dispatcher->dispatch(new \App\Events\RenderingBadges($badges));
|
||||
|
||||
$view->with([
|
||||
'user' => $user,
|
||||
'avatar' => $avatar,
|
||||
'badges' => $badges,
|
||||
]);
|
||||
$view->with(compact('user', 'avatar', 'badges'));
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,8 @@ class UserControllerTest extends TestCase
|
||||
$filter = Fakes\Filter::fake();
|
||||
|
||||
$user = factory(User::class)->create();
|
||||
factory(\App\Models\Player::class)->create(['uid' => $user->uid]);
|
||||
$uid = $user->uid;
|
||||
factory(\App\Models\Player::class)->create(['uid' => $uid]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get('/user')
|
||||
@ -48,6 +49,12 @@ class UserControllerTest extends TestCase
|
||||
->assertSee((new Parsedown())->text(option_localized('announcement')))
|
||||
->assertSee((string) $user->score);
|
||||
$filter->assertApplied('grid:user.index');
|
||||
$filter->assertApplied('user_avatar', function ($url, $user) use ($uid) {
|
||||
$this->assertTrue(Str::endsWith($url, 'tid=0'));
|
||||
$this->assertEquals($uid, $user->uid);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$unverified = factory(User::class)->create(['verified' => false]);
|
||||
$this->actingAs($unverified)
|
||||
|
Loading…
Reference in New Issue
Block a user