Merge branch 'feat-sb-list' into feat-sb-id-get
This commit is contained in:
commit
8265884fb9
3 changed files with 149 additions and 36 deletions
|
@ -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],
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
/*
|
||||
|
|
|
@ -26,7 +26,6 @@ use Utopia\Validator\Integer;
|
|||
use Appwrite\Database\Exception\Authorization as AuthorizationException;
|
||||
use Appwrite\Database\Exception\Structure as StructureException;
|
||||
use Utopia\Database\Query;
|
||||
use Utopia\Validator\Numeric;
|
||||
|
||||
App::post('/v1/storage/buckets')
|
||||
->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('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('projectDB')
|
||||
->inject('dbForInternal')
|
||||
->inject('user')
|
||||
->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 Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
/** @var Utopia\Database\Database $dbForInternal */
|
||||
/** @var Appwrite\Database\Document $user */
|
||||
/** @var Appwrite\Event\Event $audits */
|
||||
|
||||
try {
|
||||
$data = [
|
||||
'$collection' => Database::SYSTEM_COLLECTION_BUCKETS,
|
||||
'$collection' => 'buckets',
|
||||
'dateCreated' => \time(),
|
||||
'dateUpdated' => \time(),
|
||||
'name' => $name,
|
||||
'maximumFileSize' => $maximumFileSize,
|
||||
'allowedFileExtensions' => $allowedFileExtensions,
|
||||
|
@ -72,11 +72,10 @@ App::post('/v1/storage/buckets')
|
|||
'encryption' => $encryption,
|
||||
'antiVirus' => $antiVirus,
|
||||
];
|
||||
$data['$permissions'] = [
|
||||
'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 = $projectDB->createDocument($data);
|
||||
|
||||
$data['$read'] = (is_null($read) && !$user->isEmpty()) ? ['user:' . $user->getId()] : $read ?? []; // By default set read 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));
|
||||
} catch (AuthorizationException $exception) {
|
||||
throw new Exception('Unauthorized permissions', 401);
|
||||
} catch (StructureException $exception) {
|
||||
|
@ -91,11 +90,8 @@ App::post('/v1/storage/buckets')
|
|||
->setParam('data', $data->getArrayCopy())
|
||||
;
|
||||
|
||||
$response
|
||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||
->dynamic($data, Response::MODEL_BUCKET)
|
||||
;
|
||||
|
||||
$response->setStatusCode(Response::STATUS_CODE_CREATED);
|
||||
$response->dynamic2($data, Response::MODEL_BUCKET);
|
||||
});
|
||||
|
||||
App::get('/v1/storage/buckets')
|
||||
|
@ -114,24 +110,16 @@ App::get('/v1/storage/buckets')
|
|||
->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true)
|
||||
->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true)
|
||||
->inject('response')
|
||||
->inject('projectDB')
|
||||
->action(function ($search, $limit, $offset, $orderType, $response, $projectDB) {
|
||||
->inject('dbForInternal')
|
||||
->action(function ($search, $limit, $offset, $orderType, $response, $dbForInternal) {
|
||||
/** @var Appwrite\Utopia\Response $response */
|
||||
/** @var Appwrite\Database\Database $projectDB */
|
||||
/** @var Utopia\Database\Database $dbForInternal */
|
||||
|
||||
$results = $projectDB->getCollection([
|
||||
'limit' => $limit,
|
||||
'offset' => $offset,
|
||||
'orderType' => $orderType,
|
||||
'search' => $search,
|
||||
'filters' => [
|
||||
'$collection='.Database::SYSTEM_COLLECTION_BUCKETS,
|
||||
],
|
||||
]);
|
||||
$queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, $search)] : [];
|
||||
|
||||
$response->dynamic(new Document([
|
||||
'sum' => $projectDB->getSum(),
|
||||
'buckets' => $results
|
||||
$response->dynamic2(new Document([
|
||||
'buckets' => $dbForInternal->find('buckets', $queries, $limit, $offset, ['_id'], [$orderType]),
|
||||
'sum' => $dbForInternal->count('buckets', $queries, APP_LIMIT_COUNT),
|
||||
]), Response::MODEL_BUCKET_LIST);
|
||||
});
|
||||
|
||||
|
|
6
composer.lock
generated
6
composer.lock
generated
|
@ -1704,7 +1704,7 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/lohanidamodar/audit",
|
||||
"reference": "b3ca9fa928fdec8c966596cbd85ee1141c79b6eb"
|
||||
"reference": "d5591321161b81043c45be3c53ce9dcfa2d81d72"
|
||||
},
|
||||
"require": {
|
||||
"ext-pdo": "*",
|
||||
|
@ -1738,7 +1738,7 @@
|
|||
"upf",
|
||||
"utopia"
|
||||
],
|
||||
"time": "2021-06-13T07:41:15+00:00"
|
||||
"time": "2021-06-14T07:38:18+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/cache",
|
||||
|
@ -6195,5 +6195,5 @@
|
|||
"platform-overrides": {
|
||||
"php": "8.0"
|
||||
},
|
||||
"plugin-api-version": "2.0.0"
|
||||
"plugin-api-version": "2.1.0"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue