1
0
Fork 0
mirror of synced 2024-10-02 10:16:27 +13:00

Merge branch 'feat-sb-create' into feat-sb-list

This commit is contained in:
Damodar Lohani 2021-06-15 14:20:12 +05:45
commit 017da96eb0
3 changed files with 142 additions and 21 deletions

View file

@ -967,6 +967,131 @@ $collections = [
] ]
], ],
], ],
'buckets' => [
'$collection' => Database::COLLECTIONS,
'$id' => 'buckets',
'$permissions' => ['read' => ['*']],
'name' => 'Buckets',
'structure' => true,
'attributes' => [
[
'$id' => 'dateCreated',
'type' => Database::VAR_INTEGER,
'format' => '',
'signed' => false,
'size' => 0,
'required' => false,
'array' => false,
'filters' => [],
],
[
'$id' => 'dateUpdated',
'type' => Database::VAR_INTEGER,
'size' => 0,
'format' => '',
'signed' => true,
'required' => false,
'array' => false,
'filters' => [],
],
[
'$id' => 'enabled',
'type' => Database::VAR_BOOLEAN,
'signed' => true,
'size' => 0,
'format' => '',
'filters' => [],
'required' => true,
'array' => false,
],
[
'$id' => 'name',
'type' => Database::VAR_STRING,
'signed' => true,
'size' => 128,
'format' => '',
'filters' => [],
'required' => true,
'array' => false,
],
[
'label' => 'Adapter',
'$id' => 'adapter',
'type' => Database::VAR_STRING,
'signed' => true,
'size' => 64,
'format' => '',
'filters' => [],
'required' => true,
'array' => false,
],
[
'$id' => 'adapterCredentials',
'type' => Database::VAR_STRING,
'signed' => true,
'size' => 16384,
'format' => '',
'required' => false,
'array' => false,
'filters' => ['json']
],
[
'$id' => 'maximumFileSize',
'type' => Database::VAR_INTEGER,
'signed' => true,
'size' => 0,
'format' => '',
'filters' => [],
'required' => true,
'array' => false,
],
[
'$id' => 'allowedFileExtensions',
'type' => Database::VAR_STRING,
'signed' => true,
'size' => 64,
'format' => '',
'filters' => [],
'required' => true,
'array' => true,
],
[
'label' => 'Encryption',
'$id' => 'encryption',
'type' => Database::VAR_BOOLEAN,
'signed' => true,
'size' => 0,
'format' => '',
'filters' => [],
'required' => true,
'array' => false,
],
[
'label' => 'Virus Scan',
'$id' => 'antiVirus',
'type' => Database::VAR_BOOLEAN,
'signed' => true,
'size' => 0,
'format' => '',
'filters' => [],
'required' => true,
'array' => false,
],
],
'indexes' => [
[
'$id' => '_fulltext_name',
'type' => Database::INDEX_FULLTEXT,
'attributes' => ['name'],
'lengths' => [1024],
'orders' => [Database::ORDER_ASC],
]
]
]
]; ];
/* /*

View file

@ -26,7 +26,6 @@ use Utopia\Validator\Integer;
use Appwrite\Database\Exception\Authorization as AuthorizationException; use Appwrite\Database\Exception\Authorization as AuthorizationException;
use Appwrite\Database\Exception\Structure as StructureException; use Appwrite\Database\Exception\Structure as StructureException;
use Utopia\Database\Query; use Utopia\Database\Query;
use Utopia\Validator\Numeric;
App::post('/v1/storage/buckets') App::post('/v1/storage/buckets')
->desc('Create storage bucket') ->desc('Create storage bucket')
@ -50,20 +49,21 @@ App::post('/v1/storage/buckets')
->param('read', null, new ArrayList(new Text(64)), 'An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) ->param('read', null, new ArrayList(new Text(64)), 'An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true)
->param('write', null, new ArrayList(new Text(64)), 'An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true) ->param('write', null, new ArrayList(new Text(64)), 'An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.', true)
->inject('response') ->inject('response')
->inject('projectDB') ->inject('dbForInternal')
->inject('user') ->inject('user')
->inject('audits') ->inject('audits')
->action(function ($name, $maximumFileSize, $allowedFileExtensions, $enabled, $adapter, $encryption, $antiVirus, $read, $write, $response, $projectDB, $user, $audits) { ->action(function ($name, $maximumFileSize, $allowedFileExtensions, $enabled, $adapter, $encryption, $antiVirus, $read, $write, $response, $dbForInternal, $user, $audits) {
/** @var Utopia\Swoole\Request $request */ /** @var Utopia\Swoole\Request $request */
/** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Database\Database $projectDB */ /** @var Utopia\Database\Database $dbForInternal */
/** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Document $user */
/** @var Appwrite\Event\Event $audits */ /** @var Appwrite\Event\Event $audits */
try { try {
$data = [ $data = [
'$collection' => Database::SYSTEM_COLLECTION_BUCKETS, '$collection' => 'buckets',
'dateCreated' => \time(), 'dateCreated' => \time(),
'dateUpdated' => \time(),
'name' => $name, 'name' => $name,
'maximumFileSize' => $maximumFileSize, 'maximumFileSize' => $maximumFileSize,
'allowedFileExtensions' => $allowedFileExtensions, 'allowedFileExtensions' => $allowedFileExtensions,
@ -72,30 +72,26 @@ App::post('/v1/storage/buckets')
'encryption' => $encryption, 'encryption' => $encryption,
'antiVirus' => $antiVirus, 'antiVirus' => $antiVirus,
]; ];
$data['$permissions'] = [
'read' => (is_null($read) && !$user->isEmpty()) ? ['user:'.$user->getId()] : $read ?? [], // By default set read permissions for user $data['$read'] = (is_null($read) && !$user->isEmpty()) ? ['user:' . $user->getId()] : $read ?? []; // By default set read permissions for user
'write' => (is_null($write) && !$user->isEmpty()) ? ['user:'.$user->getId()] : $write ?? [], // By default set write permissions for user $data['$write'] = (is_null($write) && !$user->isEmpty()) ? ['user:' . $user->getId()] : $write ?? []; // By default set write permissions for user
]; $data = $dbForInternal->createDocument('buckets', new Document($data));
$data = $projectDB->createDocument($data);
} catch (AuthorizationException $exception) { } catch (AuthorizationException $exception) {
throw new Exception('Unauthorized permissions', 401); throw new Exception('Unauthorized permissions', 401);
} catch (StructureException $exception) { } catch (StructureException $exception) {
throw new Exception('Bad structure. '.$exception->getMessage(), 400); throw new Exception('Bad structure. ' . $exception->getMessage(), 400);
} catch (\Exception $exception) { } catch (\Exception$exception) {
throw new Exception('Failed saving document to DB', 500); throw new Exception('Failed saving document to DB', 500);
} }
$audits $audits
->setParam('event', 'database.collections.create') ->setParam('event', 'database.collections.create')
->setParam('resource', 'database/collection/'.$data->getId()) ->setParam('resource', 'database/collection/' . $data->getId())
->setParam('data', $data->getArrayCopy()) ->setParam('data', $data->getArrayCopy())
; ;
$response $response->setStatusCode(Response::STATUS_CODE_CREATED);
->setStatusCode(Response::STATUS_CODE_CREATED) $response->dynamic2($data, Response::MODEL_BUCKET);
->dynamic($data, Response::MODEL_BUCKET)
;
}); });
App::get('/v1/storage/buckets') App::get('/v1/storage/buckets')

6
composer.lock generated
View file

@ -1704,7 +1704,7 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/lohanidamodar/audit", "url": "https://github.com/lohanidamodar/audit",
"reference": "b3ca9fa928fdec8c966596cbd85ee1141c79b6eb" "reference": "d5591321161b81043c45be3c53ce9dcfa2d81d72"
}, },
"require": { "require": {
"ext-pdo": "*", "ext-pdo": "*",
@ -1738,7 +1738,7 @@
"upf", "upf",
"utopia" "utopia"
], ],
"time": "2021-06-13T07:41:15+00:00" "time": "2021-06-14T07:38:18+00:00"
}, },
{ {
"name": "utopia-php/cache", "name": "utopia-php/cache",
@ -6195,5 +6195,5 @@
"platform-overrides": { "platform-overrides": {
"php": "8.0" "php": "8.0"
}, },
"plugin-api-version": "2.0.0" "plugin-api-version": "2.1.0"
} }