Skip to content

Commit

Permalink
Policy and delete action
Browse files Browse the repository at this point in the history
  • Loading branch information
alexPopaCode4 committed Dec 19, 2024
1 parent 0275181 commit 5d86d10
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function table(Table $table): Table
return $table
->query(
fn () => $this->record->monthlyPlans()
->with('caseManager')
->with(['caseManager', 'beneficiary'])
->withCount(['monthlyPlanServices', 'monthlyPlanInterventions'])
)
->heading(__('intervention_plan.headings.monthly_plans'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
namespace App\Filament\Organizations\Resources\MonthlyPlanResource\Pages;

use App\Concerns\HasParentResource;
use App\Filament\Organizations\Resources\BeneficiaryResource;
use App\Filament\Organizations\Resources\InterventionPlanResource;
use App\Filament\Organizations\Resources\MonthlyPlanResource;
use App\Infolists\Components\SectionHeader;
use App\Infolists\Components\TableEntry;
use App\Models\Specialist;
use App\Services\Breadcrumb\InterventionPlanBreadcrumb;
use Carbon\Carbon;
use Filament\Actions\DeleteAction;
use Filament\Infolists\Components\Actions\Action;
use Filament\Infolists\Components\RepeatableEntry;
use Filament\Infolists\Components\Section;
Expand Down Expand Up @@ -39,6 +41,24 @@ public function getTitle(): string|Htmlable
return __('intervention_plan.headings.monthly_plan');
}

public function getHeaderActions(): array
{
return [
DeleteAction::make()
->label(__('intervention_plan.actions.delete_monthly_plan'))
->icon('heroicon-o-trash')
->modalHeading(__('intervention_plan.headings.delete_monthly_plan_modal'))
->modalSubmitActionLabel(__('intervention_plan.actions.delete_monthly_plan'))
->successRedirectUrl(
BeneficiaryResource::getUrl('view_intervention_plan', [
'parent' => $this->parent->beneficiary,
'record' => $this->parent,
])
)
->outlined(),
];
}

public function infolist(Infolist $infolist): Infolist
{
$this->getRecord()
Expand Down
67 changes: 67 additions & 0 deletions app/Policies/MonthlyPlanPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace App\Policies;

use App\Models\MonthlyPlan;
use App\Models\User;

class MonthlyPlanPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return true;
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, MonthlyPlan $monthlyPlan): bool
{
return $user->hasAccessToBeneficiary($monthlyPlan->beneficiary);
}

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return true;
}

/**
* Determine whether the user can update the model.
*/
public function update(User $user, MonthlyPlan $monthlyPlan): bool
{
return $user->hasAccessToBeneficiary($monthlyPlan->beneficiary);
}

/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, MonthlyPlan $monthlyPlan): bool
{
return $user->hasAccessToBeneficiary($monthlyPlan->beneficiary);
}

/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, MonthlyPlan $monthlyPlan): bool
{
return true;
}

/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, MonthlyPlan $monthlyPlan): bool
{
return true;
}
}
2 changes: 2 additions & 0 deletions lang/ro/intervention_plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
'dashboard_intervention_table_empty_state' => 'Odată deschis primul caz și creat primul plan de intervenție pentru acesta, o listă a intervențiilor va fi afișată în acest tabel.',
'edit_monthly_plan_title' => 'Editează plan lunar',
'edit_monthly_plan_services_and_interventions_title' => 'Editează servicii si intervenții',
'delete_monthly_plan_modal' => 'Șterge plan lunar',
],

'actions' => [
Expand Down Expand Up @@ -275,6 +276,7 @@
'create_monthly_plan' => 'Crează un plan',
'create_monthly_plan_from_last' => 'Pornește de la un duplicat',
'create_monthly_plan_simple' => 'Începe cu un plan necompletată',
'delete_monthly_plan' => 'Șterge planul lunar',
],

'placeholders' => [
Expand Down

0 comments on commit 5d86d10

Please sign in to comment.