54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Album;
|
|
use App\Facade\UserConfig;
|
|
use App\Photo;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* The policy mappings for the application.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $policies = [
|
|
'App\Model' => 'App\Policies\ModelPolicy',
|
|
];
|
|
|
|
/**
|
|
* Register any authentication / authorization services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
$this->registerPolicies();
|
|
|
|
Gate::define('album.view', function ($user, Album $album)
|
|
{
|
|
return (!$album->is_private || $album->user_id == $user->id);
|
|
});
|
|
Gate::define('admin-access', function ($user)
|
|
{
|
|
return $user->is_admin;
|
|
});
|
|
Gate::define('admin-create-albums', function ($user)
|
|
{
|
|
return $user->can_create_albums;
|
|
});
|
|
Gate::define('photo.download_original', function ($user, Photo $photo)
|
|
{
|
|
if (!UserConfig::get('restrict_original_download'))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return ($user->id == $photo->user_id);
|
|
});
|
|
}
|
|
}
|