snipe-it/app/Providers/AuthServiceProvider.php

339 lines
11 KiB
PHP
Raw Normal View History

2016-03-25 01:18:05 -07:00
<?php
namespace App\Providers;
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 04:32:24 -08:00
//$this->registerPolicies();
// --------------------------------
// 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) {
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) {
if ($user->hasAccess('admin')) {
return true;
}
});
# -----------------------------------------
# Reports
# -----------------------------------------
2016-12-14 04:32:24 -08:00
Gate::define('reports.view', function ($user) {
if ($user->hasAccess('reports.view')) {
return true;
}
});
# -----------------------------------------
# Assets
# -----------------------------------------
2016-12-14 04:32:24 -08:00
Gate::define('assets.view', function ($user) {
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) {
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) {
if (($user->hasAccess('assets.create')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('assets.checkout', function ($user) {
if (($user->hasAccess('assets.checkout')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('assets.checkin', function ($user) {
if (($user->hasAccess('assets.checkin')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('assets.edit', function ($user) {
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;
}
});
# -----------------------------------------
# Accessories
# -----------------------------------------
2016-12-14 04:32:24 -08:00
Gate::define('accessories.view', function ($user) {
if (($user->hasAccess('accessories.view')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('accessories.create', function ($user) {
if (($user->hasAccess('accessories.create')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('accessories.edit', function ($user) {
if (($user->hasAccess('accessories.edit')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('accessories.delete', function ($user) {
if (($user->hasAccess('accessories.delete')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('accessories.checkout', function ($user) {
if (($user->hasAccess('accessories.checkout')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('accessories.checkin', function ($user) {
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;
}
});
# -----------------------------------------
# Consumables
# -----------------------------------------
2016-12-14 04:32:24 -08:00
Gate::define('consumables.view', function ($user) {
if (($user->hasAccess('consumables.view')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('consumables.create', function ($user) {
if (($user->hasAccess('consumables.create')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('consumables.edit', function ($user) {
if (($user->hasAccess('consumables.edit')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('consumables.delete', function ($user) {
if (($user->hasAccess('consumables.delete')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('consumables.checkout', function ($user) {
if (($user->hasAccess('consumables.checkout')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('consumables.checkin', function ($user) {
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;
}
});
# -----------------------------------------
# Users
# -----------------------------------------
2016-12-14 04:32:24 -08:00
Gate::define('users.view', function ($user) {
if (($user->hasAccess('users.view')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('users.create', function ($user) {
if (($user->hasAccess('users.create')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('users.edit', function ($user) {
if (($user->hasAccess('users.edit')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('users.delete', function ($user) {
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) {
if (($user->hasAccess('components.view')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('components.create', function ($user) {
if (($user->hasAccess('components.create')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('components.edit', function ($user) {
if (($user->hasAccess('components.edit')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('components.delete', function ($user) {
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;
}
});
# -----------------------------------------
# Licenses
# -----------------------------------------
2016-12-14 04:32:24 -08:00
Gate::define('licenses.view', function ($user) {
if (($user->hasAccess('licenses.view')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('licenses.create', function ($user) {
if (($user->hasAccess('licenses.create')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('licenses.edit', function ($user) {
if (($user->hasAccess('licenses.edit')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('licenses.delete', function ($user) {
if (($user->hasAccess('licenses.delete')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('licenses.checkout', function ($user) {
if (($user->hasAccess('licenses.checkout')) || ($user->hasAccess('admin'))) {
return true;
}
});
2016-12-14 04:32:24 -08:00
Gate::define('licenses.checkin', function ($user) {
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;
}
});
# -----------------------------------------
# Self
# -----------------------------------------
2016-12-14 04:32:24 -08:00
Gate::define('self.two_factor', function ($user) {
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
}
}