From 86b72153752516274c875dd2d053bbde4e9943e9 Mon Sep 17 00:00:00 2001 From: shimon Date: Wed, 13 Jul 2022 18:40:30 +0300 Subject: [PATCH] metadata collecting routes renaming permissions --- CHANGES.md | 12 +- CONTRIBUTING.md | 14 +- README-CN.md | 6 +- README.md | 6 +- app/config/platforms.php | 2 +- app/controllers/api/account.php | 1 + app/controllers/api/databases.php | 22 ++-- app/controllers/api/functions.php | 7 +- app/controllers/api/projects.php | 2 +- app/controllers/api/storage.php | 16 +-- app/init.php | 6 +- app/realtime.php | 8 +- app/tasks/usage.php | 2 +- app/views/console/databases/database.phtml | 4 +- app/workers/messaging.php | 2 + composer.json | 7 +- .../account/create-magic-url-session.md | 2 +- .../account/create-phone-session.md | 2 +- docs/sdks/cli/GETTING_STARTED.md | 12 -- docs/sdks/dart/CHANGELOG.md | 4 +- docs/sdks/flutter/CHANGELOG.md | 4 +- docs/services/account.md | 2 +- src/Appwrite/Auth/Phone/Msg91.php | 46 +++++++ src/Appwrite/Auth/Phone/Telesign.php | 2 +- src/Appwrite/Migration/Migration.php | 3 +- .../Utopia/Response/Model/Database.php | 12 ++ tests/e2e/Services/Account/AccountBase.php | 61 +++++---- .../e2e/Services/Databases/DatabasesBase.php | 120 +++++++++++++++++- .../Functions/FunctionsConsoleClientTest.php | 12 ++ .../Realtime/RealtimeConsoleClientTest.php | 105 +++++++++++++++ .../Webhooks/WebhooksCustomServerTest.php | 10 ++ 31 files changed, 420 insertions(+), 94 deletions(-) create mode 100644 src/Appwrite/Auth/Phone/Msg91.php diff --git a/CHANGES.md b/CHANGES.md index 4016a982fb..5ba47ab638 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,11 @@ +# Version 0.15.2 +## Bugs +- Fixed Realtime Authentication for the Console by @TorstenDittmann in https://github.com/appwrite/appwrite/pull/3506 +- Fixed Collection Usage by @stnguyen90 in https://github.com/appwrite/appwrite/pull/3505 +- Fixed `$createdAt` after updating document by @Meldiron in https://github.com/appwrite/appwrite/pull/3498 +- Fixed Redirect after deleting Collection in Console @TorstenDittmann in https://github.com/appwrite/appwrite/pull/3476 +- Fixed broken Link for Documents under Collections by @TorstenDittmann in https://github.com/appwrite/appwrite/pull/3469 + # Version 0.15.1 ## Bugs - Fixed SMS for `createVerification` by @christyjacob4 in https://github.com/appwrite/appwrite/pull/3454 @@ -26,8 +34,8 @@ - `collections.[COLLECTION_ID]` is now `databases.[DATABASE_ID].collections.[COLLECTION_ID]` - `collections.[COLLECTION_ID].documents.[DOCUMENT_ID]` is now `databases.[DATABASE_ID].collections.[COLLECTION_ID].documents.[DOCUMENT_ID]` - Following Realtime Channels are changed: - - `collections.[COLLECTION_ID]` is now `databases.[DATABASE_ID].ollections.[COLLECTION_ID]` - - `collections.[COLLECTION_ID].documents` is now `databases.[DATABASE_ID].ollections.[COLLECTION_ID].documents` + - `collections.[COLLECTION_ID]` is now `databases.[DATABASE_ID].collections.[COLLECTION_ID]` + - `collections.[COLLECTION_ID].documents` is now `databases.[DATABASE_ID].collections.[COLLECTION_ID].documents` - After Migration a Database called `default` is created for all your existing Database Collections ## Features diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 255595c590..0a0cf85c11 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,19 +51,19 @@ $ git checkout -b [name_of_your_new_branch] 4. Before you push your changes, make sure your code follows the `PSR12` coding standards , which is the standard Appwrite follows currently. You can easily do this by running the formatter. ```bash -./vendor/bin/phpcbf +composer format ``` Now, go a step further by running the linter by the following command to manually fix the issues the formatter wasn't able to fix. ```bash -./vendor/bin/phpcs +composer lint ``` This will give you a list of errors for you to rectify , if there is an instance you need more information on the errors being displayed you can pass in additional command line arguments. More list of available arguments can be found [here](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage). A very useful command line argument is `--report=diff`. This will give you the expected changes by the linter for easy fixing of formatting issues. ```bash -./vendor/bin/phpcs --report=diff +composer lint --report=diff ``` 5. Push changes to GitHub @@ -413,18 +413,18 @@ We use some automation tools to help us keep a healthy codebase. ```bash # Run on all files -./vendor/bin/phpcbf +composer format # Run on single file or folder -./vendor/bin/phpcbf +composer format ``` **Run Linter:** ```bash # Run on all files -./vendor/bin/phpcs +composer lint # Run on single file or folder -./vendor/bin/phpcs +composer lint ``` ## Tutorials diff --git a/README-CN.md b/README-CN.md index 5b1cdcda91..095d06e221 100644 --- a/README-CN.md +++ b/README-CN.md @@ -59,7 +59,7 @@ docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ - appwrite/appwrite:0.15.1 + appwrite/appwrite:0.15.2 ``` ### Windows @@ -71,7 +71,7 @@ docker run -it --rm ^ --volume //var/run/docker.sock:/var/run/docker.sock ^ --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^ --entrypoint="install" ^ - appwrite/appwrite:0.15.1 + appwrite/appwrite:0.15.2 ``` #### PowerShell @@ -81,7 +81,7 @@ docker run -it --rm , --volume /var/run/docker.sock:/var/run/docker.sock , --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw , --entrypoint="install" , - appwrite/appwrite:0.15.1 + appwrite/appwrite:0.15.2 ``` 运行后,可以在浏览器上访问 http://localhost 找到 Appwrite 控制台。在非 Linux 的本机主机上完成安装后,服务器可能需要几分钟才能启动。 diff --git a/README.md b/README.md index 171203b29c..35c8c6e67c 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ - appwrite/appwrite:0.15.1 + appwrite/appwrite:0.15.2 ``` ### Windows @@ -77,7 +77,7 @@ docker run -it --rm ^ --volume //var/run/docker.sock:/var/run/docker.sock ^ --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^ --entrypoint="install" ^ - appwrite/appwrite:0.15.1 + appwrite/appwrite:0.15.2 ``` #### PowerShell @@ -87,7 +87,7 @@ docker run -it --rm , --volume /var/run/docker.sock:/var/run/docker.sock , --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw , --entrypoint="install" , - appwrite/appwrite:0.15.1 + appwrite/appwrite:0.15.2 ``` Once the Docker installation completes, go to http://localhost to access the Appwrite console from your browser. Please note that on non-Linux native hosts, the server might take a few minutes to start after installation completes. diff --git a/app/config/platforms.php b/app/config/platforms.php index f54ded0807..71412482af 100644 --- a/app/config/platforms.php +++ b/app/config/platforms.php @@ -180,7 +180,7 @@ return [ [ 'key' => 'cli', 'name' => 'Command Line', - 'version' => '0.18.0', + 'version' => '0.18.1', 'url' => 'https://github.com/appwrite/sdk-for-cli', 'package' => 'https://www.npmjs.com/package/appwrite-cli', 'enabled' => true, diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 5144441a1f..6c90441afb 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -133,6 +133,7 @@ App::post('/v1/account') }); App::post('/v1/account/sessions/email') + ->alias('/v1/account/sessions') ->desc('Create Account Session with Email') ->groups(['api', 'account', 'auth']) ->label('event', 'users.[userId].sessions.[sessionId].create') diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 5ce5dea75c..989ed660c5 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -96,7 +96,7 @@ function createAttribute(string $databaseId, string $collectionId, Document $att '$id' => $db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key, 'key' => $key, 'databaseInternalId' => $db->getInternalId(), - 'databaseId' => $db->getInternalId(), + 'databaseId' => $db->getId(), 'collectionInternalId' => $collection->getInternalId(), 'collectionId' => $collectionId, 'type' => $type, @@ -498,8 +498,8 @@ App::post('/v1/databases/:databaseId/collections') ->param('collectionId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Collection name. Max length: 128 chars.') ->param('permission', null, new WhiteList(['document', 'collection']), 'Specifies the permissions model used in this collection, which accepts either \'collection\' or \'document\'. For \'collection\' level permission, the permissions specified in read and write params are applied to all documents in the collection. For \'document\' level permissions, read and write permissions are specified in each document. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.') - ->param('read', null, new Permissions(), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.') - ->param('write', null, new Permissions(), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.') + ->param('read', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.') + ->param('write', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.') ->inject('response') ->inject('dbForProject') ->inject('audits') @@ -752,8 +752,8 @@ App::put('/v1/databases/:databaseId/collections/:collectionId') ->param('collectionId', '', new UID(), 'Collection ID.') ->param('name', null, new Text(128), 'Collection name. Max length: 128 chars.') ->param('permission', null, new WhiteList(['document', 'collection']), 'Permissions type model to use for reading documents in this collection. You can use collection-level permission set once on the collection using the `read` and `write` params, or you can set document-level permission where each document read and write params will decide who has access to read and write to each document individually. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.') - ->param('read', null, new Permissions(), 'An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) - ->param('write', null, new Permissions(), 'An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) + ->param('read', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) + ->param('write', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) ->param('enabled', true, new Boolean(), 'Is collection enabled?', true) ->inject('response') ->inject('dbForProject') @@ -1822,8 +1822,8 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') ->param('documentId', '', new CustomId(), 'Document ID. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('collectionId', null, new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/database#createCollection). Make sure to define attributes before creating documents.') ->param('data', [], new JSON(), 'Document data as JSON object.') - ->param('read', null, new Permissions(), 'An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) - ->param('write', null, new Permissions(), 'An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) + ->param('read', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) + ->param('write', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) ->inject('response') ->inject('dbForProject') ->inject('user') @@ -2223,8 +2223,8 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum ->param('collectionId', null, new UID(), 'Collection ID.') ->param('documentId', null, new UID(), 'Document ID.') ->param('data', [], new JSON(), 'Document data as JSON object. Include only attribute and value pairs to be updated.', true) - ->param('read', null, new Permissions(), 'An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) - ->param('write', null, new Permissions(), 'An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) + ->param('read', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) + ->param('write', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) ->inject('response') ->inject('dbForProject') ->inject('audits') @@ -2279,7 +2279,7 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum $data = \array_merge($document->getArrayCopy(), $data); $data['$collection'] = $collection->getId(); // Make sure user don't switch collectionID - $data['$createdAt'] = $collection->getCreatedAt(); // Make sure user don't switch createdAt + $data['$createdAt'] = $document->getCreatedAt(); // Make sure user don't switch createdAt $data['$id'] = $document->getId(); // Make sure user don't switch document unique ID $data['$read'] = (is_null($read)) ? ($document->getRead() ?? []) : $read; // By default inherit read permissions $data['$write'] = (is_null($write)) ? ($document->getWrite() ?? []) : $write; // By default inherit write permissions @@ -2669,7 +2669,7 @@ App::get('/v1/databases/:databaseId/usage') }); App::get('/v1/databases/:databaseId/collections/:collectionId/usage') - ->alias('/v1/database/collections/:collectionId/documents', ['databaseId' => 'default']) + ->alias('/v1/database/:collectionId/usage', ['databaseId' => 'default']) ->desc('Get usage stats for a collection') ->groups(['api', 'database']) ->label('scope', 'collections.read') diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index e464fb7929..0137ab92a8 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -33,6 +33,7 @@ use Utopia\Config\Config; use Cron\CronExpression; use Executor\Executor; use Utopia\CLI\Console; +use Utopia\Database\Validator\Permissions; use Utopia\Validator\Boolean; include_once __DIR__ . '/../shared/api.php'; @@ -51,7 +52,7 @@ App::post('/v1/functions') ->label('sdk.response.model', Response::MODEL_FUNCTION) ->param('functionId', '', new CustomId(), 'Function ID. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Function name. Max length: 128 chars.') - ->param('execute', [], new ArrayList(new Text(64), APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed, each 64 characters long.') + ->param('execute', [], new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed, each 64 characters long.') ->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.') ->param('vars', [], new Assoc(), 'Key-value JSON object that will be passed to the function as environment variables.', true) ->param('events', [], new ArrayList(new ValidatorEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true) @@ -289,7 +290,7 @@ App::put('/v1/functions/:functionId') ->label('sdk.response.model', Response::MODEL_FUNCTION) ->param('functionId', '', new UID(), 'Function ID.') ->param('name', '', new Text(128), 'Function name. Max length: 128 chars.') - ->param('execute', [], new ArrayList(new Text(64), APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed, each 64 characters long.') + ->param('execute', [], new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed, each 64 characters long.') ->param('vars', [], new Assoc(), 'Key-value JSON object that will be passed to the function as environment variables.', true) ->param('events', [], new ArrayList(new ValidatorEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true) ->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true) @@ -696,7 +697,7 @@ App::get('/v1/functions/:functionId/deployments/:deploymentId') ->label('sdk.description', '/docs/references/functions/get-deployment.md') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) - ->label('sdk.response.model', Response::MODEL_DEPLOYMENT_LIST) + ->label('sdk.response.model', Response::MODEL_DEPLOYMENT) ->param('functionId', '', new UID(), 'Function ID.') ->param('deploymentId', '', new UID(), 'Deployment ID.') ->inject('response') diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 1862808fef..3027524055 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -113,7 +113,7 @@ App::post('/v1/projects') $collections = Config::getParam('collections', []); $dbForProject->setNamespace("_{$project->getInternalId()}"); - $dbForProject->create('appwrite'); + $dbForProject->create(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); $audit = new Audit($dbForProject); $audit->setup(); diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 9cc9d9194d..a0b91e7768 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -56,8 +56,8 @@ App::post('/v1/storage/buckets') ->param('bucketId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `unique()` to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Bucket name') ->param('permission', null, new WhiteList(['file', 'bucket']), 'Permissions type model to use for reading files in this bucket. You can use bucket-level permission set once on the bucket using the `read` and `write` params, or you can set file-level permission where each file read and write params will decide who has access to read and write to each file individually. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') - ->param('read', null, new Permissions(), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) - ->param('write', null, new Permissions(), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) + ->param('read', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) + ->param('write', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) ->param('enabled', true, new Boolean(true), 'Is bucket enabled?', true) ->param('maximumFileSize', (int) App::getEnv('_APP_STORAGE_LIMIT', 0), new Range(1, (int) App::getEnv('_APP_STORAGE_LIMIT', 0)), 'Maximum file size allowed in bytes. Maximum allowed value is ' . Storage::human(App::getEnv('_APP_STORAGE_LIMIT', 0), 0) . '. For self-hosted setups you can change the max limit by changing the `_APP_STORAGE_LIMIT` environment variable. [Learn more about storage environment variables](docs/environment-variables#storage)', true) ->param('allowedFileExtensions', [], new ArrayList(new Text(64), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Allowed file extensions. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' extensions are allowed, each 64 characters long.', true) @@ -224,8 +224,8 @@ App::put('/v1/storage/buckets/:bucketId') ->param('bucketId', '', new UID(), 'Bucket unique ID.') ->param('name', null, new Text(128), 'Bucket name', false) ->param('permission', null, new WhiteList(['file', 'bucket']), 'Permissions type model to use for reading files in this bucket. You can use bucket-level permission set once on the bucket using the `read` and `write` params, or you can set file-level permission where each file read and write params will decide who has access to read and write to each file individually. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') - ->param('read', null, new Permissions(), 'An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) - ->param('write', null, new Permissions(), 'An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) + ->param('read', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) + ->param('write', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) ->param('enabled', true, new Boolean(true), 'Is bucket enabled?', true) ->param('maximumFileSize', null, new Range(1, (int) App::getEnv('_APP_STORAGE_LIMIT', 0)), 'Maximum file size allowed in bytes. Maximum allowed value is ' . Storage::human((int)App::getEnv('_APP_STORAGE_LIMIT', 0), 0) . '. For self hosted version you can change the limit by changing _APP_STORAGE_LIMIT environment variable. [Learn more about storage environment variables](docs/environment-variables#storage)', true) ->param('allowedFileExtensions', [], new ArrayList(new Text(64), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Allowed file extensions. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' extensions are allowed, each 64 characters long.', true) @@ -342,8 +342,8 @@ App::post('/v1/storage/buckets/:bucketId/files') ->param('bucketId', null, new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket).') ->param('fileId', '', new CustomId(), 'File ID. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('file', [], new File(), 'Binary file.', false) - ->param('read', null, new Permissions(), 'An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) - ->param('write', null, new Permissions(), 'An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) + ->param('read', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) + ->param('write', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) ->inject('request') ->inject('response') ->inject('dbForProject') @@ -1294,8 +1294,8 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId') ->label('sdk.response.model', Response::MODEL_FILE) ->param('bucketId', null, new UID(), 'Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket).') ->param('fileId', '', new UID(), 'File unique ID.') - ->param('read', null, new Permissions(), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) - ->param('write', null, new Permissions(), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) + ->param('read', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) + ->param('write', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions.', true) ->inject('response') ->inject('dbForProject') ->inject('user') diff --git a/app/init.php b/app/init.php index 0cd089028d..78ea9990ba 100644 --- a/app/init.php +++ b/app/init.php @@ -27,6 +27,7 @@ use Appwrite\Auth\Phone\Mock; use Appwrite\Auth\Phone\Telesign; use Appwrite\Auth\Phone\TextMagic; use Appwrite\Auth\Phone\Twilio; +use Appwrite\Auth\Phone\Msg91; use Appwrite\DSN\DSN; use Appwrite\Event\Audit; use Appwrite\Event\Database as EventDatabase; @@ -86,8 +87,8 @@ const APP_LIMIT_COMPRESSION = 20000000; //20MB const APP_LIMIT_ARRAY_PARAMS_SIZE = 100; // Default maximum of how many elements can there be in API parameter that expects array value const APP_LIMIT_ARRAY_ELEMENT_SIZE = 4096; // Default maximum length of element in array parameter represented by maximum URL length. const APP_LIMIT_SUBQUERY = 1000; -const APP_CACHE_BUSTER = 401; -const APP_VERSION_STABLE = '0.15.1'; +const APP_CACHE_BUSTER = 402; +const APP_VERSION_STABLE = '0.15.2'; const APP_DATABASE_ATTRIBUTE_EMAIL = 'email'; const APP_DATABASE_ATTRIBUTE_ENUM = 'enum'; const APP_DATABASE_ATTRIBUTE_IP = 'ip'; @@ -996,6 +997,7 @@ App::setResource('phone', function () { 'twilio' => new Twilio($user, $secret), 'text-magic' => new TextMagic($user, $secret), 'telesign' => new Telesign($user, $secret), + 'msg91' => new Msg91($user, $secret), default => null }; }); diff --git a/app/realtime.php b/app/realtime.php index d13e1c867f..09e419dcce 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -491,8 +491,12 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re $database = new Database(new MariaDB($db), $cache); $database->setDefaultDatabase(App::getEnv('_APP_DB_SCHEMA', 'appwrite')); $database->setNamespace("_console"); - $project = Authorization::skip(fn() => $database->getDocument('projects', $realtime->connections[$connection]['projectId'])); - $database->setNamespace("_{$project->getInternalId()}"); + $projectId = $realtime->connections[$connection]['projectId']; + + if ($projectId !== 'console') { + $project = Authorization::skip(fn() => $database->getDocument('projects', $projectId)); + $database->setNamespace("_{$project->getInternalId()}"); + } /* * Abuse Check diff --git a/app/tasks/usage.php b/app/tasks/usage.php index 26e47adfea..7a22d7e79f 100644 --- a/app/tasks/usage.php +++ b/app/tasks/usage.php @@ -83,7 +83,7 @@ $logError = function (Throwable $error, string $action = 'syncUsageStats') use ( $version = App::getEnv('_APP_VERSION', 'UNKNOWN'); $log = new Log(); - $log->setNamespace("realtime"); + $log->setNamespace("usage"); $log->setServer(\gethostname()); $log->setVersion($version); $log->setType(Log::TYPE_ERROR); diff --git a/app/views/console/databases/database.phtml b/app/views/console/databases/database.phtml index 612863507d..6af07cb091 100644 --- a/app/views/console/databases/database.phtml +++ b/app/views/console/databases/database.phtml @@ -292,8 +292,8 @@
  • -
  • Last Updated:
  • -
  • Created:
  • +
  • Last Updated:
  • +
  • Created:
new Twilio($user, $secret), 'text-magic' => new TextMagic($user, $secret), 'telesign' => new Telesign($user, $secret), + 'msg91' => new Msg91($user, $secret), default => null }; diff --git a/composer.json b/composer.json index e3febca675..c0f839e594 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,11 @@ "email": "eldad@appwrite.io" } ], + "scripts": { + "test": "vendor/bin/phpunit", + "lint": "vendor/bin/phpcs", + "format": "vendor/bin/phpcbf" + }, "autoload": { "psr-4": { "Appwrite\\": "src/Appwrite", @@ -75,7 +80,7 @@ } ], "require-dev": { - "appwrite/sdk-generator": "0.19.4", + "appwrite/sdk-generator": "0.19.5", "phpunit/phpunit": "9.5.20", "squizlabs/php_codesniffer": "^3.6", "swoole/ide-helper": "4.8.9", diff --git a/docs/references/account/create-magic-url-session.md b/docs/references/account/create-magic-url-session.md index 4be53f1381..78bf99d55e 100644 --- a/docs/references/account/create-magic-url-session.md +++ b/docs/references/account/create-magic-url-session.md @@ -1 +1 @@ -Sends the user an email with a secret key for creating a session. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [PUT /account/sessions/magic-url](/docs/client/account#accountUpdateMagicURLSession) endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour. If you are on a mobile device you can leave the URL parameter empty, so that the login completion will be handled by your Appwrite instance by default. \ No newline at end of file +Sends the user an email with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [PUT /account/sessions/magic-url](/docs/client/account#accountUpdateMagicURLSession) endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour. If you are on a mobile device you can leave the URL parameter empty, so that the login completion will be handled by your Appwrite instance by default. \ No newline at end of file diff --git a/docs/references/account/create-phone-session.md b/docs/references/account/create-phone-session.md index 677c315ac2..58cf35265d 100644 --- a/docs/references/account/create-phone-session.md +++ b/docs/references/account/create-phone-session.md @@ -1 +1 @@ -Sends the user an SMS with a secret key for creating a session. Use the returned user ID and secret and submit a request to the [PUT /account/sessions/phone](/docs/client/account#accountUpdatePhoneSession) endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes. \ No newline at end of file +Sends the user an SMS with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [PUT /account/sessions/phone](/docs/client/account#accountUpdatePhoneSession) endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes. \ No newline at end of file diff --git a/docs/sdks/cli/GETTING_STARTED.md b/docs/sdks/cli/GETTING_STARTED.md index 2c71d37c0b..4d0f6fcba7 100644 --- a/docs/sdks/cli/GETTING_STARTED.md +++ b/docs/sdks/cli/GETTING_STARTED.md @@ -31,12 +31,6 @@ You can also fetch all the collections in your current project using appwrite init collection ``` -The CLI also comes with a convenient `--all` flag to perform both these steps at once. - -```sh -appwrite init --all -``` - * ### Creating and deploying cloud functions The CLI makes it extremely easy to create and deploy Appwrite's cloud functions. Initialise your new function using @@ -82,12 +76,6 @@ Similarly, you can deploy all your collections to your Appwrite server using appwrite deploy collections ``` -The `deploy` command also comes with a convenient `--all` flag to deploy all your functions and collections at once. - -```sh -appwrite deploy --all -``` - > ### Note > By default, requests to domains with self signed SSL certificates (or no certificates) are disabled. If you trust the domain, you can bypass the certificate validation using ```sh diff --git a/docs/sdks/dart/CHANGELOG.md b/docs/sdks/dart/CHANGELOG.md index 7d8f2aefc0..23aea11553 100644 --- a/docs/sdks/dart/CHANGELOG.md +++ b/docs/sdks/dart/CHANGELOG.md @@ -5,8 +5,8 @@ * **BREAKING** `dateCreated` attribute removed from `Team`, `Execution`, `File` models * **BREAKING** `dateCreated` and `dateUpdated` attribute removed from `Func`, `Deployment`, `Bucket` models * **BREAKING** Realtime channels - * collections.[COLLECTION_ID] is now databases.[DATABASE_ID].ollections.[COLLECTION_ID] - * collections.[COLLECTION_ID].documents is now databases.[DATABASE_ID].ollections.[COLLECTION_ID].documents + * collections.[COLLECTION_ID] is now databases.[DATABASE_ID].collections.[COLLECTION_ID] + * collections.[COLLECTION_ID].documents is now databases.[DATABASE_ID].collections.[COLLECTION_ID].documents **Full Changelog for Appwrite 0.15 can be found here**: https://github.com/appwrite/appwrite/blob/master/CHANGES.md#version-0150 diff --git a/docs/sdks/flutter/CHANGELOG.md b/docs/sdks/flutter/CHANGELOG.md index 80a4e03981..f6fd906a7d 100644 --- a/docs/sdks/flutter/CHANGELOG.md +++ b/docs/sdks/flutter/CHANGELOG.md @@ -6,8 +6,8 @@ * **BREAKING** `dateCreated` attribute removed from `Team`, `Execution`, `File` models * **BREAKING** `dateCreated` and `dateUpdated` attribute removed from `Func`, `Deployment`, `Bucket` models * **BREAKING** Realtime channels - * collections.[COLLECTION_ID] is now databases.[DATABASE_ID].ollections.[COLLECTION_ID] - * collections.[COLLECTION_ID].documents is now databases.[DATABASE_ID].ollections.[COLLECTION_ID].documents + * collections.[COLLECTION_ID] is now databases.[DATABASE_ID].collections.[COLLECTION_ID] + * collections.[COLLECTION_ID].documents is now databases.[DATABASE_ID].collections.[COLLECTION_ID].documents **Full Changelog for Appwrite 0.15 can be found here**: https://github.com/appwrite/appwrite/blob/master/CHANGES.md#version-0150 diff --git a/docs/services/account.md b/docs/services/account.md index d0495b3ba7..999a9be4a4 100644 --- a/docs/services/account.md +++ b/docs/services/account.md @@ -1,6 +1,6 @@ The Account service allows you to authenticate and manage a user account. You can use the account service to update user information, retrieve the user sessions across different devices, and fetch the user security logs with his or her recent activity. -You can authenticate the user account by using multiple sign-in methods available. Once the user is authenticated, a new session object will be created to allow the user to access his or her private data and settings. +Register new user accounts with the [Create Account](/docs/client/account#accountCreate), [Create Magic URL session](/docs/client/account#accountCreateMagicURLSession), or [Create Phone session](/docs/client/account#accountCreatePhoneSession) endpoint. You can authenticate the user account by using multiple sign-in methods available. Once the user is authenticated, a new session object will be created to allow the user to access his or her private data and settings. This service also exposes an endpoint to save and read the [user preferences](/docs/client/account#accountUpdatePrefs) as a key-value object. This feature is handy if you want to allow extra customization in your app. Common usage for this feature may include saving the user preferred locale, timezone, or custom app theme. diff --git a/src/Appwrite/Auth/Phone/Msg91.php b/src/Appwrite/Auth/Phone/Msg91.php new file mode 100644 index 0000000000..64e5973597 --- /dev/null +++ b/src/Appwrite/Auth/Phone/Msg91.php @@ -0,0 +1,46 @@ + utilized from for flow id + * @param string $to + * @param string $message + * @return void + */ + public function send(string $from, string $to, string $message): void + { + $to = ltrim($to, '+'); + $this->request( + method: 'POST', + url: $this->endpoint, + payload: json_encode([ + 'sender' => $this->user, + 'otp' => $message, + 'flow_id' => $from, + 'mobiles' => $to + ]), + headers: [ + "content-type: application/JSON", + "authkey: {$this->secret}", + ] + ); + } +} diff --git a/src/Appwrite/Auth/Phone/Telesign.php b/src/Appwrite/Auth/Phone/Telesign.php index 5272b732ee..520dfc61bf 100644 --- a/src/Appwrite/Auth/Phone/Telesign.php +++ b/src/Appwrite/Auth/Phone/Telesign.php @@ -5,7 +5,7 @@ namespace Appwrite\Auth\Phone; use Appwrite\Auth\Phone; // Reference Material -// https://www.twilio.com/docs/sms/api +// https://developer.telesign.com/enterprise/docs/sms-api-send-an-sms class Telesign extends Phone { diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index fe14c61aa8..a60272f3bd 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -46,7 +46,8 @@ abstract class Migration '0.14.1' => 'V13', '0.14.2' => 'V13', '0.15.0' => 'V14', - '0.15.1' => 'V14' + '0.15.1' => 'V14', + '0.15.2' => 'V14' ]; /** diff --git a/src/Appwrite/Utopia/Response/Model/Database.php b/src/Appwrite/Utopia/Response/Model/Database.php index 96d925c58f..1a98747ac7 100644 --- a/src/Appwrite/Utopia/Response/Model/Database.php +++ b/src/Appwrite/Utopia/Response/Model/Database.php @@ -22,6 +22,18 @@ class Database extends Model 'default' => '', 'example' => 'My Database', ]) + ->addRule('$createdAt', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Collection creation date in Unix timestamp.', + 'default' => 0, + 'example' => 1592981250, + ]) + ->addRule('$updatedAt', [ + 'type' => self::TYPE_INTEGER, + 'description' => 'Collection update date in Unix timestamp.', + 'default' => 0, + 'example' => 1592981250, + ]) ; } diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 9e36632354..283c76a34b 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -120,6 +120,17 @@ trait AccountBase $sessionId = $response['body']['$id']; $session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_' . $this->getProject()['$id']]; + $response = $this->client->call(Client::METHOD_POST, '/account/sessions', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'email' => $email, + 'password' => $password, + ]); + + $this->assertEquals($response['headers']['status-code'], 201); + /** * Test for FAILURE */ @@ -267,7 +278,7 @@ trait AccountBase $this->assertIsArray($response['body']); $this->assertNotEmpty($response['body']); $this->assertCount(2, $response['body']); - $this->assertEquals(1, $response['body']['total']); + $this->assertEquals(2, $response['body']['total']); $this->assertEquals($sessionId, $response['body']['sessions'][0]['$id']); $this->assertEquals('Windows', $response['body']['sessions'][0]['osName']); @@ -325,30 +336,8 @@ trait AccountBase $this->assertEquals($response['headers']['status-code'], 200); $this->assertIsArray($response['body']['logs']); $this->assertNotEmpty($response['body']['logs']); - $this->assertCount(2, $response['body']['logs']); + $this->assertCount(3, $response['body']['logs']); $this->assertIsNumeric($response['body']['total']); - $this->assertContains($response['body']['logs'][0]['event'], ["users.{$userId}.create", "users.{$userId}.sessions.{$sessionId}.create"]); - $this->assertEquals($response['body']['logs'][0]['ip'], filter_var($response['body']['logs'][0]['ip'], FILTER_VALIDATE_IP)); - $this->assertIsNumeric($response['body']['logs'][0]['time']); - - $this->assertEquals('Windows', $response['body']['logs'][0]['osName']); - $this->assertEquals('WIN', $response['body']['logs'][0]['osCode']); - $this->assertEquals('10', $response['body']['logs'][0]['osVersion']); - - $this->assertEquals('browser', $response['body']['logs'][0]['clientType']); - $this->assertEquals('Chrome', $response['body']['logs'][0]['clientName']); - $this->assertEquals('CH', $response['body']['logs'][0]['clientCode']); - $this->assertEquals('70.0', $response['body']['logs'][0]['clientVersion']); - $this->assertEquals('Blink', $response['body']['logs'][0]['clientEngine']); - - $this->assertEquals('desktop', $response['body']['logs'][0]['deviceName']); - $this->assertEquals('', $response['body']['logs'][0]['deviceBrand']); - $this->assertEquals('', $response['body']['logs'][0]['deviceModel']); - $this->assertEquals($response['body']['logs'][0]['ip'], filter_var($response['body']['logs'][0]['ip'], FILTER_VALIDATE_IP)); - - $this->assertEquals('--', $response['body']['logs'][0]['countryCode']); - $this->assertEquals('Unknown', $response['body']['logs'][0]['countryName']); - $this->assertContains($response['body']['logs'][1]['event'], ["users.{$userId}.create", "users.{$userId}.sessions.{$sessionId}.create"]); $this->assertEquals($response['body']['logs'][1]['ip'], filter_var($response['body']['logs'][1]['ip'], FILTER_VALIDATE_IP)); $this->assertIsNumeric($response['body']['logs'][1]['time']); @@ -371,6 +360,28 @@ trait AccountBase $this->assertEquals('--', $response['body']['logs'][1]['countryCode']); $this->assertEquals('Unknown', $response['body']['logs'][1]['countryName']); + $this->assertContains($response['body']['logs'][2]['event'], ["users.{$userId}.create", "users.{$userId}.sessions.{$sessionId}.create"]); + $this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP)); + $this->assertIsNumeric($response['body']['logs'][2]['time']); + + $this->assertEquals('Windows', $response['body']['logs'][2]['osName']); + $this->assertEquals('WIN', $response['body']['logs'][2]['osCode']); + $this->assertEquals('10', $response['body']['logs'][2]['osVersion']); + + $this->assertEquals('browser', $response['body']['logs'][2]['clientType']); + $this->assertEquals('Chrome', $response['body']['logs'][2]['clientName']); + $this->assertEquals('CH', $response['body']['logs'][2]['clientCode']); + $this->assertEquals('70.0', $response['body']['logs'][2]['clientVersion']); + $this->assertEquals('Blink', $response['body']['logs'][2]['clientEngine']); + + $this->assertEquals('desktop', $response['body']['logs'][2]['deviceName']); + $this->assertEquals('', $response['body']['logs'][2]['deviceBrand']); + $this->assertEquals('', $response['body']['logs'][2]['deviceModel']); + $this->assertEquals($response['body']['logs'][2]['ip'], filter_var($response['body']['logs'][2]['ip'], FILTER_VALIDATE_IP)); + + $this->assertEquals('--', $response['body']['logs'][2]['countryCode']); + $this->assertEquals('Unknown', $response['body']['logs'][2]['countryName']); + $responseLimit = $this->client->call(Client::METHOD_GET, '/account/logs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', @@ -400,7 +411,7 @@ trait AccountBase $this->assertEquals($responseOffset['headers']['status-code'], 200); $this->assertIsArray($responseOffset['body']['logs']); $this->assertNotEmpty($responseOffset['body']['logs']); - $this->assertCount(1, $responseOffset['body']['logs']); + $this->assertCount(2, $responseOffset['body']['logs']); $this->assertIsNumeric($responseOffset['body']['total']); $this->assertEquals($response['body']['logs'][1], $responseOffset['body']['logs'][0]); diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 747d725e6c..34a4160fde 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -922,6 +922,63 @@ trait DatabasesBase return ['documents' => $documents['body']['documents'], 'databaseId' => $databaseId]; } + public function testCreateCollectionAlias(): array + { + // Create default database + $database = $this->client->call(Client::METHOD_POST, '/databases', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ], [ + 'databaseId' => 'default', + 'name' => 'Default' + ]); + + $this->assertNotEmpty($database['body']['$id']); + $this->assertEquals(201, $database['headers']['status-code']); + + /** + * Test for SUCCESS + */ + + $movies = $this->client->call(Client::METHOD_POST, '/database/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'collectionId' => 'unique()', + 'name' => 'Movies', + 'read' => [], + 'write' => [], + 'permission' => 'document', + ]); + + $this->assertEquals($movies['headers']['status-code'], 201); + $this->assertEquals($movies['body']['name'], 'Movies'); + + return ['moviesId' => $movies['body']['$id']]; + } + + /** + * @depends testCreateCollectionAlias + */ + public function testListDocumentsAlias(array $data): array + { + /** + * Test for SUCCESS + */ + + $documents = $this->client->call(Client::METHOD_GET, '/database/collections/' . $data['moviesId'] . '/documents', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals($documents['headers']['status-code'], 200); + $this->assertEquals($documents['body']['total'], 0); + + return []; + } + /** * @depends testListDocuments */ @@ -2302,6 +2359,67 @@ trait DatabasesBase return $data; } + /** + * @depends testUniqueIndexDuplicate + */ + public function testPersistantCreatedAt(array $data): array + { + $headers = $this->getSide() === 'client' ? array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()) : [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]; + + $document = $this->client->call(Client::METHOD_POST, '/databases/' . $data['databaseId'] . '/collections/' . $data['moviesId'] . '/documents', $headers, [ + 'documentId' => 'unique()', + 'data' => [ + 'title' => 'Creation Date Test', + 'releaseYear' => 2000 + ] + ]); + + $this->assertEquals($document['body']['title'], 'Creation Date Test'); + + $documentId = $document['body']['$id']; + $createdAt = $document['body']['$createdAt']; + $updatedAt = $document['body']['$updatedAt']; + + \sleep(1); + + $document = $this->client->call(Client::METHOD_PATCH, '/databases/' . $data['databaseId'] . '/collections/' . $data['moviesId'] . '/documents/' . $documentId, $headers, [ + 'data' => [ + 'title' => 'Updated Date Test', + ] + ]); + + $updatedAtSecond = $document['body']['$updatedAt']; + + $this->assertEquals($document['body']['title'], 'Updated Date Test'); + $this->assertEquals($document['body']['$createdAt'], $createdAt); + $this->assertNotEquals($document['body']['$updatedAt'], $updatedAt); + + \sleep(1); + + $document = $this->client->call(Client::METHOD_PATCH, '/databases/' . $data['databaseId'] . '/collections/' . $data['moviesId'] . '/documents/' . $documentId, $headers, [ + 'data' => [ + 'title' => 'Again Updated Date Test', + '$createdAt' => 1657271810, // Try to update it, should not work + '$updatedAt' => 1657271810 // Try to update it, should not work + ] + ]); + + $this->assertEquals($document['body']['title'], 'Again Updated Date Test'); + $this->assertEquals($document['body']['$createdAt'], $createdAt); + $this->assertNotEquals($document['body']['$updatedAt'], $updatedAt); + $this->assertNotEquals($document['body']['$updatedAt'], $updatedAtSecond); + $this->assertNotEquals($document['body']['$updatedAt'], 1657271810); + + return $data; + } + public function testUpdatePermissionsWithEmptyPayload(): array { // Create Database @@ -2376,7 +2494,7 @@ trait DatabasesBase $document = $this->client->call(Client::METHOD_PATCH, '/databases/' . $databaseId . '/collections/' . $moviesId . '/documents/' . $id, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ + ], $this->getHeaders()), [ 'read' => ['user:' . $this->getUser()['$id']], ]); diff --git a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php index 0180a87de3..c344114364 100644 --- a/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsConsoleClientTest.php @@ -37,6 +37,18 @@ class FunctionsConsoleClientTest extends Scope $this->assertEquals(201, $function['headers']['status-code']); + $response = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'functionId' => 'unique()', + 'name' => 'Test Failure', + 'execute' => ['some-random-string'], + 'runtime' => 'php-8.0' + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + return [ 'functionId' => $function['body']['$id'] ]; diff --git a/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php b/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php index 466c432825..8217f46539 100644 --- a/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php @@ -13,6 +13,111 @@ class RealtimeConsoleClientTest extends Scope use ProjectCustom; use SideConsole; + public function testManualAuthentication() + { + $user = $this->getUser(); + $userId = $user['$id'] ?? ''; + $session = $user['session'] ?? ''; + + /** + * Test for SUCCESS + */ + $client = $this->getWebsocket(['account'], [ + 'origin' => 'http://localhost' + ]); + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('connected', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertCount(1, $response['data']['channels']); + $this->assertContains('account', $response['data']['channels']); + + $client->send(\json_encode([ + 'type' => 'authentication', + 'data' => [ + 'session' => $session + ] + ])); + + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('response', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertEquals('authentication', $response['data']['to']); + $this->assertTrue($response['data']['success']); + $this->assertNotEmpty($response['data']['user']); + $this->assertEquals($userId, $response['data']['user']['$id']); + + /** + * Test for FAILURE + */ + $client->send(\json_encode([ + 'type' => 'authentication', + 'data' => [ + 'session' => 'invalid_session' + ] + ])); + + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('error', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertEquals(1003, $response['data']['code']); + $this->assertEquals('Session is not valid.', $response['data']['message']); + + $client->send(\json_encode([ + 'type' => 'authentication', + 'data' => [] + ])); + + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('error', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertEquals(1003, $response['data']['code']); + $this->assertEquals('Payload is not valid.', $response['data']['message']); + + $client->send(\json_encode([ + 'type' => 'unknown', + 'data' => [ + 'session' => 'invalid_session' + ] + ])); + + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('error', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertEquals(1003, $response['data']['code']); + $this->assertEquals('Message type is not valid.', $response['data']['message']); + + $client->send(\json_encode([ + 'test' => '123', + ])); + + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('error', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertEquals(1003, $response['data']['code']); + $this->assertEquals('Message format is not valid.', $response['data']['message']); + + + $client->close(); + } + public function testAttributes() { $user = $this->getUser(); diff --git a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php index 1a6aed65a7..c60e57f6af 100644 --- a/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php +++ b/tests/e2e/Services/Webhooks/WebhooksCustomServerTest.php @@ -467,6 +467,16 @@ class WebhooksCustomServerTest extends Scope $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Id'] ?? '', $this->getProject()['webhookId']); $this->assertEquals($webhook['headers']['X-Appwrite-Webhook-Project-Id'] ?? '', $this->getProject()['$id']); + $function = $this->client->call(Client::METHOD_PUT, '/functions/' . $data['functionId'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'name' => 'Test Failure', + 'execute' => [ 'not-valid-permission' ] + ]); + + $this->assertEquals($function['headers']['status-code'], 400); + return $data; }