From f1ba7b08ab40718aa08f0eb0b682676ca0a74ec7 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 27 Dec 2023 23:35:32 +0000 Subject: [PATCH] Update the delete identity endpoints to set the params and payload Because no payload was set, the event params (userId and identityId) wasn't picked up automatically. This updates the endpoints so that the payload is set, but also makes sure to set the userId and identityId params since the identityId param's key doesn't match the key in the payload. --- app/controllers/api/account.php | 10 ++++++++-- app/controllers/api/users.php | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index c210b19f4f..9cbe6ce7ef 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -842,7 +842,7 @@ App::get('/v1/account/identities') }); App::delete('/v1/account/identities/:identityId') - ->desc('Delete Identity') + ->desc('Delete identity') ->groups(['api', 'account']) ->label('scope', 'account') ->label('event', 'users.[userId].identities.[identityId].delete') @@ -859,7 +859,8 @@ App::delete('/v1/account/identities/:identityId') ->param('identityId', '', new UID(), 'Identity ID.') ->inject('response') ->inject('dbForProject') - ->action(function (string $identityId, Response $response, Database $dbForProject) { + ->inject('queueForEvents') + ->action(function (string $identityId, Response $response, Database $dbForProject, Event $queueForEvents) { $identity = $dbForProject->getDocument('identities', $identityId); @@ -869,6 +870,11 @@ App::delete('/v1/account/identities/:identityId') $dbForProject->deleteDocument('identities', $identityId); + $queueForEvents + ->setParam('userId', $identity->getAttribute('userId')) + ->setParam('identityId', $identity->getId()) + ->setPayload($response->output($identity, Response::MODEL_IDENTITY)); + return $response->noContent(); }); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 0869453cc9..30f52c614e 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -1211,7 +1211,7 @@ App::delete('/v1/users/:userId') }); App::delete('/v1/users/identities/:identityId') - ->desc('Delete Identity') + ->desc('Delete identity') ->groups(['api', 'users']) ->label('event', 'users.[userId].identities.[identityId].delete') ->label('scope', 'users.write') @@ -1227,7 +1227,8 @@ App::delete('/v1/users/identities/:identityId') ->param('identityId', '', new UID(), 'Identity ID.') ->inject('response') ->inject('dbForProject') - ->action(function (string $identityId, Response $response, Database $dbForProject) { + ->inject('queueForEvents') + ->action(function (string $identityId, Response $response, Database $dbForProject, Event $queueForEvents) { $identity = $dbForProject->getDocument('identities', $identityId); @@ -1237,6 +1238,11 @@ App::delete('/v1/users/identities/:identityId') $dbForProject->deleteDocument('identities', $identityId); + $queueForEvents + ->setParam('userId', $identity->getAttribute('userId')) + ->setParam('identityId', $identity->getId()) + ->setPayload($response->output($identity, Response::MODEL_IDENTITY)); + return $response->noContent(); });