2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2016-09-09 16:59:13 +01:00
|
|
|
use App\Album;
|
2016-09-11 07:19:11 +01:00
|
|
|
use App\Facade\UserConfig;
|
|
|
|
use App\Photo;
|
2016-09-01 16:23:39 +01:00
|
|
|
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();
|
|
|
|
|
2016-09-09 16:59:13 +01:00
|
|
|
Gate::define('album.view', function ($user, Album $album)
|
|
|
|
{
|
|
|
|
return (!$album->is_private || $album->user_id == $user->id);
|
|
|
|
});
|
2016-09-11 07:19:11 +01:00
|
|
|
Gate::define('admin-access', function ($user)
|
|
|
|
{
|
2016-09-01 16:23:39 +01:00
|
|
|
return $user->is_admin;
|
|
|
|
});
|
2016-09-11 07:19:11 +01:00
|
|
|
Gate::define('photo.download_original', function ($user, Photo $photo)
|
|
|
|
{
|
|
|
|
if (!UserConfig::get('restrict_original_download'))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ($user->id == $photo->user_id);
|
|
|
|
});
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
}
|