2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2016-12-19 11:04:28 -08:00
|
|
|
use App\Models\Accessory;
|
|
|
|
use App\Models\Asset;
|
2017-10-27 18:01:11 -07:00
|
|
|
use App\Models\AssetModel;
|
2017-10-07 14:49:47 -07:00
|
|
|
use App\Models\Category;
|
2017-10-27 18:01:11 -07:00
|
|
|
use App\Models\Component;
|
2016-12-19 11:04:28 -08:00
|
|
|
use App\Models\Consumable;
|
2017-10-27 18:01:11 -07:00
|
|
|
use App\Models\CustomField;
|
|
|
|
use App\Models\Department;
|
2016-12-19 11:04:28 -08:00
|
|
|
use App\Models\License;
|
2017-10-27 18:01:11 -07:00
|
|
|
use App\Models\Location;
|
|
|
|
use App\Models\Statuslabel;
|
|
|
|
use App\Models\Supplier;
|
2017-12-07 20:59:55 -08:00
|
|
|
use App\Models\Manufacturer;
|
2018-01-19 17:51:28 -08:00
|
|
|
use App\Models\Company;
|
2016-12-19 11:04:28 -08:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Policies\AccessoryPolicy;
|
2017-10-27 18:01:11 -07:00
|
|
|
use App\Policies\AssetModelPolicy;
|
2016-12-19 11:04:28 -08:00
|
|
|
use App\Policies\AssetPolicy;
|
2017-10-27 18:01:11 -07:00
|
|
|
use App\Policies\CategoryPolicy;
|
2016-12-19 11:04:28 -08:00
|
|
|
use App\Policies\ComponentPolicy;
|
|
|
|
use App\Policies\ConsumablePolicy;
|
2017-10-27 18:01:11 -07:00
|
|
|
use App\Policies\CustomFieldPolicy;
|
|
|
|
use App\Policies\DepartmentPolicy;
|
2016-12-19 11:04:28 -08:00
|
|
|
use App\Policies\LicensePolicy;
|
2017-10-07 15:07:31 -07:00
|
|
|
use App\Policies\LocationPolicy;
|
2017-10-27 18:01:11 -07:00
|
|
|
use App\Policies\StatuslabelPolicy;
|
|
|
|
use App\Policies\SupplierPolicy;
|
2016-12-19 11:04:28 -08:00
|
|
|
use App\Policies\UserPolicy;
|
2017-12-07 20:59:55 -08:00
|
|
|
use App\Policies\ManufacturerPolicy;
|
2018-01-19 17:51:28 -08:00
|
|
|
use App\Policies\CompanyPolicy;
|
2017-10-27 18:01:11 -07:00
|
|
|
use Carbon\Carbon;
|
2016-03-25 01:18:05 -07:00
|
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
2016-12-19 11:04:28 -08:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
use Laravel\Passport\Passport;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The policy mappings for the application.
|
|
|
|
*
|
2017-12-07 20:59:55 -08:00
|
|
|
* See SnipePermissionsPolicy for additional information.
|
|
|
|
*
|
2016-03-25 01:18:05 -07:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $policies = [
|
2016-12-19 11:04:28 -08:00
|
|
|
Accessory::class => AccessoryPolicy::class,
|
2017-10-27 18:01:11 -07:00
|
|
|
Asset::class => AssetPolicy::class,
|
|
|
|
AssetModel::class => AssetModelPolicy::class,
|
|
|
|
Category::class => CategoryPolicy::class,
|
2016-12-19 11:04:28 -08:00
|
|
|
Component::class => ComponentPolicy::class,
|
|
|
|
Consumable::class => ConsumablePolicy::class,
|
2017-10-27 18:01:11 -07:00
|
|
|
CustomField::class => CustomFieldPolicy::class,
|
|
|
|
Department::class => DepartmentPolicy::class,
|
2016-12-19 11:04:28 -08:00
|
|
|
License::class => LicensePolicy::class,
|
2017-10-07 15:07:31 -07:00
|
|
|
Location::class => LocationPolicy::class,
|
2017-10-27 18:01:11 -07:00
|
|
|
Statuslabel::class => StatuslabelPolicy::class,
|
|
|
|
Supplier::class => SupplierPolicy::class,
|
|
|
|
User::class => UserPolicy::class,
|
2017-12-07 20:59:55 -08:00
|
|
|
Manufacturer::class => ManufacturerPolicy::class,
|
2018-01-19 17:51:28 -08:00
|
|
|
Company::class => CompanyPolicy::class,
|
2016-03-25 01:18:05 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2016-12-14 04:32:24 -08:00
|
|
|
* Register any authentication / authorization services.
|
2016-03-25 01:18:05 -07:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-14 04:32:24 -08:00
|
|
|
public function boot()
|
2016-03-25 01:18:05 -07:00
|
|
|
{
|
2017-04-27 07:09:46 -07:00
|
|
|
|
|
|
|
$this->commands([
|
|
|
|
\Laravel\Passport\Console\InstallCommand::class,
|
|
|
|
\Laravel\Passport\Console\ClientCommand::class,
|
|
|
|
\Laravel\Passport\Console\KeysCommand::class,
|
|
|
|
]);
|
2017-10-27 18:01:11 -07:00
|
|
|
|
2017-04-27 07:09:46 -07:00
|
|
|
|
2016-12-14 10:06:05 -08:00
|
|
|
$this->registerPolicies();
|
|
|
|
Passport::routes();
|
2017-01-11 14:50:26 -08:00
|
|
|
Passport::tokensExpireIn(Carbon::now()->addYears(20));
|
|
|
|
Passport::refreshTokensExpireIn(Carbon::now()->addYears(20));
|
2017-01-11 03:38:55 -08:00
|
|
|
|
|
|
|
|
2016-06-02 02:40:49 -07:00
|
|
|
// --------------------------------
|
|
|
|
// BEFORE ANYTHING ELSE
|
|
|
|
// --------------------------------
|
2017-01-11 14:50:26 -08:00
|
|
|
// If this condition is true, ANYTHING else below will be assumed
|
2016-06-02 02:40:49 -07:00
|
|
|
// to be true. This can cause weird blade behavior.
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::before(function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if ($user->isSuperUser()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// --------------------------------
|
|
|
|
// GENERAL GATES
|
|
|
|
// These control general sections of the admin
|
|
|
|
// --------------------------------
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('admin', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if ($user->hasAccess('admin')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------
|
|
|
|
# Reports
|
|
|
|
# -----------------------------------------
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('reports.view', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if ($user->hasAccess('reports.view')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-31 16:52:25 -07:00
|
|
|
# -----------------------------------------
|
|
|
|
# Self
|
|
|
|
# -----------------------------------------
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('self.two_factor', function ($user) {
|
2016-10-31 16:52:25 -07:00
|
|
|
if (($user->hasAccess('self.two_factor')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2017-10-27 18:01:11 -07:00
|
|
|
|
2018-02-25 12:10:02 -08:00
|
|
|
Gate::define('self.api', function($user) {
|
|
|
|
return $user->hasAccess('self.api');
|
|
|
|
});
|
|
|
|
|
2017-10-27 18:01:11 -07:00
|
|
|
Gate::define('backend.interact', function ($user) {
|
|
|
|
return $user->can('view', \App\Models\Statuslabel::class)
|
|
|
|
|| $user->can('view', \App\Models\AssetModel::class)
|
|
|
|
|| $user->can('view', \App\Models\Category::class)
|
|
|
|
|| $user->can('view', \App\Models\Manufacturer::class)
|
|
|
|
|| $user->can('view', \App\Models\Supplier::class)
|
|
|
|
|| $user->can('view', \App\Models\Department::class)
|
|
|
|
|| $user->can('view', \App\Models\Location::class)
|
|
|
|
|| $user->can('view', \App\Models\Company::class)
|
2017-12-07 20:59:55 -08:00
|
|
|
|| $user->can('view', \App\Models\Manufacturer::class)
|
2018-01-19 17:51:28 -08:00
|
|
|
|| $user->can('view', \App\Models\Company::class)
|
2018-03-07 13:37:37 -08:00
|
|
|
|| $user->can('view', \App\Models\CustomField::class)
|
2017-10-27 18:01:11 -07:00
|
|
|
|| $user->can('view', \App\Models\Depreciation::class);
|
|
|
|
});
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|