1
0
Fork 0
mirror of synced 2024-10-01 01:37:56 +13:00

Merge branch 'feat-storage-buckets' into feat-sb-uis

This commit is contained in:
Damodar Lohani 2021-11-19 15:49:10 +05:45
commit 7147a7dc6f
3 changed files with 45 additions and 18 deletions

View file

@ -513,7 +513,8 @@ App::post('/v1/storage/buckets/:bucketId/files')
->inject('user')
->inject('audits')
->inject('usage')
->action(function ($bucketId, $fileId, $file, $read, $write, $request, $response, $dbForInternal, $dbForExternal, $user, $audits, $usage) {
->inject('mode')
->action(function ($bucketId, $fileId, $file, $read, $write, $request, $response, $dbForInternal, $dbForExternal, $user, $audits, $usage, $mode) {
/** @var Utopia\Swoole\Request $request */
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
@ -524,7 +525,8 @@ App::post('/v1/storage/buckets/:bucketId/files')
$bucket = $dbForInternal->getDocument('buckets', $bucketId);
if($bucket->isEmpty()) {
if($bucket->isEmpty()
|| (!$bucket->getAttribute('enabled') && $mode !== APP_MODE_ADMIN )) {
throw new Exception('Bucket not found', 404);
}
@ -697,7 +699,8 @@ App::get('/v1/storage/buckets/:bucketId/files')
->inject('dbForInternal')
->inject('dbForExternal')
->inject('usage')
->action(function ($bucketId, $search, $limit, $offset, $cursor, $cursorDirection, $orderType, $response, $dbForInternal, $dbForExternal, $usage) {
->inject('mode')
->action(function ($bucketId, $search, $limit, $offset, $cursor, $cursorDirection, $orderType, $response, $dbForInternal, $dbForExternal, $usage, $mode) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
/** @var Utopia\Database\Database $dbForExternal */
@ -705,7 +708,8 @@ App::get('/v1/storage/buckets/:bucketId/files')
$bucket = $dbForInternal->getDocument('buckets', $bucketId);
if($bucket->isEmpty()) {
if($bucket->isEmpty()
|| (!$bucket->getAttribute('enabled') && $mode !== APP_MODE_ADMIN )) {
throw new Exception('Bucket not found', 404);
}
@ -780,7 +784,8 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId')
->inject('dbForInternal')
->inject('dbForExternal')
->inject('usage')
->action(function ($bucketId, $fileId, $response, $dbForInternal, $dbForExternal, $usage) {
->inject('mode')
->action(function ($bucketId, $fileId, $response, $dbForInternal, $dbForExternal, $usage, $mode) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
/** @var Utopia\Database\Database $dbForExternal */
@ -788,7 +793,8 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId')
$bucket = $dbForInternal->getDocument('buckets', $bucketId);
if($bucket->isEmpty()) {
if($bucket->isEmpty()
|| (!$bucket->getAttribute('enabled') && $mode !== APP_MODE_ADMIN )) {
throw new Exception('Bucket not found', 404);
}
@ -849,7 +855,8 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
->inject('dbForInternal')
->inject('dbForExternal')
->inject('usage')
->action(function ($bucketId, $fileId, $width, $height, $gravity, $quality, $borderWidth, $borderColor, $borderRadius, $opacity, $rotation, $background, $output, $request, $response, $project, $dbForInternal, $dbForExternal, $usage) {
->inject('mode')
->action(function ($bucketId, $fileId, $width, $height, $gravity, $quality, $borderWidth, $borderColor, $borderRadius, $opacity, $rotation, $background, $output, $request, $response, $project, $dbForInternal, $dbForExternal, $usage, $mode) {
/** @var Utopia\Swoole\Request $request */
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Document $project */
@ -868,7 +875,8 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
}
$bucket = $dbForInternal->getDocument('buckets', $bucketId);
if($bucket->isEmpty()) {
if($bucket->isEmpty()
|| (!$bucket->getAttribute('enabled') && $mode !== APP_MODE_ADMIN )) {
throw new Exception('Bucket not found', 404);
}
@ -1020,7 +1028,8 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download')
->inject('dbForInternal')
->inject('dbForExternal')
->inject('usage')
->action(function ($bucketId, $fileId, $response, $dbForInternal, $dbForExternal, $usage) {
->inject('mode')
->action(function ($bucketId, $fileId, $response, $dbForInternal, $dbForExternal, $usage, $mode) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
/** @var Utopia\Database\Database $dbForExternal */
@ -1028,7 +1037,8 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download')
$bucket = $dbForInternal->getDocument('buckets', $bucketId);
if($bucket->isEmpty()) {
if($bucket->isEmpty()
|| (!$bucket->getAttribute('enabled') && $mode !== APP_MODE_ADMIN )) {
throw new Exception('Bucket not found', 404);
}
@ -1109,14 +1119,16 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/view')
->inject('dbForInternal')
->inject('dbForExternal')
->inject('usage')
->action(function ($bucketId, $fileId, $response, $dbForInternal, $dbForExternal, $usage) {
->inject('mode')
->action(function ($bucketId, $fileId, $response, $dbForInternal, $dbForExternal, $usage, $mode) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
/** @var Appwrite\Stats\Stats $usage */
$bucket = $dbForInternal->getDocument('buckets', $bucketId);
if($bucket->isEmpty()) {
if($bucket->isEmpty()
|| (!$bucket->getAttribute('enabled') && $mode !== APP_MODE_ADMIN )) {
throw new Exception('Bucket not found', 404);
}
@ -1211,7 +1223,8 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId')
->inject('dbForExternal')
->inject('audits')
->inject('usage')
->action(function ($bucketId, $fileId, $read, $write, $response, $dbForInternal, $dbForExternal, $audits, $usage) {
->inject('mode')
->action(function ($bucketId, $fileId, $read, $write, $response, $dbForInternal, $dbForExternal, $audits, $usage, $mode) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
/** @var Appwrite\Event\Event $audits */
@ -1219,7 +1232,8 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId')
$bucket = $dbForInternal->getDocument('buckets', $bucketId);
if($bucket->isEmpty()) {
if($bucket->isEmpty()
|| (!$bucket->getAttribute('enabled') && $mode !== APP_MODE_ADMIN )) {
throw new Exception('Bucket not found', 404);
}
@ -1290,7 +1304,8 @@ App::delete('/v1/storage/buckets/:bucketId/files/:fileId')
->inject('events')
->inject('audits')
->inject('usage')
->action(function ($bucketId, $fileId, $response, $dbForInternal, $dbForExternal, $events, $audits, $usage) {
->inject('mode')
->action(function ($bucketId, $fileId, $response, $dbForInternal, $dbForExternal, $events, $audits, $usage, $mode) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
/** @var Utopia\Database\Database $dbForExternal */
@ -1300,7 +1315,8 @@ App::delete('/v1/storage/buckets/:bucketId/files/:fileId')
$bucket = $dbForInternal->getDocument('buckets', $bucketId);
if($bucket->isEmpty()) {
if($bucket->isEmpty()
|| (!$bucket->getAttribute('enabled') && $mode !== APP_MODE_ADMIN )) {
throw new Exception('Bucket not found', 404);
}

View file

@ -410,7 +410,7 @@ class DeletesV1 extends Worker
$this->deleteByGroup('files',[
new Query('bucketId', Query::TYPE_EQUAL, [$bucketId])
], $this->getInternalDB($projectId));
], $this->getExternalDB($projectId));
$device = new Local(APP_STORAGE_UPLOADS.'/app-'.$projectId);
$device->deletePath($device->getRoot() . DIRECTORY_SEPARATOR . $bucketId);

View file

@ -347,6 +347,17 @@ trait WebhooksBase
*/
public function testCreateBucketFile(array $data): array
{
//enable bucket
$bucket = $this->client->call(Client::METHOD_PUT, '/storage/buckets/' . $data['bucketId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'name' => 'Test Bucket Updated',
'enabled' => true,
]);
$this->assertEquals($bucket['headers']['status-code'], 200);
/**
* Test for SUCCESS
*/
@ -498,7 +509,7 @@ trait WebhooksBase
$this->assertEquals(empty($webhook['headers']['X-Appwrite-Webhook-User-Id'] ?? ''), true);
$this->assertNotEmpty($webhook['data']['$id']);
$this->assertEquals('Test Bucket Updated', $webhook['data']['name']);
$this->assertEquals(false, $webhook['data']['enabled']);
$this->assertEquals(true, $webhook['data']['enabled']);
$this->assertIsArray($webhook['data']['$read']);
$this->assertIsArray($webhook['data']['$write']);
}