36 changed files with 209 additions and 269 deletions
@ -0,0 +1,18 @@ |
|||
<?php |
|||
|
|||
namespace App\Domains\Admission\Actions\StudyModeProvisioning; |
|||
|
|||
use App\Domains\Admission\DTOs\StudyModeProvisioning\DefineAcademicProgramDTO; |
|||
use App\Domains\Admission\Models\AcademicProgram; |
|||
|
|||
class DefineAcademicProgram |
|||
{ |
|||
public function execute(DefineAcademicProgramDTO $dto): void |
|||
{ |
|||
AcademicProgram::create([ |
|||
'name' => $dto->name, |
|||
'code' => $dto->code, |
|||
'status' => $dto->status, |
|||
]); |
|||
} |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Domains\Admission\Actions\StudyModeProvisioning; |
|||
|
|||
use App\Domains\Admission\DTOs\StudyModeProvisioning\DefineProgramTrackDTO; |
|||
use App\Domains\Admission\Models\ProgramTrack; |
|||
|
|||
class DefineProgramTrack |
|||
{ |
|||
public function execute(DefineProgramTrackDTO $dto): void |
|||
{ |
|||
ProgramTrack::create([ |
|||
'name' => $dto->name, |
|||
'code' => $dto->code, |
|||
'status' => $dto->status, |
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
<?php |
|||
|
|||
namespace App\Domains\Admission\Policies; |
|||
|
|||
use App\Domains\Admission\Models\AcademicProgram; |
|||
use App\Domains\Identity\Models\User; |
|||
|
|||
class AcademicProgramPolicy |
|||
{ |
|||
/** |
|||
* Determine whether the user can view any models. |
|||
*/ |
|||
public function viewAny(User $user): bool |
|||
{ |
|||
return $user->hasPermissionTo('academic-program.viewAny'); |
|||
} |
|||
|
|||
/** |
|||
* Determine whether the user can view the model. |
|||
*/ |
|||
public function view(User $user, AcademicProgram $model): bool |
|||
{ |
|||
return $user->hasPermissionTo('academic-program.view'); |
|||
} |
|||
|
|||
/** |
|||
* Determine whether the user can create models. |
|||
*/ |
|||
public function create(User $user): bool |
|||
{ |
|||
return $user->hasPermissionTo('academic-program.create'); |
|||
} |
|||
|
|||
/** |
|||
* Determine whether the user can update the model. |
|||
*/ |
|||
public function update(User $user, AcademicProgram $model): bool |
|||
{ |
|||
return $user->hasPermissionTo('academic-program.update'); |
|||
} |
|||
|
|||
/** |
|||
* Determine whether the user can delete the model. |
|||
*/ |
|||
public function delete(User $user, AcademicProgram $model): bool |
|||
{ |
|||
return $user->hasPermissionTo('academic-program.delete'); |
|||
} |
|||
} |
|||
@ -1,49 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Domains\Admission\Policies; |
|||
|
|||
use App\Domains\Admission\Models\ProgramTrack; |
|||
use App\Domains\Identity\Models\User; |
|||
|
|||
class ProgramTrackPolicy |
|||
{ |
|||
/** |
|||
* Determine whether the user can view any models. |
|||
*/ |
|||
public function viewAny(User $user): bool |
|||
{ |
|||
return $user->hasPermissionTo('program-track.viewAny'); |
|||
} |
|||
|
|||
/** |
|||
* Determine whether the user can view the model. |
|||
*/ |
|||
public function view(User $user, ProgramTrack $model): bool |
|||
{ |
|||
return $user->hasPermissionTo('program-track.view'); |
|||
} |
|||
|
|||
/** |
|||
* Determine whether the user can create models. |
|||
*/ |
|||
public function create(User $user): bool |
|||
{ |
|||
return $user->hasPermissionTo('program-track.create'); |
|||
} |
|||
|
|||
/** |
|||
* Determine whether the user can update the model. |
|||
*/ |
|||
public function update(User $user, ProgramTrack $model): bool |
|||
{ |
|||
return $user->hasPermissionTo('program-track.update'); |
|||
} |
|||
|
|||
/** |
|||
* Determine whether the user can delete the model. |
|||
*/ |
|||
public function delete(User $user, ProgramTrack $model): bool |
|||
{ |
|||
return $user->hasPermissionTo('program-track.delete'); |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Web\Admission; |
|||
|
|||
use App\Attributes\LayoutData; |
|||
use App\Attributes\Seo; |
|||
use App\Http\Controllers\Controller; |
|||
use App\Http\DataTables\Admission\AcademicProgramDataTable; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class AcademicProgramController extends Controller |
|||
{ |
|||
/** |
|||
* Handle the incoming request. |
|||
*/ |
|||
#[Seo( |
|||
title: 'domains/admission/seo.academic-program.title', |
|||
description: 'domains/admission/seo.academic-program.description', |
|||
keywords: 'domains/admission/seo.academic-program.keywords' |
|||
)] |
|||
#[LayoutData( |
|||
header: 'domains/admission/seo.academic-program.title', |
|||
breadcrumbs: [ |
|||
'ui.menu.dashboard' => 'dashboard', |
|||
'domains/admission/seo.academic-program.title' => '', |
|||
], |
|||
)] |
|||
public function __invoke(AcademicProgramDataTable $dataTable) |
|||
{ |
|||
return $dataTable->render('pages.admission.academic-program.index'); |
|||
} |
|||
} |
|||
@ -1,32 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers\Web\Admission; |
|||
|
|||
use App\Attributes\LayoutData; |
|||
use App\Attributes\Seo; |
|||
use App\Http\Controllers\Controller; |
|||
use App\Http\DataTables\Admission\ProgramTrackDataTable; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class ProgramTrackController extends Controller |
|||
{ |
|||
/** |
|||
* Handle the incoming request. |
|||
*/ |
|||
#[Seo( |
|||
title: 'domains/admission/seo.program-track.title', |
|||
description: 'domains/admission/seo.program-track.description', |
|||
keywords: 'domains/admission/seo.program-track.keywords' |
|||
)] |
|||
#[LayoutData( |
|||
header: 'domains/admission/seo.program-track.title', |
|||
breadcrumbs: [ |
|||
'ui.menu.dashboard' => 'dashboard', |
|||
'domains/admission/seo.program-track.title' => '', |
|||
], |
|||
)] |
|||
public function __invoke(ProgramTrackDataTable $dataTable) |
|||
{ |
|||
return $dataTable->render('pages.admission.program-track.index'); |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
<x-modal id="academicprogram-form-modal" :title="$this->title" wire:submit="save" wire:loading form livewire> |
|||
|
|||
<div class="d-flex flex-column gap-3"> |
|||
<x-form.input name="form.name" wire:model="form.name" :label="__('domains/admission/field.academic-program.name')" /> |
|||
|
|||
<x-form.input name="form.code" wire:model="form.code" :label="__('domains/admission/field.academic-program.code')" /> |
|||
|
|||
<x-form.select name="form.status" wire:model="form.status" :label="__('domains/admission/field.academic-program.status')" :options="['active' => 'Active', 'archived' => 'Archived']" /> |
|||
</div> |
|||
|
|||
<x-slot:footer> |
|||
<x-button type="button" theme="secondary" :label="__('ui.button.cancel')" data-bs-dismiss="modal" /> |
|||
<x-button type="submit" theme="primary" :label="__('ui.button.save')" /> |
|||
</x-slot:footer> |
|||
</x-modal> |
|||
@ -1,13 +0,0 @@ |
|||
<x-modal id="programtrack-form-modal" :title="$this->title" wire:submit="save" wire:loading form livewire> |
|||
|
|||
<div class="d-flex flex-column gap-3"> |
|||
<x-form.input name="form.name" wire:model="form.name" :label="__('domains/admission/field.program-track.name')" /> |
|||
|
|||
<x-form.select name="form.status" wire:model="form.status" :label="__('domains/admission/field.program-track.status')" :options="['active' => 'Active', 'archived' => 'Archived']" /> |
|||
</div> |
|||
|
|||
<x-slot:footer> |
|||
<x-button type="button" theme="secondary" :label="__('ui.button.cancel')" data-bs-dismiss="modal" /> |
|||
<x-button type="submit" theme="primary" :label="__('ui.button.save')" /> |
|||
</x-slot:footer> |
|||
</x-modal> |
|||
@ -1,54 +0,0 @@ |
|||
<?php |
|||
|
|||
use App\Domains\System\Actions\Files\DeleteModelFile; |
|||
use App\Domains\System\Models\File; |
|||
use Illuminate\Foundation\Testing\RefreshDatabase; |
|||
use Tests\TestCase; |
|||
|
|||
uses(TestCase::class, RefreshDatabase::class); |
|||
|
|||
test('it removes all files associated with a model', function () { |
|||
// Create some files |
|||
File::create([ |
|||
'fileable_type' => 'User', |
|||
'fileable_id' => '1', |
|||
'relation_name' => 'avatar', |
|||
'name' => 'file1.txt', |
|||
'mime_type' => 'text/plain', |
|||
'size' => 1024, |
|||
'disk' => 'public', |
|||
'path' => 'path/to/file1.txt', |
|||
'uploader_id' => 'u1', |
|||
]); |
|||
|
|||
File::create([ |
|||
'fileable_type' => 'User', |
|||
'fileable_id' => '1', |
|||
'relation_name' => 'documents', |
|||
'name' => 'file2.txt', |
|||
'mime_type' => 'text/plain', |
|||
'size' => 1024, |
|||
'disk' => 'public', |
|||
'path' => 'path/to/file2.txt', |
|||
'uploader_id' => 'u1', |
|||
]); |
|||
|
|||
// Create a file for a different model/id to ensure no accidental deletion |
|||
File::create([ |
|||
'fileable_type' => 'Post', |
|||
'fileable_id' => '2', |
|||
'relation_name' => 'attachments', |
|||
'name' => 'file3.txt', |
|||
'mime_type' => 'text/plain', |
|||
'size' => 1024, |
|||
'disk' => 'public', |
|||
'path' => 'path/to/file3.txt', |
|||
'uploader_id' => 'u1', |
|||
]); |
|||
|
|||
$action = new DeleteModelFile; |
|||
$action->execute('User', '1'); |
|||
|
|||
expect(File::where('fileable_type', 'User')->where('fileable_id', '1')->count())->toBe(0) |
|||
->and(File::where('fileable_type', 'Post')->where('fileable_id', '2')->count())->toBe(1); |
|||
}); |
|||
Loading…
Reference in new issue