Skip to content

Commit

Permalink
#253791 [bugfix] Silent booking failure on session expire
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan-thapliyal authored Jul 12, 2022
1 parent d1f7ffa commit e759598
Show file tree
Hide file tree
Showing 25 changed files with 159 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/Mealz/MealBundle/Controller/ParticipantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function delete(

$this->triggerDeleteEvents($participant);

if (($this->getDoorman()->isKitchenStaff()) === true) {
if (true === $this->getDoorman()->isKitchenStaff()) {
$logger = $this->get('monolog.logger.balance');
$logger->info(
'admin removed {profile} from {meal} (Meal: {mealId})',
Expand Down
16 changes: 8 additions & 8 deletions src/Mealz/MealBundle/Message/NewOfferMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public function getContent(): string
$offerCount = $this->offerService->getOfferCount($this->participant->getMeal()->getDateTime());

return $this->translator->trans(
'mattermost.offered',
[
'%count%' => $offerCount,
'%dish%' => $this->getBookedDishTitle($this->participant),
],
'messages',
'en_EN'
);
'mattermost.offered',
[
'%count%' => $offerCount,
'%dish%' => $this->getBookedDishTitle($this->participant),
],
'messages',
'en_EN'
);
}
}
14 changes: 7 additions & 7 deletions src/Mealz/MealBundle/Message/WeeklyMenuMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public function getContent(): string

if ($this->week->isEnabled()) {
$header = '#### ' . $this->translator->trans(
'week.notification.header.default',
[
'%weekStart%' => $this->week->getStartTime()->format('d.m.'),
'%weekEnd%' => $this->week->getEndTime()->format('d.m.'),
],
'messages'
);
'week.notification.header.default',
[
'%weekStart%' => $this->week->getStartTime()->format('d.m.'),
'%weekEnd%' => $this->week->getEndTime()->format('d.m.'),
],
'messages'
);
$tableHeader = "\n|Day|Meals|\n|:-----|:-----|\n";
$body = $this->getDishesByWeek($this->week);
$footer = $this->translator->trans('week.notification.footer.default', [], 'messages');
Expand Down
2 changes: 1 addition & 1 deletion src/Mealz/MealBundle/Service/ParticipationServiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private function updateCombinedMealDishes(Participant $participant, array $dishS
ParticipationException::ERR_INVALID_OPERATION
);
}
if ((2 !== count($dishSlugs))) {
if (2 !== count($dishSlugs)) {
throw new ParticipationException(
'invalid dish count; combined meal expects 2 dishes, got ' . count($dishSlugs),
ParticipationException::ERR_COMBI_MEAL_INVALID_DISH_COUNT
Expand Down
37 changes: 37 additions & 0 deletions src/Mealz/UserBundle/EventSubscriber/ExceptionSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace App\Mealz\UserBundle\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;

class ExceptionSubscriber implements EventSubscriberInterface
{
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents(): array
{
return [
KernelEvents::EXCEPTION => ['handleException', 5],
];
}

public function handleException(ExceptionEvent $event): void
{
if (!$event->getRequest()->isXmlHttpRequest()) {
return;
}

$exception = $event->getThrowable();
if ($exception instanceof AuthenticationException || $exception instanceof AccessDeniedException) {
$event->setResponse(new JsonResponse(null, 401));
}
}
}
2 changes: 1 addition & 1 deletion src/Resources/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'jquery-datetimepicker/build/jquery.datetimepicker.full';
import '@fancyapps/fancybox';
import 'easy-autocomplete';
import 'daterangepicker';
import {Controller} from "./controller";
import {Controller} from './controller';



Expand Down
16 changes: 16 additions & 0 deletions src/Resources/js/modules/ajax-error-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default class AjaxErrorHandler {
public static handleError(jqXHR: JQueryXHR, customFn?: () => void){
if (401 === jqXHR.status) {
location.reload();
return;
}

if (undefined !== customFn) {
customFn();
return;
}

console.log(jqXHR.status + ': ' + jqXHR.statusText);
alert('An unknown error occurred');
}
}
10 changes: 6 additions & 4 deletions src/Resources/js/modules/ajax-forms.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import AjaxErrorHandler from './ajax-error-handler';

Mealz.prototype.initAjaxForms = function () {
var that = this;
$('.load-ajax-form').on('click', function (e) {
Expand Down Expand Up @@ -88,8 +90,8 @@ Mealz.prototype.loadAjaxForm = function ($element) {

$element.addClass('loaded');
},
error: function (xhr) {
console.log(xhr.status + ': ' + xhr.statusText);
error: function (jqXHR) {
AjaxErrorHandler.handleError(jqXHR);
}
});
};
Expand Down Expand Up @@ -146,8 +148,8 @@ Mealz.prototype.loadAjaxFormPayment = function ($element) {
that.enablePaypal();
}
},
error: function (xhr) {
console.log(xhr.status + ': ' + xhr.statusText);
error: function (jqXHR) {
AjaxErrorHandler.handleError(jqXHR);
}
});
};
4 changes: 2 additions & 2 deletions src/Resources/js/modules/combined-meal-dialog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'jquery-ui/ui/widgets/dialog';
import {BaseDialog} from "./base-dialog";
import {Dish} from "./combined-meal-service";
import {BaseDialog} from './base-dialog';
import {Dish} from './combined-meal-service';

export class CombinedMealDialog extends BaseDialog {
private readonly containerID: string = '#combined-meal-selector';
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/js/modules/combined-meal-offers-dialog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'jquery-ui/ui/widgets/dialog';
import {BaseDialog} from "./base-dialog";
import {BaseDialog} from './base-dialog';

export class CombinedMealOffersDialog extends BaseDialog {
private readonly containerID: string = '#combined-meal-selector';
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/js/modules/combined-meal-offers-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'jquery-ui/ui/widgets/dialog';
import {CombinedMealOffersDialog, Offer} from "./combined-meal-offers-dialog";
import {AbstractParticipationToggleHandler} from "./participation-toggle-handler";
import {ParticipantCounter} from "./participant-counter";
import {CombinedMealOffersDialog, Offer} from './combined-meal-offers-dialog';
import {AbstractParticipationToggleHandler} from './participation-toggle-handler';
import {ParticipantCounter} from './participant-counter';

export class CombinedMealOffersService {
public static execute($checkbox: JQuery, participationToggleHandler: AbstractParticipationToggleHandler) {
Expand Down Expand Up @@ -36,4 +36,4 @@ export class CombinedMealOffersService {
interface Offers {
title: string,
offers: Array<Offer>
}
}
2 changes: 1 addition & 1 deletion src/Resources/js/modules/combined-meal-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MealService} from "./meal-service";
import {MealService} from './meal-service';

export class CombinedMealService {

Expand Down
8 changes: 4 additions & 4 deletions src/Resources/js/modules/confirm-swap-dialog.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'jquery-ui/ui/widgets/dialog';
import {ParticipationRequest, ParticipationRequestHandler} from "./participation-request-handler";
import {ActionResponse} from "./participation-response-handler";
import {BaseDialog} from "./base-dialog";
import {ParticipationRequest, ParticipationRequestHandler} from './participation-request-handler';
import {ActionResponse} from './participation-response-handler';
import {BaseDialog} from './base-dialog';

export class ConfirmSwapDialog extends BaseDialog {
private readonly containerID: string = '#confirm-swapbox';
Expand Down Expand Up @@ -36,4 +36,4 @@ interface ConfirmSwapDialogOptions {
participationRequest: ParticipationRequest,
$checkbox: JQuery,
handlerMethod: ($checkbox: JQuery, response: ActionResponse) => void
}
}
5 changes: 5 additions & 0 deletions src/Resources/js/modules/custom-functions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import AjaxErrorHandler from './ajax-error-handler';

Mealz.prototype.toggleArrayItem = function (a, v) {
var i = a.indexOf(v);
if (i === -1)
Expand Down Expand Up @@ -59,6 +61,9 @@ Mealz.prototype.copyToClipboard = function() {
}
}
return false;
},
error: function(jqXHR){
AjaxErrorHandler.handleError(jqXHR);
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/js/modules/meal-offer-update-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ParticipationUpdateHandler} from "./participation-update-handler";
import {MealService} from "./meal-service";
import {ParticipationUpdateHandler} from './participation-update-handler';
import {MealService} from './meal-service';

export enum MealOfferStates {
New = 'new',
Expand Down
10 changes: 5 additions & 5 deletions src/Resources/js/modules/participation-pre-toggle-handler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {CombinedMealDialog, SerializedFormData} from "./combined-meal-dialog";
import {CombinedMealDialog, SerializedFormData} from './combined-meal-dialog';
import Event = JQuery.Event;
import {AbstractParticipationToggleHandler} from "./participation-toggle-handler";
import {ParticipantCounter} from "./participant-counter";
import {CombinedMealOffersService} from "./combined-meal-offers-service";
import {CombinedMealService} from "./combined-meal-service";
import {AbstractParticipationToggleHandler} from './participation-toggle-handler';
import {ParticipantCounter} from './participant-counter';
import {CombinedMealOffersService} from './combined-meal-offers-service';
import {CombinedMealService} from './combined-meal-service';

export class ParticipationPreToggleHandler {
private readonly participationToggleHandler: AbstractParticipationToggleHandler;
Expand Down
18 changes: 10 additions & 8 deletions src/Resources/js/modules/participation-request-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ParticipationResponse} from "./participation-response-handler";
import {ParticipationResponse} from './participation-response-handler';
import AjaxErrorHandler from './ajax-error-handler';

export class ParticipationRequest {
readonly url: string;
Expand Down Expand Up @@ -37,13 +38,14 @@ export class ParticipationRequestHandler {
success: function (data) {
handle($checkbox, data);
},
error: function (xhr) {
console.log(xhr.status + ': ' + xhr.statusText);
if (true === ParticipationRequestHandler.isJoinRequest(participationRequest.url)) {
let mealTitle = $checkbox.closest('.meal-row').children('.title').text();
let errMsg = $('.weeks').data('errJoinNotPossible').replace('%dish%', mealTitle);
ParticipationRequestHandler.sendAlert(errMsg);
}
error: function (jqXHR) {
AjaxErrorHandler.handleError(jqXHR, function (){
if (true === ParticipationRequestHandler.isJoinRequest(participationRequest.url)) {
let mealTitle = $checkbox.closest('.meal-row').children('.title').text();
let errMsg = $('.weeks').data('errJoinNotPossible').replace('%dish%', mealTitle);
ParticipationRequestHandler.sendAlert(errMsg);
}
});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/js/modules/participation-response-handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AcceptOfferData, ParticipationUpdateHandler, ToggleData} from "./participation-update-handler";
import {AcceptOfferData, ParticipationUpdateHandler, ToggleData} from './participation-update-handler';

export interface ParticipationResponse {
actionText: string;
Expand Down
10 changes: 5 additions & 5 deletions src/Resources/js/modules/participation-toggle-handler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {ParticipantCounter} from "./participant-counter";
import {ParticipationResponseHandler} from "./participation-response-handler";
import {ParticipantCounter} from './participant-counter';
import {ParticipationResponseHandler} from './participation-response-handler';
import {
ParticipationRequest,
ParticipationRequestHandler
} from "./participation-request-handler";
import {ConfirmSwapDialog} from "./confirm-swap-dialog";
import {CombinedMealService} from "./combined-meal-service";
} from './participation-request-handler';
import {ConfirmSwapDialog} from './confirm-swap-dialog';
import {CombinedMealService} from './combined-meal-service';

export abstract class AbstractParticipationToggleHandler {
constructor($checkboxes: JQuery) {
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/js/modules/participation-update-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Labels, TooltipLabel} from "./labels";
import {CombinedMealService} from "./combined-meal-service";
import {MealService} from "./meal-service";
import {Labels, TooltipLabel} from './labels';
import {CombinedMealService} from './combined-meal-service';
import {MealService} from './meal-service';

/**
* Meal States
Expand Down
21 changes: 12 additions & 9 deletions src/Resources/js/views/adminParticipationEdit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {CombinedMealDialog, SerializedFormData} from "../modules/combined-meal-dialog";
import {Dish, DishVariation} from "../modules/combined-meal-service";
import {CombinedMealDialog, SerializedFormData} from '../modules/combined-meal-dialog';
import {Dish, DishVariation} from '../modules/combined-meal-service';
import AjaxErrorHandler from '../modules/ajax-error-handler';

interface DeleteResponseData {
participantsCount: number;
Expand Down Expand Up @@ -346,14 +347,16 @@ export default class AdminParticipationEditView {
data: payload,
dataType: 'json',
success: successFn,
error: function (xhr, status, error) {
if (failureFn) {
let errMsg = status;
if ('' !== error) {
errMsg += `, ${error}`;
error: function (jqXHR, status, error) {
AjaxErrorHandler.handleError(jqXHR, function(){
if (failureFn) {
let errMsg = status;
if ('' !== error) {
errMsg += `, ${error}`;
}
failureFn(errMsg);
}
failureFn(errMsg);
}
});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/js/views/dishIndex.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Switchery from "switchery.js";
import Switchery from 'switchery.js';

export default class DishIndex {
constructor() {
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/js/views/mealGuest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ParticipationGuestToggleHandler} from "../modules/participation-toggle-handler";
import {ParticipationPreToggleHandler} from "../modules/participation-pre-toggle-handler";
import {ParticipationUpdateHandler} from "../modules/participation-update-handler";
import {SlotAllocationUpdateHandler} from "../modules/slot-allocation-update-handler";
import {ParticipationGuestToggleHandler} from '../modules/participation-toggle-handler';
import {ParticipationPreToggleHandler} from '../modules/participation-pre-toggle-handler';
import {ParticipationUpdateHandler} from '../modules/participation-update-handler';
import {SlotAllocationUpdateHandler} from '../modules/slot-allocation-update-handler';

export default class MealGuestView {
$participationCheckboxes: JQuery;
Expand Down
25 changes: 13 additions & 12 deletions src/Resources/js/views/mealIndex.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {ParticipationPreToggleHandler} from "../modules/participation-pre-toggle-handler";
import {ParticipationToggleHandler} from "../modules/participation-toggle-handler";
import {CombinedMealDialog, SerializedFormData} from "../modules/combined-meal-dialog";
import {ParticipationRequest, ParticipationRequestHandler} from "../modules/participation-request-handler";
import {ParticipationResponse} from "../modules/participation-response-handler";
import {CombinedMealService} from "../modules/combined-meal-service";
import {MealOfferUpdate, MealOfferUpdateHandler} from "../modules/meal-offer-update-handler";
import {ParticipationUpdateHandler} from "../modules/participation-update-handler";
import {SlotAllocationUpdateHandler} from "../modules/slot-allocation-update-handler";
import {MealService} from "../modules/meal-service";
import {ParticipationPreToggleHandler} from '../modules/participation-pre-toggle-handler';
import {ParticipationToggleHandler} from '../modules/participation-toggle-handler';
import {CombinedMealDialog, SerializedFormData} from '../modules/combined-meal-dialog';
import {ParticipationRequest, ParticipationRequestHandler} from '../modules/participation-request-handler';
import {ParticipationResponse} from '../modules/participation-response-handler';
import {CombinedMealService} from '../modules/combined-meal-service';
import {MealOfferUpdate, MealOfferUpdateHandler} from '../modules/meal-offer-update-handler';
import {ParticipationUpdateHandler} from '../modules/participation-update-handler';
import {SlotAllocationUpdateHandler} from '../modules/slot-allocation-update-handler';
import {MealService} from '../modules/meal-service';
import AjaxErrorHandler from '../modules/ajax-error-handler';

interface UpdateResponse extends ParticipationResponse {
bookedDishSlugs: string[];
Expand Down Expand Up @@ -78,8 +79,8 @@ export default class MealIndexView {
// hide default option to auto-select slot [TP##250006]
$slotSelector.find('option[value=""]').hide()
},
error: function () {
alert('An unknown error occurred');
error: function (jqXHR) {
AjaxErrorHandler.handleError(jqXHR);
}
});
}
Expand Down
Loading

0 comments on commit e759598

Please sign in to comment.