This commit is contained in:
@@ -24,6 +24,13 @@ class FlagController extends Controller
|
||||
helper(['url', 'form']);
|
||||
}
|
||||
|
||||
private function assertSchoolYearNameWritable(string $schoolYear): void
|
||||
{
|
||||
service('schoolYearWriteGuard')->assertWritable(
|
||||
service('schoolYearContext')->forYearName($schoolYear)
|
||||
);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$currentFlagModel = new CurrentFlagModel();
|
||||
@@ -436,6 +443,13 @@ class FlagController extends Controller
|
||||
return $this->index();
|
||||
}
|
||||
|
||||
$flagData = $currentFlagModel->find($id);
|
||||
if (!$flagData) {
|
||||
session()->setFlashdata('error', 'Incident not found.');
|
||||
return $this->index();
|
||||
}
|
||||
$this->assertSchoolYearNameWritable((string)($flagData['school_year'] ?? ''));
|
||||
|
||||
$update = ['flag_state' => $newState];
|
||||
if ($newState === 'Closed') {
|
||||
$update['updated_by_closed'] = $userId;
|
||||
@@ -490,6 +504,7 @@ class FlagController extends Controller
|
||||
session()->setFlashdata('error', 'Incident not found.');
|
||||
return redirect()->back();
|
||||
}
|
||||
$this->assertSchoolYearNameWritable((string)($flagData['school_year'] ?? ''));
|
||||
|
||||
// Proceed only if flag is not closed
|
||||
if ($flagData['flag_state'] !== 'Closed') {
|
||||
@@ -537,6 +552,7 @@ class FlagController extends Controller
|
||||
session()->setFlashdata('error', 'Incident not found.');
|
||||
return redirect()->back();
|
||||
}
|
||||
$this->assertSchoolYearNameWritable((string)($flagData['school_year'] ?? ''));
|
||||
|
||||
// Check if the flag is not already canceled
|
||||
if ($flagData['flag_state'] !== 'Canceled') {
|
||||
|
||||
Reference in New Issue
Block a user