Clear caches when adding or removing a flag. Block adding or removing flags from published auditions

Closes #91
This commit is contained in:
Matt Young 2025-06-30 01:13:02 -05:00
parent d0aa29fb1a
commit fc650b3be1
1 changed files with 28 additions and 0 deletions

View File

@ -2,17 +2,30 @@
namespace App\Observers; namespace App\Observers;
use App\Exceptions\AuditionAdminException;
use App\Models\Doubler; use App\Models\Doubler;
use App\Models\EntryFlag; use App\Models\EntryFlag;
use Illuminate\Support\Facades\Cache;
class EntryFlagObserver class EntryFlagObserver
{ {
/** /**
* Handle the EntryFlag "created" event. * Handle the EntryFlag "created" event.
*/ */
public function creating(EntryFlag $entryFlag): void
{
if (in_array($entryFlag->flag_name, ['declined', 'no_show', 'failed_prelim'])) {
if ($entryFlag->entry->audition->hasFlag('seats_published') || $entryFlag->entry->audition->hasFlag('advancement_published')) {
throw new AuditionAdminException('Cannot change flag for published auditions.');
}
}
}
public function created(EntryFlag $entryFlag): void public function created(EntryFlag $entryFlag): void
{ {
Doubler::syncDoublers(); Doubler::syncDoublers();
Cache::forget('rank_advancement_'.$entryFlag->entry->audition_id);
Cache::forget('rank_seating_'.$entryFlag->entry->audition_id);
} }
@ -22,14 +35,29 @@ class EntryFlagObserver
public function updated(EntryFlag $entryFlag): void public function updated(EntryFlag $entryFlag): void
{ {
Doubler::syncDoublers(); Doubler::syncDoublers();
Cache::forget('rank_advancement_'.$entryFlag->entry->audition_id);
Cache::forget('rank_seating_'.$entryFlag->entry->audition_id);
} }
/** /**
* Handle the EntryFlag "deleted" event. * Handle the EntryFlag "deleted" event.
*/ */
public function deleting(EntryFlag $entryFlag): void
{
if (in_array($entryFlag->flag_name, ['declined', 'no_show', 'failed_prelim'])) {
if ($entryFlag->entry->audition->hasFlag('seats_published') || $entryFlag->entry->audition->hasFlag('advancement_published')) {
throw new AuditionAdminException('Cannot change flag for published auditions.');
}
}
}
public function deleted(EntryFlag $entryFlag): void public function deleted(EntryFlag $entryFlag): void
{ {
Doubler::syncDoublers(); Doubler::syncDoublers();
Cache::forget('rank_advancement_'.$entryFlag->entry->audition_id);
Cache::forget('rank_seating_'.$entryFlag->entry->audition_id);
} }
/** /**