1
0
Fork 0
mirror of synced 2024-10-01 17:58:02 +13:00

review changes

This commit is contained in:
Prateek Banga 2023-10-18 13:19:21 +05:30
parent b86f531b30
commit 4bef86d88b
5 changed files with 78 additions and 36 deletions

View file

@ -2489,8 +2489,11 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes')
'orders' => $orders,
]);
$validator = new IndexValidator($dbForProject->getAdapter()->getMaxIndexLength());
if (!$validator->isValid($collection->setAttribute('indexes', $index, Document::SET_TYPE_APPEND))) {
$validator = new IndexValidator(
$collection->getAttribute('attributes'),
$dbForProject->getAdapter()->getMaxIndexLength()
);
if (!$validator->isValid($index)) {
throw new Exception(Exception::INDEX_INVALID, $validator->getDescription());
}

View file

@ -8,6 +8,7 @@ use Appwrite\Role;
use Appwrite\Utopia\Database\Validator\CustomId;
use Appwrite\Utopia\Database\Validator\Queries\Messages;
use Appwrite\Utopia\Database\Validator\Queries\Providers;
use Appwrite\Utopia\Database\Validator\Queries\Subscribers;
use Appwrite\Utopia\Database\Validator\Queries\Topics;
use Appwrite\Utopia\Response;
use Utopia\App;
@ -1454,23 +1455,41 @@ App::get('/v1/messaging/topics/:topicId/subscribers')
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_SUBSCRIBER_LIST)
->param('topicId', '', new UID(), 'Topic ID.')
->param('queries', [], new Subscribers(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Providers::ALLOWED_ATTRIBUTES), true)
->inject('dbForProject')
->inject('response')
->action(function (string $topicId, Database $dbForProject, Response $response) {
->action(function (string $topicId, array $queries, Database $dbForProject, Response $response) {
$queries = Query::parseQueries($queries);
$topic = Authorization::skip(fn () => $dbForProject->getDocument('topics', $topicId));
if ($topic->isEmpty()) {
throw new Exception(Exception::TOPIC_NOT_FOUND);
}
$subscribers = $dbForProject->find('subscribers', [
Query::equal('topicInternalId', [$topic->getInternalId()])
]);
\array_push($queries, Query::equal('topicInternalId', [$topic->getInternalId()]));
// Get cursor document if there was a cursor query
$cursor = Query::getByType($queries, [Query::TYPE_CURSORAFTER, Query::TYPE_CURSORBEFORE]);
$cursor = reset($cursor);
if ($cursor) {
$subscriberId = $cursor->getValue();
$cursorDocument = Authorization::skip(fn () => $dbForProject->getDocument('subscribers', $subscriberId));
if ($cursorDocument->isEmpty()) {
throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Subscriber '{$subscriberId}' for the 'cursor' value not found.");
}
$cursor->setValue($cursorDocument);
}
$filterQueries = Query::groupByType($queries)['filters'];
$response
->dynamic(new Document([
'subscribers' => $subscribers,
'total' => \count($subscribers),
'subscribers' => $dbForProject->find('subscribers', $queries),
'total' => $dbForProject->count('subscribers', $filterQueries, APP_LIMIT_COUNT),
]), Response::MODEL_SUBSCRIBER_LIST);
});
@ -1562,9 +1581,9 @@ App::post('/v1/messaging/messages/email')
->param('subject', '', new Text(998), 'Email Subject.')
->param('description', '', new Text(256), 'Description for Message.', true)
->param('content', '', new Text(64230), 'Email Content.')
->param('status', 'processing', new WhiteList(['draft', 'processing']), 'Message Status.', true)
->param('status', 'processing', new WhiteList(['draft', 'processing']), 'Message Status. Value must be either draft or processing.', true)
->param('html', false, new Boolean(), 'Is content of type HTML', true)
->param('deliveryTime', null, new DatetimeValidator(false), 'Delivery time for message.', true)
->param('deliveryTime', null, new DatetimeValidator(requireDateInFuture: true), 'Delivery time for message in ISO 8601 format. DateTime value must be in future.', true)
->inject('dbForProject')
->inject('project')
->inject('messaging')
@ -1693,9 +1712,9 @@ App::patch('/v1/messaging/messages/email/:messageId')
->param('subject', '', new Text(998), 'Email Subject.', true)
->param('description', '', new Text(256), 'Description for Message.', true)
->param('content', '', new Text(64230), 'Email Content.', true)
->param('status', '', new WhiteList(['draft', 'processing']), 'Message Status.', true)
->param('status', '', new WhiteList(['draft', 'processing']), 'Message Status. Value must be either draft or processing.', true)
->param('html', false, new Boolean(), 'Is content of type HTML', true)
->param('deliveryTime', null, new DatetimeValidator(), 'Delivery time for message in ISO 8601 format.', true)
->param('deliveryTime', null, new DatetimeValidator(requireDateInFuture: true), 'Delivery time for message in ISO 8601 format. DateTime value must be in future.', true)
->inject('dbForProject')
->inject('project')
->inject('messaging')

View file

@ -43,13 +43,13 @@
"ext-sockets": "*",
"appwrite/php-runtimes": "0.13.*",
"appwrite/php-clamav": "2.0.*",
"utopia-php/abuse": "0.31.*",
"utopia-php/abuse": "0.32.*",
"utopia-php/analytics": "0.10.*",
"utopia-php/audit": "0.33.*",
"utopia-php/audit": "0.34.*",
"utopia-php/cache": "0.8.*",
"utopia-php/cli": "0.15.*",
"utopia-php/config": "0.2.*",
"utopia-php/database": "0.43.*",
"utopia-php/database": "0.44.*",
"utopia-php/domains": "0.3.*",
"utopia-php/dsn": "0.1.*",
"utopia-php/framework": "0.31.0",

42
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "34cb0b1c81424d1858df197aed030793",
"content-hash": "ee4518740e581a9a4889936fb584a5a4",
"packages": [
{
"name": "adhocore/jwt",
@ -1861,23 +1861,23 @@
},
{
"name": "utopia-php/abuse",
"version": "0.31.1",
"version": "0.32.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/abuse.git",
"reference": "b2ad372d1070f55f9545cb811b6ed2d40094e6dd"
"reference": "9717ffb2d7711f3fd621bb6df3edf5724c08ea78"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/b2ad372d1070f55f9545cb811b6ed2d40094e6dd",
"reference": "b2ad372d1070f55f9545cb811b6ed2d40094e6dd",
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/9717ffb2d7711f3fd621bb6df3edf5724c08ea78",
"reference": "9717ffb2d7711f3fd621bb6df3edf5724c08ea78",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-pdo": "*",
"php": ">=8.0",
"utopia-php/database": "0.43.*"
"utopia-php/database": "0.44.*"
},
"require-dev": {
"laravel/pint": "1.5.*",
@ -1904,9 +1904,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/abuse/issues",
"source": "https://github.com/utopia-php/abuse/tree/0.31.1"
"source": "https://github.com/utopia-php/abuse/tree/0.32.0"
},
"time": "2023-08-29T11:07:46+00:00"
"time": "2023-10-18T07:28:55+00:00"
},
{
"name": "utopia-php/analytics",
@ -1956,21 +1956,21 @@
},
{
"name": "utopia-php/audit",
"version": "0.33.1",
"version": "0.34.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/audit.git",
"reference": "c117e8e9ce4e3e1b369e8b5b55b2d6ab3138eadd"
"reference": "cf34cc3f9f20da4e574a9be4517e1a11025a858f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/audit/zipball/c117e8e9ce4e3e1b369e8b5b55b2d6ab3138eadd",
"reference": "c117e8e9ce4e3e1b369e8b5b55b2d6ab3138eadd",
"url": "https://api.github.com/repos/utopia-php/audit/zipball/cf34cc3f9f20da4e574a9be4517e1a11025a858f",
"reference": "cf34cc3f9f20da4e574a9be4517e1a11025a858f",
"shasum": ""
},
"require": {
"php": ">=8.0",
"utopia-php/database": "0.43.*"
"utopia-php/database": "0.44.*"
},
"require-dev": {
"laravel/pint": "1.5.*",
@ -1997,9 +1997,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/audit/issues",
"source": "https://github.com/utopia-php/audit/tree/0.33.1"
"source": "https://github.com/utopia-php/audit/tree/0.34.0"
},
"time": "2023-08-29T11:07:40+00:00"
"time": "2023-10-18T07:43:25+00:00"
},
{
"name": "utopia-php/cache",
@ -2152,16 +2152,16 @@
},
{
"name": "utopia-php/database",
"version": "0.43.5",
"version": "0.44.1",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/database.git",
"reference": "5f7b05189cfbcc0506090498c580c5765375a00a"
"reference": "e0b832d217e4d429c96ade671e85ece942446543"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/database/zipball/5f7b05189cfbcc0506090498c580c5765375a00a",
"reference": "5f7b05189cfbcc0506090498c580c5765375a00a",
"url": "https://api.github.com/repos/utopia-php/database/zipball/e0b832d217e4d429c96ade671e85ece942446543",
"reference": "e0b832d217e4d429c96ade671e85ece942446543",
"shasum": ""
},
"require": {
@ -2202,9 +2202,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/0.43.5"
"source": "https://github.com/utopia-php/database/tree/0.44.1"
},
"time": "2023-10-06T06:49:47+00:00"
"time": "2023-10-18T07:05:41+00:00"
},
{
"name": "utopia-php/domains",

View file

@ -0,0 +1,20 @@
<?php
namespace Appwrite\Utopia\Database\Validator\Queries;
class Subscribers extends Base
{
public const ALLOWED_ATTRIBUTES = [
'targetId',
'topicId'
];
/**
* Expression constructor
*
*/
public function __construct()
{
parent::__construct('messages', self::ALLOWED_ATTRIBUTES);
}
}