diff --git a/app/config/collections.php b/app/config/collections.php index 38568a01c3..4da8de6c45 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -10,7 +10,7 @@ $auth = Config::getParam('auth', []); * $collection => id of the parent collection where this will be inserted * $id => id of this collection * name => name of this collection - * project => whether or not this collection should be created per project + * project => whether this collection should be created per project * attributes => list of attributes * indexes => list of indexes */ @@ -99,6 +99,17 @@ $collections = [ 'default' => null, 'array' => false, ], + [ + '$id' => 'documentSecurity', + 'type' => Database::VAR_BOOLEAN, + 'signed' => true, + 'size' => 0, + 'format' => '', + 'filters' => [], + 'required' => true, + 'default' => null, + 'array' => false, + ], [ '$id' => 'attributes', 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 32b1db1b75..3c4c718aa1 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -498,7 +498,7 @@ 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('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with 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('documentSecurity', false, new Boolean(), '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('documentSecurity', false, new Boolean(true), '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.') ->inject('response') ->inject('dbForProject') ->inject('audits') @@ -517,9 +517,10 @@ App::post('/v1/databases/:databaseId/collections') try { $dbForProject->createDocument('database_' . $database->getInternalId(), new Document([ '$id' => $collectionId, + '$permissions' => $permissions ?? [], 'databaseInternalId' => $database->getInternalId(), 'databaseId' => $databaseId, - '$permissions' => $permissions ?? [], + 'documentSecurity' => $documentSecurity, 'enabled' => true, 'name' => $name, 'search' => implode(' ', [$collectionId, $name]), @@ -749,7 +750,7 @@ 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('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with permissions. By default no user is granted with any permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) - ->param('documentSecurity', false, new Boolean(), 'Whether to enable document-level permission where each document\'s permissions parameter will decide who has access to each file individually. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') + ->param('documentSecurity', false, new Boolean(true), 'Whether to enable document-level permission where each document\'s permissions parameter will decide who has access to each file individually. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->param('enabled', true, new Boolean(), 'Is collection enabled?', true) ->inject('response') ->inject('dbForProject') @@ -774,8 +775,8 @@ App::put('/v1/databases/:databaseId/collections/:collectionId') try { $collection = $dbForProject->updateDocument('database_' . $database->getInternalId(), $collectionId, $collection - ->setAttribute('$permissions', $permissions) ->setAttribute('name', $name) + ->setAttribute('$permissions', $permissions) ->setAttribute('documentSecurity', $documentSecurity) ->setAttribute('enabled', $enabled) ->setAttribute('search', implode(' ', [$collectionId, $name]))); diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index dcad8cc2a5..81e255a414 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -55,8 +55,8 @@ App::post('/v1/storage/buckets') ->label('sdk.response.model', Response::MODEL_BUCKET) ->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('fileSecurity', false, new Boolean(), 'Whether to enable file-level permission where each files permissions parameter will decide who has access to each file individually. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with permissions. By default no user is granted with any permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) + ->param('fileSecurity', false, new Boolean(true), 'Whether to enable file-level permission where each files permissions parameter will decide who has access to each file individually. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->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) @@ -106,13 +106,14 @@ App::post('/v1/storage/buckets') $bucket = $dbForProject->createDocument('buckets', new Document([ '$id' => $bucketId, '$collection' => 'buckets', + '$permissions' => $permissions, 'name' => $name, 'maximumFileSize' => $maximumFileSize, 'allowedFileExtensions' => $allowedFileExtensions, + 'fileSecurity' => (bool) filter_var($fileSecurity, FILTER_VALIDATE_BOOLEAN), 'enabled' => (bool) filter_var($enabled, FILTER_VALIDATE_BOOLEAN), 'encryption' => (bool) filter_var($encryption, FILTER_VALIDATE_BOOLEAN), 'antivirus' => (bool) filter_var($antivirus, FILTER_VALIDATE_BOOLEAN), - '$permissions' => $permissions, 'search' => implode(' ', [$bucketId, $name]), ])); @@ -220,8 +221,8 @@ App::put('/v1/storage/buckets/:bucketId') ->label('sdk.response.model', Response::MODEL_BUCKET) ->param('bucketId', '', new UID(), 'Bucket unique ID.') ->param('name', null, new Text(128), 'Bucket name', false) - ->param('fileSecurity', false, new Boolean(), 'Whether to enable file-level permission where each files permissions parameter will decide who has access to each file individually. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with permissions. By default no user is granted with any permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) + ->param('fileSecurity', false, new Boolean(true), 'Whether to enable file-level permission where each files permissions parameter will decide who has access to each file individually. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->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) @@ -251,6 +252,7 @@ App::put('/v1/storage/buckets/:bucketId') ->setAttribute('$permissions', $permissions) ->setAttribute('maximumFileSize', $maximumFileSize) ->setAttribute('allowedFileExtensions', $allowedFileExtensions) + ->setAttribute('fileSecurity', (bool) filter_var($fileSecurity, FILTER_VALIDATE_BOOLEAN)) ->setAttribute('enabled', (bool) filter_var($enabled, FILTER_VALIDATE_BOOLEAN)) ->setAttribute('encryption', (bool) filter_var($encryption, FILTER_VALIDATE_BOOLEAN)) ->setAttribute('antivirus', (bool) filter_var($antivirus, FILTER_VALIDATE_BOOLEAN))); diff --git a/composer.lock b/composer.lock index 6f2899f72d..230e98c703 100644 --- a/composer.lock +++ b/composer.lock @@ -2055,12 +2055,12 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "ea890cc8bf53bd379f74f6f9a444a18d817ec67d" + "reference": "6dc6e3870f017ac8e6be3af0f897af88b01a3ee7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/ea890cc8bf53bd379f74f6f9a444a18d817ec67d", - "reference": "ea890cc8bf53bd379f74f6f9a444a18d817ec67d", + "url": "https://api.github.com/repos/utopia-php/database/zipball/6dc6e3870f017ac8e6be3af0f897af88b01a3ee7", + "reference": "6dc6e3870f017ac8e6be3af0f897af88b01a3ee7", "shasum": "" }, "require": { @@ -2111,7 +2111,7 @@ "issues": "https://github.com/utopia-php/database/issues", "source": "https://github.com/utopia-php/database/tree/refactor-permissions" }, - "time": "2022-08-02T06:51:50+00:00" + "time": "2022-08-03T10:59:18+00:00" }, { "name": "utopia-php/domains",