mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-09 06:24:48 +00:00
* Convert string references to `::class` PHP 5.5.9 adds the new static `class` property which provides the fully qualified class name. This is preferred over using strings for class names since the `class` property references are checked by PHP. * Use Faker methods Accessing Faker properties was deprecated in Faker 1.14. * Convert route options to fluent methods Laravel 8 adopts the tuple syntax for controller actions. Since the old options array is incompatible with this syntax, Shift converted them to use modern, fluent methods. * Adopt class based routes * Remove default `app` files * Shift core files * Streamline config files * Set new `ENV` variables * Default new `bootstrap/app.php` * Re-register HTTP middleware * Consolidate service providers * Re-register service providers * Re-register routes * Re-register scheduled commands * Bump Composer dependencies * Use `<env>` tags for configuration `<env>` tags have a lower precedence than system environment variables making it easier to overwrite PHPUnit configuration values in additional environments, such a CI. Review this blog post for more details on configuration precedence when testing Laravel: https://jasonmccreary.me/articles/laravel-testing-configuration-precedence/ * Adopt anonymous migrations * Rename `password_resets` table * Convert `$casts` property to method * Adopt Laravel type hints * Mark base controller as `abstract` * Remove `CreatesApplication` testing trait * Shift cleanup * Fix shift first issues * Updating Rules for laravel 11, sanctum config and pint * Fix Carbon issue on dashboard * Temporary fix for tests while migration is issue fixed on laravel side * Carbon needs numerical values, not strings * Minimum php version * Fix domain installation step not fetching the correct company_id * Fix Role Policy wasn't properly registered ---------
140 lines
4.7 KiB
PHP
140 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Bouncer\Scopes\DefaultScope;
|
|
use App\Policies\CompanyPolicy;
|
|
use App\Policies\CustomerPolicy;
|
|
use App\Policies\DashboardPolicy;
|
|
use App\Policies\EstimatePolicy;
|
|
use App\Policies\ExpensePolicy;
|
|
use App\Policies\InvoicePolicy;
|
|
use App\Policies\ItemPolicy;
|
|
use App\Policies\ModulesPolicy;
|
|
use App\Policies\NotePolicy;
|
|
use App\Policies\OwnerPolicy;
|
|
use App\Policies\PaymentPolicy;
|
|
use App\Policies\RecurringInvoicePolicy;
|
|
use App\Policies\ReportPolicy;
|
|
use App\Policies\RolePolicy;
|
|
use App\Policies\SettingsPolicy;
|
|
use App\Policies\UserPolicy;
|
|
use App\Space\InstallUtils;
|
|
use Gate;
|
|
use Illuminate\Support\Facades\Broadcast;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Silber\Bouncer\Database\Models as BouncerModels;
|
|
use Silber\Bouncer\Database\Role;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* The path to your application's "home" route.
|
|
*
|
|
* Typically, users are redirected here after authentication.
|
|
*
|
|
* @var string
|
|
*/
|
|
public const HOME = '/home';
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
|
|
if (InstallUtils::isDbCreated()) {
|
|
$this->addMenus();
|
|
}
|
|
|
|
Gate::policy(Role::class, RolePolicy::class);
|
|
|
|
$this->bootAuth();
|
|
$this->bootBroadcast();
|
|
}
|
|
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
BouncerModels::scope(new DefaultScope);
|
|
}
|
|
|
|
public function addMenus()
|
|
{
|
|
//main menu
|
|
\Menu::make('main_menu', function ($menu) {
|
|
foreach (config('invoiceshelf.main_menu') as $data) {
|
|
$this->generateMenu($menu, $data);
|
|
}
|
|
});
|
|
|
|
//setting menu
|
|
\Menu::make('setting_menu', function ($menu) {
|
|
foreach (config('invoiceshelf.setting_menu') as $data) {
|
|
$this->generateMenu($menu, $data);
|
|
}
|
|
});
|
|
|
|
\Menu::make('customer_portal_menu', function ($menu) {
|
|
foreach (config('invoiceshelf.customer_menu') as $data) {
|
|
$this->generateMenu($menu, $data);
|
|
}
|
|
});
|
|
}
|
|
|
|
public function generateMenu($menu, $data)
|
|
{
|
|
$menu->add($data['title'], $data['link'])
|
|
->data('icon', $data['icon'])
|
|
->data('name', $data['name'])
|
|
->data('owner_only', $data['owner_only'])
|
|
->data('ability', $data['ability'])
|
|
->data('model', $data['model'])
|
|
->data('group', $data['group']);
|
|
}
|
|
|
|
public function bootAuth()
|
|
{
|
|
|
|
Gate::define('create company', [CompanyPolicy::class, 'create']);
|
|
Gate::define('transfer company ownership', [CompanyPolicy::class, 'transferOwnership']);
|
|
Gate::define('delete company', [CompanyPolicy::class, 'delete']);
|
|
|
|
Gate::define('manage modules', [ModulesPolicy::class, 'manageModules']);
|
|
|
|
Gate::define('manage settings', [SettingsPolicy::class, 'manageSettings']);
|
|
Gate::define('manage company', [SettingsPolicy::class, 'manageCompany']);
|
|
Gate::define('manage backups', [SettingsPolicy::class, 'manageBackups']);
|
|
Gate::define('manage file disk', [SettingsPolicy::class, 'manageFileDisk']);
|
|
Gate::define('manage email config', [SettingsPolicy::class, 'manageEmailConfig']);
|
|
Gate::define('manage notes', [NotePolicy::class, 'manageNotes']);
|
|
Gate::define('view notes', [NotePolicy::class, 'viewNotes']);
|
|
|
|
Gate::define('send invoice', [InvoicePolicy::class, 'send']);
|
|
Gate::define('send estimate', [EstimatePolicy::class, 'send']);
|
|
Gate::define('send payment', [PaymentPolicy::class, 'send']);
|
|
|
|
Gate::define('delete multiple items', [ItemPolicy::class, 'deleteMultiple']);
|
|
Gate::define('delete multiple customers', [CustomerPolicy::class, 'deleteMultiple']);
|
|
Gate::define('delete multiple users', [UserPolicy::class, 'deleteMultiple']);
|
|
Gate::define('delete multiple invoices', [InvoicePolicy::class, 'deleteMultiple']);
|
|
Gate::define('delete multiple estimates', [EstimatePolicy::class, 'deleteMultiple']);
|
|
Gate::define('delete multiple expenses', [ExpensePolicy::class, 'deleteMultiple']);
|
|
Gate::define('delete multiple payments', [PaymentPolicy::class, 'deleteMultiple']);
|
|
Gate::define('delete multiple recurring invoices', [RecurringInvoicePolicy::class, 'deleteMultiple']);
|
|
|
|
Gate::define('view dashboard', [DashboardPolicy::class, 'view']);
|
|
|
|
Gate::define('view report', [ReportPolicy::class, 'viewReport']);
|
|
|
|
Gate::define('owner only', [OwnerPolicy::class, 'managedByOwner']);
|
|
}
|
|
|
|
public function bootBroadcast()
|
|
{
|
|
Broadcast::routes(['middleware' => 'api.auth']);
|
|
}
|
|
}
|