mirror of
https://github.com/appwrite/appwrite
synced 2026-05-06 14:58:33 +00:00
Merge pull request #7638 from appwrite/fix-update-topics-permissions
Fix update topics permissions
This commit is contained in:
commit
4ce6eabf40
2 changed files with 19 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue