Add Access group admin surfaces, booking soft deletes, refund crash fix
Access group (Filament):
- StaffResource: manage users with an admin-tier role, gated by manage_staff
- CustomerResource: read-only view of role-less users, gated by view_customers
- RoleResource: edit permissions per role (fixed role set), gated by manage_roles
- ManageAppSettings: tabbed General/Booking settings page that reads/writes
real .env keys via new EnvFileWriter (no parallel DB settings table, so
BookingService/config('booking.*') stay unchanged)
- Moved Access above Catalog in the nav group order
- New permissions: manage_staff, manage_roles, view_customers, manage_settings
Booking soft deletes:
- bookings.deleted_at + SoftDeletes on the Booking model
- BookingPolicy::delete (manage_bookings, cancelled/expired only) and
::restore (manage_bookings)
- DeleteBookingTableAction/RestoreBookingTableAction + TrashedFilter on
BookingsTable, using authorize() so the policy is enforced at call time,
not just cosmetically hidden
Refund crash fix:
- ProcessRefundAction passed a nullable $payment->booking into
RefundBookingAction's non-nullable Booking param — a soft-deleted
booking's payment reaching the refund picker was an uncaught TypeError.
Excluded such payments from the picker and added a defensive guard.
- Same unguarded $event->payment->booking / $event->refund->payment->booking
pattern fixed in the MarkBookingPaid/MarkBookingRefunded queued listeners.
289 tests passing.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Livewire\Livewire;
|
||||
use Modules\Identity\Database\Seeders\RolePermissionSeeder;
|
||||
use Modules\Identity\Filament\Pages\ManageAppSettings;
|
||||
use Modules\Shared\Support\EnvFileWriter;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->seed(RolePermissionSeeder::class);
|
||||
|
||||
// Never let a test write to the real project .env — bind the writer to
|
||||
// a throwaway temp file instead.
|
||||
$this->envPath = sys_get_temp_dir().'/manage-app-settings-test-'.uniqid().'.env';
|
||||
file_put_contents($this->envPath, "APP_NAME=Laravel\n");
|
||||
app()->instance(EnvFileWriter::class, new EnvFileWriter($this->envPath));
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
@unlink($this->envPath);
|
||||
});
|
||||
|
||||
test('an admin without manage_settings is forbidden from the app settings page', function () {
|
||||
$support = User::factory()->create();
|
||||
$support->assignRole('support');
|
||||
|
||||
$this->actingAs($support)->get('/admin/manage-app-settings')->assertForbidden();
|
||||
});
|
||||
|
||||
test('a super_admin can view and save app settings, writing them to .env', function () {
|
||||
$superAdmin = User::factory()->create();
|
||||
$superAdmin->assignRole('super_admin');
|
||||
$this->actingAs($superAdmin);
|
||||
|
||||
Livewire::test(ManageAppSettings::class)
|
||||
->assertOk()
|
||||
->fillForm([
|
||||
'site_name' => 'EV Booking Co',
|
||||
'support_email' => 'help@evbooking.test',
|
||||
'support_phone' => '+95912345678',
|
||||
'timezone' => 'Asia/Yangon',
|
||||
'currency' => 'MMK',
|
||||
'back_seat_enabled' => false,
|
||||
'whole_vehicle_enabled' => true,
|
||||
'front_seat_max_per_booking' => 2,
|
||||
])
|
||||
->call('save')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
$contents = file_get_contents($this->envPath);
|
||||
|
||||
expect($contents)
|
||||
->toContain('APP_NAME="EV Booking Co"')
|
||||
->toContain('SUPPORT_EMAIL=help@evbooking.test')
|
||||
->toContain('APP_TIMEZONE=Asia/Yangon')
|
||||
->toContain('APP_CURRENCY=MMK')
|
||||
->toContain('BOOKING_BACK_SEAT_ENABLED=false')
|
||||
->toContain('BOOKING_WHOLE_VEHICLE_ENABLED=true')
|
||||
->toContain('BOOKING_FRONT_SEAT_MAX_PER_BOOKING=2');
|
||||
});
|
||||
|
||||
test('front seat max per booking must be at least 1', function () {
|
||||
$superAdmin = User::factory()->create();
|
||||
$superAdmin->assignRole('super_admin');
|
||||
$this->actingAs($superAdmin);
|
||||
|
||||
Livewire::test(ManageAppSettings::class)
|
||||
->fillForm(['front_seat_max_per_booking' => 0])
|
||||
->call('save')
|
||||
->assertHasFormErrors(['front_seat_max_per_booking']);
|
||||
});
|
||||
Reference in New Issue
Block a user