2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2016-12-14 10:06:05 -08:00
|
|
|
use Laravel\Passport\Passport;
|
2016-12-14 04:32:24 -08:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2016-03-25 01:18:05 -07:00
|
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
|
|
|
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The policy mappings for the application.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $policies = [
|
2016-12-14 04:32:24 -08:00
|
|
|
//'App\Model' => 'App\Policies\ModelPolicy',
|
|
|
|
// We should switch to the below
|
|
|
|
// App\Post::class => PostPolicy::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
|
|
|
{
|
2016-12-14 10:06:05 -08:00
|
|
|
$this->registerPolicies();
|
|
|
|
Passport::routes();
|
2016-06-02 02:40:49 -07:00
|
|
|
|
|
|
|
// --------------------------------
|
|
|
|
// BEFORE ANYTHING ELSE
|
|
|
|
// --------------------------------
|
|
|
|
// If this condition is true, ANYTHING else below will be asssumed
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------
|
|
|
|
# Assets
|
|
|
|
# -----------------------------------------
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('assets.view', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('assets.view')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('assets.view.requestable', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('assets.view.requestable')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('assets.create', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('assets.create')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('assets.checkout', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('assets.checkout')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('assets.checkin', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('assets.checkin')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('assets.edit', function ($user) {
|
2016-08-09 16:38:43 -07:00
|
|
|
if (($user->hasAccess('assets.edit')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-02 00:54:38 -07:00
|
|
|
// Checks for some level of management
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('assets.manage', function ($user) {
|
2016-08-02 00:54:38 -07:00
|
|
|
if (($user->hasAccess('assets.checkin')) || ($user->hasAccess('assets.edit')) || ($user->hasAccess('assets.delete')) || ($user->hasAccess('assets.checkout')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-02 02:40:49 -07:00
|
|
|
|
|
|
|
# -----------------------------------------
|
|
|
|
# Accessories
|
|
|
|
# -----------------------------------------
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('accessories.view', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('accessories.view')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('accessories.create', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('accessories.create')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('accessories.edit', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('accessories.edit')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('accessories.delete', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('accessories.delete')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('accessories.checkout', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('accessories.checkout')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('accessories.checkin', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('accessories.checkin')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-02 00:54:38 -07:00
|
|
|
// Checks for some level of management
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('accessories.manage', function ($user) {
|
2016-08-02 00:54:38 -07:00
|
|
|
if (($user->hasAccess('accessories.checkin')) || ($user->hasAccess('accessories.edit')) || ($user->hasAccess('accessories.checkout')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-02 02:40:49 -07:00
|
|
|
# -----------------------------------------
|
|
|
|
# Consumables
|
|
|
|
# -----------------------------------------
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('consumables.view', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('consumables.view')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('consumables.create', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('consumables.create')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('consumables.edit', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('consumables.edit')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('consumables.delete', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('consumables.delete')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('consumables.checkout', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('consumables.checkout')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('consumables.checkin', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('consumables.checkin')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-02 00:54:38 -07:00
|
|
|
// Checks for some level of management
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('consumables.manage', function ($user) {
|
2016-08-02 00:54:38 -07:00
|
|
|
if (($user->hasAccess('consumables.checkin')) || ($user->hasAccess('consumables.edit')) || ($user->hasAccess('consumables.delete')) || ($user->hasAccess('consumables.checkout')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-02 02:40:49 -07:00
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------
|
|
|
|
# Users
|
|
|
|
# -----------------------------------------
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('users.view', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('users.view')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('users.create', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('users.create')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('users.edit', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('users.edit')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('users.delete', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('users.delete')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------
|
|
|
|
# Components
|
|
|
|
# -----------------------------------------
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('components.view', function ($user) {
|
2016-07-28 20:59:42 -07:00
|
|
|
if (($user->hasAccess('components.view')) || ($user->hasAccess('admin'))) {
|
2016-06-02 02:40:49 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('components.create', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('components.create')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('components.edit', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('components.edit')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('components.delete', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('components.delete')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('components.checkout', function ($user) {
|
2016-09-28 22:57:19 -07:00
|
|
|
if (($user->hasAccess('components.checkout')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-02 00:54:38 -07:00
|
|
|
// Checks for some level of management
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('components.manage', function ($user) {
|
2016-08-02 00:54:38 -07:00
|
|
|
if (($user->hasAccess('components.edit')) || ($user->hasAccess('components.delete')) || ($user->hasAccess('components.checkout')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-02 02:40:49 -07:00
|
|
|
|
|
|
|
# -----------------------------------------
|
|
|
|
# Licenses
|
|
|
|
# -----------------------------------------
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('licenses.view', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('licenses.view')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('licenses.create', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('licenses.create')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('licenses.edit', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('licenses.edit')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('licenses.delete', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('licenses.delete')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('licenses.checkout', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('licenses.checkout')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('licenses.checkin', function ($user) {
|
2016-06-02 02:40:49 -07:00
|
|
|
if (($user->hasAccess('licenses.checkin')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('licenses.keys', function ($user) {
|
2016-07-28 21:31:53 -07:00
|
|
|
if (($user->hasAccess('licenses.keys')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-02 00:54:38 -07:00
|
|
|
// Checks for some level of management
|
2016-12-14 04:32:24 -08:00
|
|
|
Gate::define('licenses.manage', function ($user) {
|
2016-08-02 00:54:38 -07:00
|
|
|
if (($user->hasAccess('licenses.checkin')) || ($user->hasAccess('licenses.edit')) || ($user->hasAccess('licenses.delete')) || ($user->hasAccess('licenses.checkout')) || ($user->hasAccess('admin'))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-02 02:40:49 -07:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-12-14 04:32:24 -08:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
}
|