added permission for opening a closed expense
This commit is contained in:
@@ -347,7 +347,7 @@ class FormEntertainmentPresentationController extends Controller
|
|||||||
|
|
||||||
public function open($id)
|
public function open($id)
|
||||||
{
|
{
|
||||||
$this->checkAuthorization(auth()->user(), ['final_approval.approve']);
|
$this->checkAuthorization(auth()->user(), ['final_approval.open']);
|
||||||
|
|
||||||
$form = FormEntertaimentPresentation::findOrfail($id);
|
$form = FormEntertaimentPresentation::findOrfail($id);
|
||||||
$form->update([
|
$form->update([
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ class FormMeetingSeminarController extends Controller
|
|||||||
|
|
||||||
public function open($id)
|
public function open($id)
|
||||||
{
|
{
|
||||||
$this->checkAuthorization(auth()->user(), ['final_approval.approve']);
|
$this->checkAuthorization(auth()->user(), ['final_approval.open']);
|
||||||
|
|
||||||
$form = FormMeetingSeminar::findOrfail($id);
|
$form = FormMeetingSeminar::findOrfail($id);
|
||||||
$form->update([
|
$form->update([
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ class FormOtherController extends Controller
|
|||||||
|
|
||||||
public function open($id)
|
public function open($id)
|
||||||
{
|
{
|
||||||
$this->checkAuthorization(auth()->user(), ['final_approval.approve']);
|
$this->checkAuthorization(auth()->user(), ['final_approval.open']);
|
||||||
|
|
||||||
$form = FormOthers::findOrfail($id);
|
$form = FormOthers::findOrfail($id);
|
||||||
$form->update([
|
$form->update([
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ class FormUpCountryController extends Controller
|
|||||||
|
|
||||||
public function open($id)
|
public function open($id)
|
||||||
{
|
{
|
||||||
$this->checkAuthorization(auth()->user(), ['final_approval.approve']);
|
$this->checkAuthorization(auth()->user(), ['final_approval.open']);
|
||||||
|
|
||||||
$form = FormUpCountry::findOrfail($id);
|
$form = FormUpCountry::findOrfail($id);
|
||||||
$form->update([
|
$form->update([
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ class FormVehicleController extends Controller
|
|||||||
|
|
||||||
public function open($id)
|
public function open($id)
|
||||||
{
|
{
|
||||||
$this->checkAuthorization(auth()->user(), ['final_approval.approve']);
|
$this->checkAuthorization(auth()->user(), ['final_approval.open']);
|
||||||
|
|
||||||
$form = FormVehicleRunningCost::findOrfail($id);
|
$form = FormVehicleRunningCost::findOrfail($id);
|
||||||
$form->update([
|
$form->update([
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use Database\Seeds\RayonSeeder;
|
|||||||
use Database\Seeds\RolePermissionSeeder2;
|
use Database\Seeds\RolePermissionSeeder2;
|
||||||
use Database\Seeds\RolePermissionSeeder3;
|
use Database\Seeds\RolePermissionSeeder3;
|
||||||
use Database\Seeds\RolePermissionSeeder4;
|
use Database\Seeds\RolePermissionSeeder4;
|
||||||
|
use Database\Seeds\RolePermissionSeeder5;
|
||||||
|
|
||||||
class DatabaseSeeder extends Seeder
|
class DatabaseSeeder extends Seeder
|
||||||
{
|
{
|
||||||
@@ -26,6 +27,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
// $this->call(RayonSeeder::class);
|
// $this->call(RayonSeeder::class);
|
||||||
// $this->call(RolePermissionSeeder2::class);
|
// $this->call(RolePermissionSeeder2::class);
|
||||||
// $this->call(RolePermissionSeeder3::class);
|
// $this->call(RolePermissionSeeder3::class);
|
||||||
$this->call(RolePermissionSeeder4::class);
|
// $this->call(RolePermissionSeeder4::class);
|
||||||
|
$this->call(RolePermissionSeeder5::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeds;
|
||||||
|
|
||||||
|
use App\Models\Admin;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Spatie\Permission\Models\Role;
|
||||||
|
use Spatie\Permission\Models\Permission;
|
||||||
|
|
||||||
|
class RolePermissionSeeder5 extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Enable these options if you need same role and other permission for User Model
|
||||||
|
* Else, please follow the below steps for admin guard
|
||||||
|
*/
|
||||||
|
$permissions = [
|
||||||
|
[
|
||||||
|
'group_name' => 'final_approval',
|
||||||
|
'permissions' => [
|
||||||
|
'final_approval.open',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'group_name' => 'audit.trail',
|
||||||
|
'permissions' => [
|
||||||
|
'audit.trail.view',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'group_name' => 'report',
|
||||||
|
'permissions' => [
|
||||||
|
'report.view',
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
// Do same for the admin guard for tutorial purposes.
|
||||||
|
$admin = Admin::where('username', 'superadmin')->first();
|
||||||
|
$roleSuperAdmin = $this->maybeCreateSuperAdminRole($admin);
|
||||||
|
|
||||||
|
// Create and Assign Permissions
|
||||||
|
for ($i = 0; $i < count($permissions); $i++) {
|
||||||
|
$permissionGroup = $permissions[$i]['group_name'];
|
||||||
|
for ($j = 0; $j < count($permissions[$i]['permissions']); $j++) {
|
||||||
|
$permissionExist = Permission::where('name', $permissions[$i]['permissions'][$j])->first();
|
||||||
|
if (is_null($permissionExist)) {
|
||||||
|
$permission = Permission::create(
|
||||||
|
[
|
||||||
|
'name' => $permissions[$i]['permissions'][$j],
|
||||||
|
'group_name' => $permissionGroup,
|
||||||
|
'guard_name' => 'admin'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$roleSuperAdmin->givePermissionTo($permission);
|
||||||
|
$permission->assignRole($roleSuperAdmin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign super admin role permission to superadmin user
|
||||||
|
if ($admin) {
|
||||||
|
$admin->assignRole($roleSuperAdmin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function maybeCreateSuperAdminRole($admin): Role
|
||||||
|
{
|
||||||
|
if (is_null($admin)) {
|
||||||
|
$roleSuperAdmin = Role::create(['name' => 'superadmin', 'guard_name' => 'admin']);
|
||||||
|
} else {
|
||||||
|
$roleSuperAdmin = Role::where('name', 'superadmin')->where('guard_name', 'admin')->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($roleSuperAdmin)) {
|
||||||
|
$roleSuperAdmin = Role::create(['name' => 'superadmin', 'guard_name' => 'admin']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $roleSuperAdmin;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -191,7 +191,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
@else
|
@else
|
||||||
@if ($item->final_approved_at)
|
@if ($item->final_approved_at && auth()->user()->can('final_approval.open'))
|
||||||
<form action="{{ route('forms.entertainment.open', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');">
|
<form action="{{ route('forms.entertainment.open', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');">
|
||||||
@csrf
|
@csrf
|
||||||
@method('PUT')
|
@method('PUT')
|
||||||
|
|||||||
@@ -191,7 +191,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
@else
|
@else
|
||||||
@if ($item->final_approved_at)
|
@if ($item->final_approved_at && auth()->user()->can('final_approval.open'))
|
||||||
<form action="{{ route('forms.meeting.open', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');">
|
<form action="{{ route('forms.meeting.open', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');">
|
||||||
@csrf
|
@csrf
|
||||||
@method('PUT')
|
@method('PUT')
|
||||||
|
|||||||
@@ -189,7 +189,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
@else
|
@else
|
||||||
@if ($item->final_approved_at)
|
@if ($item->final_approved_at && auth()->user()->can('final_approval.open'))
|
||||||
<form action="{{ route('forms.other.open', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');">
|
<form action="{{ route('forms.other.open', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');">
|
||||||
@csrf
|
@csrf
|
||||||
@method('PUT')
|
@method('PUT')
|
||||||
|
|||||||
@@ -191,7 +191,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
@else
|
@else
|
||||||
@if ($item->final_approved_at)
|
@if ($item->final_approved_at && auth()->user()->can('final_approval.open'))
|
||||||
<form action="{{ route('forms.up-country.open', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');">
|
<form action="{{ route('forms.up-country.open', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');">
|
||||||
@csrf
|
@csrf
|
||||||
@method('PUT')
|
@method('PUT')
|
||||||
|
|||||||
@@ -193,7 +193,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
@else
|
@else
|
||||||
@if ($item->final_approved_at)
|
@if ($item->final_approved_at && auth()->user()->can('final_approval.open'))
|
||||||
<form action="{{ route('forms.vehicle.open', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');">
|
<form action="{{ route('forms.vehicle.open', $item->id) }}" method="POST" class="d-inline"onsubmit="return confirm('Are you sure you want to approve this item?');">
|
||||||
@csrf
|
@csrf
|
||||||
@method('PUT')
|
@method('PUT')
|
||||||
|
|||||||
Reference in New Issue
Block a user