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;
|
2017-03-21 22:10:36 +00:00
|
|
|
use App\Policies\AlbumPolicy;
|
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 = [
|
2017-03-21 22:10:36 +00:00
|
|
|
Album::class => AlbumPolicy::class
|
2016-09-01 16:23:39 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register any authentication / authorization services.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
|
|
|
$this->registerPolicies();
|
|
|
|
|
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;
|
|
|
|
});
|
2017-03-21 21:48:55 +00:00
|
|
|
Gate::define('admin-create-albums', function ($user)
|
|
|
|
{
|
|
|
|
return $user->can_create_albums;
|
|
|
|
});
|
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
|
|
|
}
|
|
|
|
}
|