moved offline payments permissions to module
This commit is contained in:
parent
3b652df7cd
commit
319fac06ac
@ -65,16 +65,4 @@ class Event extends Provider
|
||||
'App\Listeners\Common\TaxSummaryReport',
|
||||
'App\Listeners\Common\ProfitLossReport',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ class Roles extends Seeder
|
||||
'modules-my' => 'r',
|
||||
'modules-tiles' => 'r',
|
||||
'notifications' => 'r,u',
|
||||
'offline-payments-settings' => 'r,u,d',
|
||||
'reports-expense-summary' => 'r',
|
||||
'reports-income-summary' => 'r',
|
||||
'reports-income-expense-summary' => 'r',
|
||||
@ -111,7 +110,6 @@ class Roles extends Seeder
|
||||
'sales-revenues' => 'c,r,u,d',
|
||||
'install-updates' => 'r,u',
|
||||
'notifications' => 'r,u',
|
||||
'offline-payments-settings' => 'r,u,d',
|
||||
'reports-expense-summary' => 'r',
|
||||
'reports-income-summary' => 'r',
|
||||
'reports-income-expense-summary' => 'r',
|
||||
|
56
modules/OfflinePayments/Listeners/InstallModule.php
Normal file
56
modules/OfflinePayments/Listeners/InstallModule.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\OfflinePayments\Listeners;
|
||||
|
||||
use App\Events\Module\Installed as Event;
|
||||
use App\Models\Auth\Role;
|
||||
use App\Models\Auth\Permission;
|
||||
|
||||
class InstallModule
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param Event $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
if ($event->alias != 'offline-payments') {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->updatePermissions();
|
||||
}
|
||||
|
||||
protected function updatePermissions()
|
||||
{
|
||||
$permissions = [];
|
||||
|
||||
$permissions[] = Permission::firstOrCreate([
|
||||
'name' => 'read-offline-payments-settings',
|
||||
'display_name' => 'Read Offline Payments Settings',
|
||||
'description' => 'Read Offline Payments Settings',
|
||||
]);
|
||||
|
||||
$permissions[] = Permission::firstOrCreate([
|
||||
'name' => 'update-offline-payments-settings',
|
||||
'display_name' => 'Update Offline Payments Settings',
|
||||
'description' => 'Update Offline Payments Settings',
|
||||
]);
|
||||
|
||||
$roles = Role::all()->filter(function ($r) {
|
||||
return $r->hasPermission('read-admin-panel');
|
||||
});
|
||||
|
||||
foreach ($roles as $role) {
|
||||
foreach ($permissions as $permission) {
|
||||
if ($role->hasPermission($permission->name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$role->attachPermission($permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
28
modules/OfflinePayments/Providers/Event.php
Normal file
28
modules/OfflinePayments/Providers/Event.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\OfflinePayments\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Modules\OfflinePayments\Listeners\InstallModule;
|
||||
use Modules\OfflinePayments\Listeners\ShowPaymentMethod;
|
||||
use Modules\OfflinePayments\Listeners\ShowSetting;
|
||||
|
||||
class Event extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the module.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
\App\Events\Module\Installed::class => [
|
||||
InstallModule::class,
|
||||
],
|
||||
\App\Events\Module\PaymentMethodShowing::class => [
|
||||
ShowPaymentMethod::class,
|
||||
],
|
||||
\App\Events\Module\SettingShowing::class => [
|
||||
ShowSetting::class,
|
||||
],
|
||||
];
|
||||
}
|
@ -3,8 +3,6 @@
|
||||
namespace Modules\OfflinePayments\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider as Provider;
|
||||
use Modules\OfflinePayments\Listeners\ShowPaymentMethod;
|
||||
use Modules\OfflinePayments\Listeners\ShowSetting;
|
||||
|
||||
class Main extends Provider
|
||||
{
|
||||
@ -17,7 +15,6 @@ class Main extends Provider
|
||||
{
|
||||
$this->loadTranslations();
|
||||
$this->loadViews();
|
||||
$this->loadEvents();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,17 +47,6 @@ class Main extends Provider
|
||||
$this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'offline-payments');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadEvents()
|
||||
{
|
||||
$this->app['events']->listen(\App\Events\Module\PaymentMethodShowing::class, ShowPaymentMethod::class);
|
||||
$this->app['events']->listen(\App\Events\Module\SettingShowing::class, ShowSetting::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load routes.
|
||||
*
|
||||
|
@ -4,6 +4,7 @@
|
||||
"category": "payment-method",
|
||||
"active": 1,
|
||||
"providers": [
|
||||
"Modules\\OfflinePayments\\Providers\\Event",
|
||||
"Modules\\OfflinePayments\\Providers\\Main"
|
||||
],
|
||||
"aliases": {},
|
||||
|
Loading…
x
Reference in New Issue
Block a user