mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
296de34e8a
I'm going ahead and merging this, since the upgrade doesn't break Flysystem any worse than the current develop is broken, so far as I can tell. * Upgraded framework to Laravel 6 ### TO DO: - Fix password restriction rules- the old library isn’t compatible with Laravel 6 :( - Figure out why in-app API calls are returning “Unauthorized” * More updates from Input:: to Request:: helper * Switch to Request:: from Input * Added passport config * Fixed goofy password minimum in seeder * Added laravel/helpers * Changed ($item) to ($item->id) in forms I have no idea why this is necessary * Changed ($item) to ($item->id) in forms * Updated API middleware to auth:api * Updated with added laravel auth.php values * FIxed *&!^$%^&$^%!!!! ajax issue * Switch to Request::get from Input::get * Switched to Request facade * Added password security minimums back in The package we were using has not been updated to Laravel v6, so I created custom validators instead * Added language strings for error messages for password rules * Fixed `($item)` issue in formActions for partials
171 lines
5.5 KiB
PHP
171 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Accessory;
|
|
use App\Models\Asset;
|
|
use App\Models\AssetModel;
|
|
use App\Models\Category;
|
|
use App\Models\Company;
|
|
use App\Models\Component;
|
|
use App\Models\Consumable;
|
|
use App\Models\CustomField;
|
|
use App\Models\CustomFieldset;
|
|
use App\Models\Department;
|
|
use App\Models\Depreciation;
|
|
use App\Models\License;
|
|
use App\Models\Location;
|
|
use App\Models\Manufacturer;
|
|
use App\Models\Statuslabel;
|
|
use App\Models\Supplier;
|
|
use App\Models\User;
|
|
use App\Policies\AccessoryPolicy;
|
|
use App\Policies\AssetModelPolicy;
|
|
use App\Policies\AssetPolicy;
|
|
use App\Policies\CategoryPolicy;
|
|
use App\Policies\CompanyPolicy;
|
|
use App\Policies\ComponentPolicy;
|
|
use App\Policies\ConsumablePolicy;
|
|
use App\Policies\CustomFieldPolicy;
|
|
use App\Policies\CustomFieldsetPolicy;
|
|
use App\Policies\DepartmentPolicy;
|
|
use App\Policies\DepreciationPolicy;
|
|
use App\Policies\LicensePolicy;
|
|
use App\Policies\LocationPolicy;
|
|
use App\Policies\ManufacturerPolicy;
|
|
use App\Policies\StatuslabelPolicy;
|
|
use App\Policies\SupplierPolicy;
|
|
use App\Policies\UserPolicy;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Laravel\Passport\Passport;
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* The policy mappings for the application.
|
|
*
|
|
* See SnipePermissionsPolicy for additional information.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $policies = [
|
|
Accessory::class => AccessoryPolicy::class,
|
|
Asset::class => AssetPolicy::class,
|
|
AssetModel::class => AssetModelPolicy::class,
|
|
Category::class => CategoryPolicy::class,
|
|
Component::class => ComponentPolicy::class,
|
|
Consumable::class => ConsumablePolicy::class,
|
|
CustomField::class => CustomFieldPolicy::class,
|
|
CustomFieldset::class => CustomFieldsetPolicy::class,
|
|
Department::class => DepartmentPolicy::class,
|
|
Depreciation::class => DepreciationPolicy::class,
|
|
License::class => LicensePolicy::class,
|
|
Location::class => LocationPolicy::class,
|
|
Statuslabel::class => StatuslabelPolicy::class,
|
|
Supplier::class => SupplierPolicy::class,
|
|
User::class => UserPolicy::class,
|
|
Manufacturer::class => ManufacturerPolicy::class,
|
|
Company::class => CompanyPolicy::class,
|
|
];
|
|
|
|
/**
|
|
* Register any authentication / authorization services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
|
|
$this->commands([
|
|
\Laravel\Passport\Console\InstallCommand::class,
|
|
\Laravel\Passport\Console\ClientCommand::class,
|
|
\Laravel\Passport\Console\KeysCommand::class,
|
|
]);
|
|
|
|
|
|
$this->registerPolicies();
|
|
Passport::routes();
|
|
Passport::tokensExpireIn(Carbon::now()->addYears(20));
|
|
Passport::refreshTokensExpireIn(Carbon::now()->addYears(20));
|
|
Passport::withCookieSerialization();
|
|
|
|
|
|
// --------------------------------
|
|
// BEFORE ANYTHING ELSE
|
|
// --------------------------------
|
|
// If this condition is true, ANYTHING else below will be assumed
|
|
// to be true. This can cause weird blade behavior.
|
|
Gate::before(function ($user) {
|
|
if ($user->isSuperUser()) {
|
|
return true;
|
|
}
|
|
});
|
|
|
|
// --------------------------------
|
|
// GENERAL GATES
|
|
// These control general sections of the admin
|
|
// --------------------------------
|
|
Gate::define('admin', function ($user) {
|
|
if ($user->hasAccess('admin')) {
|
|
return true;
|
|
}
|
|
});
|
|
|
|
|
|
// Can the user import CSVs?
|
|
Gate::define('import', function ($user) {
|
|
if ($user->hasAccess('import') ) {
|
|
return true;
|
|
}
|
|
});
|
|
|
|
|
|
# -----------------------------------------
|
|
# Reports
|
|
# -----------------------------------------
|
|
Gate::define('reports.view', function ($user) {
|
|
if ($user->hasAccess('reports.view')) {
|
|
return true;
|
|
}
|
|
});
|
|
|
|
# -----------------------------------------
|
|
# Self
|
|
# -----------------------------------------
|
|
Gate::define('self.two_factor', function ($user) {
|
|
if (($user->hasAccess('self.two_factor')) || ($user->hasAccess('admin'))) {
|
|
return true;
|
|
}
|
|
});
|
|
|
|
Gate::define('self.api', function($user) {
|
|
return $user->hasAccess('self.api');
|
|
});
|
|
|
|
Gate::define('self.edit_location', function($user) {
|
|
return $user->hasAccess('self.edit_location');
|
|
});
|
|
|
|
Gate::define('self.checkout_assets', function($user) {
|
|
return $user->hasAccess('self.checkout_assets');
|
|
});
|
|
|
|
Gate::define('backend.interact', function ($user) {
|
|
return $user->can('view', Statuslabel::class)
|
|
|| $user->can('view', AssetModel::class)
|
|
|| $user->can('view', Category::class)
|
|
|| $user->can('view', Manufacturer::class)
|
|
|| $user->can('view', Supplier::class)
|
|
|| $user->can('view', Department::class)
|
|
|| $user->can('view', Location::class)
|
|
|| $user->can('view', Company::class)
|
|
|| $user->can('view', Manufacturer::class)
|
|
|| $user->can('view', CustomField::class)
|
|
|| $user->can('view', CustomFieldset::class)
|
|
|| $user->can('view', Depreciation::class);
|
|
});
|
|
}
|
|
}
|