customerapi: on cancel check also registration ownership

This commit is contained in:
2021-10-07 08:09:16 +02:00
parent 89b3ab4ce5
commit b993f5dee0
5 changed files with 49 additions and 67 deletions

View File

@@ -186,10 +186,13 @@ class EventRegistrationManager extends BaseObject
* @return array|EventRegistration|ActiveRecord|null
* @throws NotFoundHttpException
*/
public function loadRegistration($idRegistration)
public function loadRegistration($idRegistration, $idCustomer)
{
$registration = EventRegistration::find()->andWhere(['id' => $idRegistration])->one();
$registration = EventRegistration::find()
->andWhere(['id' => $idRegistration])
->andWhere(['id_customer' => $idCustomer])
->one();
if ($registration === null) {
throw new NotFoundHttpException('The requested registration does not exist.');
}
@@ -200,8 +203,12 @@ class EventRegistrationManager extends BaseObject
* @param EventRegistration $registration
* @throws ServerErrorHttpException
*/
public function cancelRegistration($registration)
public function cancelRegistration($registration, $idCustomer)
{
if ( $registration->id_customer != $idCustomer){
throw new NotFoundHttpException('The requested registration does not exist.');
}
if (isset($registration->canceled_at)) {
throw new BadRequestHttpException('The registration is already canceled', self::ALREADY_CANCELLED);
}