diff --git a/CHANGES.md b/CHANGES.md index 2088bb1de..464780732 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -30,6 +30,7 @@ - Fixed a bug, that added a wrong timzone offset to user log timestamps - Fixed a bug, that Response format header was not added in the access-control-allow-header list. - Fixed a bug where countryName is unknown on sessions (#933) +- Added missing event users.update.prefs (#952) ## Security diff --git a/app/config/events.php b/app/config/events.php index 2bb3862fd..601b50216 100644 --- a/app/config/events.php +++ b/app/config/events.php @@ -117,6 +117,11 @@ return [ 'model' => Response::MODEL_USER, 'note' => 'version >= 0.7', ], + 'users.update.prefs' => [ + 'description' => 'This event triggers when a user preference is updated from the users API.', + 'model' => Response::MODEL_ANY, + 'note' => 'version >= 0.7', + ], 'users.update.status' => [ 'description' => 'This event triggers when a user status is updated from the users API.', 'model' => Response::MODEL_USER, diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index dbff5a019..0394cd8c0 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -373,6 +373,7 @@ App::patch('/v1/users/:userId/status') App::patch('/v1/users/:userId/prefs') ->desc('Update User Preferences') ->groups(['api', 'users']) + ->label('event', 'users.update.prefs') ->label('scope', 'users.write') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'users') diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index e1059f6af..0596aee09 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -117,6 +117,7 @@ trait ProjectCustom 'storage.files.update', 'storage.files.delete', 'users.create', + 'users.update.prefs', 'users.update.status', 'users.delete', 'users.sessions.delete', diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index 360dee2cb..d2d554913 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -186,10 +186,43 @@ class WebhooksCustomServerTest extends Scope */ return ['userId' => $user['body']['$id'], 'name' => $user['body']['name'], 'email' => $user['body']['email']]; } - - /** + + /** * @depends testCreateUser */ + public function testUpdateUserPrefs(array $data):array + { + /** + * Test for SUCCESS + */ + $user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'prefs' => ['a' => 'b'] + ]); + + $this->assertEquals($user['headers']['status-code'], 200); + $this->assertEquals($user['body']['a'], 'b'); + + $webhook = $this->getLastRequest(); + + $this->assertEquals($webhook['method'], 'POST'); + $this->assertEquals($webhook['headers']['Content-Type'], 'application/json'); + $this->assertEquals($webhook['headers']['User-Agent'], 'Appwrite-Server vdev. Please report abuse at security@appwrite.io'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Event'], 'users.update.prefs'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Signature'], 'not-yet-implemented'); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Id'] ?? '', $this->getProject()['webhookId']); + $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Project-Id'] ?? '', $this->getProject()['$id']); + $this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), ('server' === $this->getSide())); + $this->assertEquals($webhook['data']['a'], 'b'); + + return $data; + } + + /** + * @depends testUpdateUserPrefs + */ public function testUpdateUserStatus(array $data):array { /** @@ -221,7 +254,7 @@ class WebhooksCustomServerTest extends Scope $this->assertEquals($webhook['data']['status'], 2); $this->assertEquals($webhook['data']['email'], $data['email']); $this->assertEquals($webhook['data']['emailVerification'], false); - $this->assertEquals($webhook['data']['prefs'], []); + $this->assertEquals($webhook['data']['prefs']['a'], 'b'); return $data; } @@ -257,8 +290,8 @@ class WebhooksCustomServerTest extends Scope $this->assertEquals($webhook['data']['status'], 2); $this->assertEquals($webhook['data']['email'], $data['email']); $this->assertEquals($webhook['data']['emailVerification'], false); - $this->assertEquals($webhook['data']['prefs'], []); + $this->assertEquals($webhook['data']['prefs']['a'], 'b'); return $data; } -} \ No newline at end of file +}