Skip to content

Commit

Permalink
Do not send menus on webex if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
carsso committed Dec 31, 2024
1 parent 8526877 commit 2c92215
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
6 changes: 5 additions & 1 deletion app/Console/Commands/NotifyWebex.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ public function handle()
{
$date = date('Y-m-d');
Log::info('Sending Webex notifications for menu of ' . $date . ' to all rooms');
$menu = Menu::where('date', $date)->first();
$menu = Menu::where('date', $date)->where('mains', '!=', '[]')->where('sides', '!=', '[]')->first();

if(!config('services.webex.bearer_token')) {
Log::info('Webex bearer token not set, aborting');
return 0;
}
if(!$menu) {
Log::info('No menu for date '.$date.', aborting');
return 0;
}
$api = new WebexApi;
Log::info('Listing Webex rooms');
$rooms = $api->getRooms();
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,16 @@ public function webexNotify()
{
$date = date('Y-m-d');
Log::info('Sending Webex notifications for menu of ' . $date . ' to all rooms');
$menu = Menu::where('date', $date)->first();
$menu = Menu::where('date', $date)->where('mains', '!=', '[]')->where('sides', '!=', '[]')->first();

if(!config('services.webex.bearer_token')) {
Log::info('Webex bearer token not set, aborting');
return $this->redirectWithError('Token Webex non configuré', redirect()->route('admin'));
}
if(!$menu) {
Log::info('No menu for date '.$date.', aborting');
return $this->redirectWithError('Aucun menu pour le '.$date, redirect()->route('admin'));
}
$api = new WebexApi;
Log::info('Listing Webex rooms');
$rooms = $api->getRooms();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function backWithSuccess(string $message, $sessionBag = 'flash', Redir
*
* @return \Illuminate\Http\RedirectResponse
*/
protected function redirectWithErrror(string $message, RedirectResponse $redirectResponse, ?Exception $e = null, $sessionBag = 'flash')
protected function redirectWithError(string $message, RedirectResponse $redirectResponse, ?Exception $e = null, $sessionBag = 'flash')
{
$withError = 'with' . Str::studly($sessionBag) . 'Error';
$withErrorException = $withError . 'Exception';
Expand Down
14 changes: 7 additions & 7 deletions app/Http/Controllers/MenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function upload(UploadFormRequest $request)
$file = File::where('hash', $fileHash)->first();
if($file) {
if(count($validated['files']) == 1) {
return $this->redirectWithErrror('Fichier déjà uploadé', redirect()->route('file', $file->hash));
return $this->redirectWithError('Fichier déjà uploadé', redirect()->route('file', $file->hash));
} else {
continue;
}
Expand All @@ -102,7 +102,7 @@ public function upload(UploadFormRequest $request)
$originalFilename = $matches[1];
}
if(!preg_match('/^S[0-9]+-[0-9]{4}\.pdf$/', $originalFilename, $matches)) {
return $this->redirectWithErrror('Fichier '.$originalFilename.' invalide, nom incorrect, format attendu : SXX-XXXX.pdf', redirect()->route('files'));
return $this->redirectWithError('Fichier '.$originalFilename.' invalide, nom incorrect, format attendu : SXX-XXXX.pdf', redirect()->route('files'));
}
$fileName = $fileHash.'_'.$originalFilename;
$filePath = $validatedFile->storeAs('uploads/menus', $fileName, 'public');
Expand All @@ -128,10 +128,10 @@ public function fileRelaunch($hash)
{
$file = File::where('hash', $hash)->first();
if(!$file) {
return $this->redirectWithErrror('Fichier non trouvé', redirect()->route('home'));
return $this->redirectWithError('Fichier non trouvé', redirect()->route('home'));
}
if($file->state != 'error' && !auth()->user()->hasRole('Super Admin')) {
return $this->redirectWithErrror('Le fichier n\'est pas en erreur', redirect()->route('file', $file->hash));
return $this->redirectWithError('Le fichier n\'est pas en erreur', redirect()->route('file', $file->hash));
}
$file->state = 'todo';
$file->message = null;
Expand All @@ -144,10 +144,10 @@ public function fileDelete($hash)
{
$file = File::where('hash', $hash)->first();
if(!$file) {
return $this->redirectWithErrror('Fichier non trouvé', redirect()->route('home'));
return $this->redirectWithError('Fichier non trouvé', redirect()->route('home'));
}
if($file->state != 'error' && !auth()->user()->hasRole('Super Admin')) {
return $this->redirectWithErrror('Fichier non en erreur', redirect()->route('file', $file->hash));
return $this->redirectWithError('Fichier non en erreur', redirect()->route('file', $file->hash));
}
if(is_file(public_path($file->file_path))) {
unlink(public_path($file->file_path));
Expand All @@ -163,7 +163,7 @@ public function file($hash)
{
$file = File::where('hash', $hash)->first();
if(!$file) {
return $this->redirectWithErrror('Fichier non trouvé', redirect()->route('home'));
return $this->redirectWithError('Fichier non trouvé', redirect()->route('home'));
}
return view('file', ['file' => $file]);
}
Expand Down

0 comments on commit 2c92215

Please sign in to comment.