From 8742bfaee820561f1495383b9556b7e94bd8cebc Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 23 Feb 2024 23:56:49 +1300 Subject: [PATCH 1/2] Fix missing subscribe on topic update --- app/controllers/api/messaging.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/messaging.php b/app/controllers/api/messaging.php index 1c30e07ba5..3e5c2666d2 100644 --- a/app/controllers/api/messaging.php +++ b/app/controllers/api/messaging.php @@ -2133,21 +2133,26 @@ App::patch('/v1/messaging/topics/:topicId') ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_TOPIC) ->param('topicId', '', new UID(), 'Topic ID.') - ->param('name', '', new Text(128), 'Topic Name.', true) + ->param('name', null, new Text(128), 'Topic Name.', true) + ->param('subscribe', null, new Roles(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of role strings with subscribe permission. By default all users are granted with any subscribe permission. [learn more about roles](https://appwrite.io/docs/permissions#permission-roles). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' roles are allowed, each 64 characters long.', true) ->inject('queueForEvents') ->inject('dbForProject') ->inject('response') - ->action(function (string $topicId, string $name, Event $queueForEvents, Database $dbForProject, Response $response) { + ->action(function (string $topicId, ?string $name, ?array $subscribe, Event $queueForEvents, Database $dbForProject, Response $response) { $topic = $dbForProject->getDocument('topics', $topicId); if ($topic->isEmpty()) { throw new Exception(Exception::TOPIC_NOT_FOUND); } - if (!empty($name)) { + if (!\is_null($name)) { $topic->setAttribute('name', $name); } + if (!\is_null($subscribe)) { + $topic->setAttribute('subscribe', $subscribe); + } + $topic = $dbForProject->updateDocument('topics', $topicId, $topic); $queueForEvents From d311f883077b3473ffc3e38741a453a93e47396b Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 24 Feb 2024 00:01:46 +1300 Subject: [PATCH 2/2] Add test --- tests/e2e/Services/Messaging/MessagingBase.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/e2e/Services/Messaging/MessagingBase.php b/tests/e2e/Services/Messaging/MessagingBase.php index 25bf985692..fb3d225699 100644 --- a/tests/e2e/Services/Messaging/MessagingBase.php +++ b/tests/e2e/Services/Messaging/MessagingBase.php @@ -341,6 +341,17 @@ trait MessagingBase $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals('android-app', $response['body']['name']); + $response2 = $this->client->call(Client::METHOD_PATCH, '/messaging/topics/' . $topics['private']['$id'], [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ], [ + 'name' => 'ios-app', + 'subscribe' => [Role::user('some-user')->toString()], + ]); + $this->assertEquals(200, $response2['headers']['status-code']); + $this->assertEquals('ios-app', $response2['body']['name']); + return $response['body']['$id']; }