Merge branch '0.13.x' of https://github.com/appwrite/appwrite into feat-permissions-improvements
This commit is contained in:
commit
f37203a18e
2 changed files with 51 additions and 50 deletions
|
@ -99,8 +99,6 @@ App::post('/v1/storage/buckets')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbForProject->createCollection('bucket_' . $bucketId, $attributes, $indexes);
|
|
||||||
|
|
||||||
$bucket = $dbForProject->createDocument('buckets', new Document([
|
$bucket = $dbForProject->createDocument('buckets', new Document([
|
||||||
'$id' => $bucketId,
|
'$id' => $bucketId,
|
||||||
'$collection' => 'buckets',
|
'$collection' => 'buckets',
|
||||||
|
@ -117,6 +115,10 @@ App::post('/v1/storage/buckets')
|
||||||
'$write' => $write ?? [],
|
'$write' => $write ?? [],
|
||||||
'search' => implode(' ', [$bucketId, $name]),
|
'search' => implode(' ', [$bucketId, $name]),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
$bucket = $dbForProject->getDocument('buckets', $bucketId);
|
||||||
|
|
||||||
|
$dbForProject->createCollection('bucket_' . $bucket->getInternalId(), $attributes, $indexes);
|
||||||
} catch (Duplicate $th) {
|
} catch (Duplicate $th) {
|
||||||
throw new Exception('Bucket already exists', 409, Exception::STORAGE_BUCKET_ALREADY_EXISTS);
|
throw new Exception('Bucket already exists', 409, Exception::STORAGE_BUCKET_ALREADY_EXISTS);
|
||||||
}
|
}
|
||||||
|
@ -483,11 +485,11 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
||||||
$path = str_ireplace($deviceFiles->getRoot(), $deviceFiles->getRoot() . DIRECTORY_SEPARATOR . $bucket->getId(), $path); // Add bucket id to path after root
|
$path = str_ireplace($deviceFiles->getRoot(), $deviceFiles->getRoot() . DIRECTORY_SEPARATOR . $bucket->getId(), $path); // Add bucket id to path after root
|
||||||
|
|
||||||
if ($permissionBucket) {
|
if ($permissionBucket) {
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $bucketId, $fileId) {
|
$file = Authorization::skip(function () use ($dbForProject, $bucket, $fileId) {
|
||||||
return $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
return $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
$file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$metadata = ['content_type' => $deviceLocal->getFileMimeType($fileTmpName)];
|
$metadata = ['content_type' => $deviceLocal->getFileMimeType($fileTmpName)];
|
||||||
|
@ -579,11 +581,11 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
||||||
'metadata' => $metadata,
|
'metadata' => $metadata,
|
||||||
]);
|
]);
|
||||||
if ($permissionBucket) {
|
if ($permissionBucket) {
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $bucketId, $doc) {
|
$file = Authorization::skip(function () use ($dbForProject, $bucket, $doc) {
|
||||||
return $dbForProject->createDocument('bucket_' . $bucketId, $doc);
|
return $dbForProject->createDocument('bucket_' . $bucket->getInternalId(), $doc);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->createDocument('bucket_' . $bucketId, $doc);
|
$file = $dbForProject->createDocument('bucket_' . $bucket->getInternalId(), $doc);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$file = $file
|
$file = $file
|
||||||
|
@ -601,11 +603,11 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
||||||
->setAttribute('chunksUploaded', $chunksUploaded);
|
->setAttribute('chunksUploaded', $chunksUploaded);
|
||||||
|
|
||||||
if ($permissionBucket) {
|
if ($permissionBucket) {
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $bucketId, $fileId, $file) {
|
$file = Authorization::skip(function () use ($dbForProject, $bucket, $fileId, $file) {
|
||||||
return $dbForProject->updateDocument('bucket_' . $bucketId, $fileId, $file);
|
return $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->updateDocument('bucket_' . $bucketId, $fileId, $file);
|
$file = $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -649,11 +651,11 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
||||||
'metadata' => $metadata,
|
'metadata' => $metadata,
|
||||||
]);
|
]);
|
||||||
if ($permissionBucket) {
|
if ($permissionBucket) {
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $bucketId, $doc) {
|
$file = Authorization::skip(function () use ($dbForProject, $bucket, $doc) {
|
||||||
return $dbForProject->createDocument('bucket_' . $bucketId, $doc);
|
return $dbForProject->createDocument('bucket_' . $bucket->getInternalId(), $doc);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->createDocument('bucket_' . $bucketId, $doc);
|
$file = $dbForProject->createDocument('bucket_' . $bucket->getInternalId(), $doc);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$file = $file
|
$file = $file
|
||||||
|
@ -661,11 +663,11 @@ App::post('/v1/storage/buckets/:bucketId/files')
|
||||||
->setAttribute('metadata', $metadata);
|
->setAttribute('metadata', $metadata);
|
||||||
|
|
||||||
if ($permissionBucket) {
|
if ($permissionBucket) {
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $bucketId, $fileId, $file) {
|
$file = Authorization::skip(function () use ($dbForProject, $bucket, $fileId, $file) {
|
||||||
return $dbForProject->updateDocument('bucket_' . $bucketId, $fileId, $file);
|
return $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->updateDocument('bucket_' . $bucketId, $fileId, $file);
|
$file = $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (StructureException $exception) {
|
} catch (StructureException $exception) {
|
||||||
|
@ -737,10 +739,10 @@ App::get('/v1/storage/buckets/:bucketId/files')
|
||||||
if (!empty($cursor)) {
|
if (!empty($cursor)) {
|
||||||
if ($bucket->getAttribute('permission') === 'bucket') {
|
if ($bucket->getAttribute('permission') === 'bucket') {
|
||||||
$cursorFile = Authorization::skip(function () use ($dbForProject, $bucket, $cursor) {
|
$cursorFile = Authorization::skip(function () use ($dbForProject, $bucket, $cursor) {
|
||||||
return $dbForProject->getDocument('bucket_' . $bucket->getId(), $cursor);
|
return $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $cursor);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$cursorFile = $dbForProject->getDocument('bucket_' . $bucket->getId(), $cursor);
|
$cursorFile = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cursorFile->isEmpty()) {
|
if ($cursorFile->isEmpty()) {
|
||||||
|
@ -755,11 +757,11 @@ App::get('/v1/storage/buckets/:bucketId/files')
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bucket->getAttribute('permission') === 'bucket') {
|
if ($bucket->getAttribute('permission') === 'bucket') {
|
||||||
$files = Authorization::skip(function () use ($dbForProject, $bucketId, $queries, $limit, $offset, $cursor, $cursorDirection, $orderType) {
|
$files = Authorization::skip(function () use ($dbForProject, $bucket, $queries, $limit, $offset, $cursor, $cursorDirection, $orderType) {
|
||||||
return $dbForProject->find('bucket_' . $bucketId, $queries, $limit, $offset, [], [$orderType], $cursorFile ?? null, $cursorDirection);
|
return $dbForProject->find('bucket_' . $bucket->getInternalId(), $queries, $limit, $offset, [], [$orderType], $cursorFile ?? null, $cursorDirection);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$files = $dbForProject->find('bucket_' . $bucketId, $queries, $limit, $offset, [], [$orderType], $cursorFile ?? null, $cursorDirection);
|
$files = $dbForProject->find('bucket_' . $bucket->getInternalId(), $queries, $limit, $offset, [], [$orderType], $cursorFile ?? null, $cursorDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
$usage
|
$usage
|
||||||
|
@ -769,7 +771,7 @@ App::get('/v1/storage/buckets/:bucketId/files')
|
||||||
|
|
||||||
$response->dynamic(new Document([
|
$response->dynamic(new Document([
|
||||||
'files' => $files,
|
'files' => $files,
|
||||||
'sum' => $dbForProject->count('bucket_' . $bucketId, $queries, APP_LIMIT_COUNT),
|
'sum' => $dbForProject->count('bucket_' . $bucket->getInternalId(), $queries, APP_LIMIT_COUNT),
|
||||||
]), Response::MODEL_FILE_LIST);
|
]), Response::MODEL_FILE_LIST);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -813,11 +815,11 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId')
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bucket->getAttribute('permission') === 'bucket') {
|
if ($bucket->getAttribute('permission') === 'bucket') {
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $bucketId, $fileId) {
|
$file = Authorization::skip(function () use ($dbForProject, $bucket, $fileId) {
|
||||||
return $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
return $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
$file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($file->isEmpty() || $file->getAttribute('bucketId') !== $bucketId) {
|
if ($file->isEmpty() || $file->getAttribute('bucketId') !== $bucketId) {
|
||||||
|
@ -902,11 +904,11 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
|
||||||
|
|
||||||
if ($bucket->getAttribute('permission') === 'bucket') {
|
if ($bucket->getAttribute('permission') === 'bucket') {
|
||||||
// skip authorization
|
// skip authorization
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $bucketId, $fileId) {
|
$file = Authorization::skip(function () use ($dbForProject, $bucket, $fileId) {
|
||||||
return $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
return $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
$file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($file->isEmpty() || $file->getAttribute('bucketId') !== $bucketId) {
|
if ($file->isEmpty() || $file->getAttribute('bucketId') !== $bucketId) {
|
||||||
|
@ -1061,11 +1063,11 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download')
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bucket->getAttribute('permission') === 'bucket') {
|
if ($bucket->getAttribute('permission') === 'bucket') {
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $fileId, $bucketId) {
|
$file = Authorization::skip(function () use ($dbForProject, $fileId, $bucket) {
|
||||||
return $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
return $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
$file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($file->isEmpty() || $file->getAttribute('bucketId') !== $bucketId) {
|
if ($file->isEmpty() || $file->getAttribute('bucketId') !== $bucketId) {
|
||||||
|
@ -1206,11 +1208,11 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/view')
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bucket->getAttribute('permission') === 'bucket') {
|
if ($bucket->getAttribute('permission') === 'bucket') {
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $fileId, $bucketId) {
|
$file = Authorization::skip(function () use ($dbForProject, $fileId, $bucket) {
|
||||||
return $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
return $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
$file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$mimes = Config::getParam('storage-mimes');
|
$mimes = Config::getParam('storage-mimes');
|
||||||
|
@ -1387,11 +1389,11 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId')
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bucket->getAttribute('permission') === 'bucket') {
|
if ($bucket->getAttribute('permission') === 'bucket') {
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $fileId, $bucketId) {
|
$file = Authorization::skip(function () use ($dbForProject, $fileId, $bucket) {
|
||||||
return $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
return $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
$file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($file->isEmpty() || $file->getAttribute('bucketId') !== $bucketId) {
|
if ($file->isEmpty() || $file->getAttribute('bucketId') !== $bucketId) {
|
||||||
|
@ -1399,14 +1401,14 @@ App::put('/v1/storage/buckets/:bucketId/files/:fileId')
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bucket->getAttribute('permission') === 'bucket') {
|
if ($bucket->getAttribute('permission') === 'bucket') {
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $fileId, $bucketId, $file, $read, $write) {
|
$file = Authorization::skip(function () use ($dbForProject, $fileId, $bucket, $file, $read, $write) {
|
||||||
return $dbForProject->updateDocument('bucket_' . $bucketId, $fileId, $file
|
return $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file
|
||||||
->setAttribute('$read', $read)
|
->setAttribute('$read', $read)
|
||||||
->setAttribute('$write', $write)
|
->setAttribute('$write', $write)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->updateDocument('bucket_' . $bucketId, $fileId, $file
|
$file = $dbForProject->updateDocument('bucket_' . $bucket->getInternalId(), $fileId, $file
|
||||||
->setAttribute('$read', $read)
|
->setAttribute('$read', $read)
|
||||||
->setAttribute('$write', $write)
|
->setAttribute('$write', $write)
|
||||||
);
|
);
|
||||||
|
@ -1475,11 +1477,11 @@ App::delete('/v1/storage/buckets/:bucketId/files/:fileId')
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bucket->getAttribute('permission') === 'bucket') {
|
if ($bucket->getAttribute('permission') === 'bucket') {
|
||||||
$file = Authorization::skip(function () use ($dbForProject, $fileId, $bucketId) {
|
$file = Authorization::skip(function () use ($dbForProject, $fileId, $bucket) {
|
||||||
return $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
return $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$file = $dbForProject->getDocument('bucket_' . $bucketId, $fileId);
|
$file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($file->isEmpty() || $file->getAttribute('bucketId') !== $bucketId) {
|
if ($file->isEmpty() || $file->getAttribute('bucketId') !== $bucketId) {
|
||||||
|
@ -1503,11 +1505,11 @@ App::delete('/v1/storage/buckets/:bucketId/files/:fileId')
|
||||||
$deviceLocal->delete($cacheDir, true);
|
$deviceLocal->delete($cacheDir, true);
|
||||||
|
|
||||||
if ($bucket->getAttribute('permission') === 'bucket') {
|
if ($bucket->getAttribute('permission') === 'bucket') {
|
||||||
$deleted = Authorization::skip(function () use ($dbForProject, $fileId, $bucketId) {
|
$deleted = Authorization::skip(function () use ($dbForProject, $fileId, $bucket) {
|
||||||
return $dbForProject->deleteDocument('bucket_' . $bucketId, $fileId);
|
return $dbForProject->deleteDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$deleted = $dbForProject->deleteDocument('bucket_' . $bucketId, $fileId);
|
$deleted = $dbForProject->deleteDocument('bucket_' . $bucket->getInternalId(), $fileId);
|
||||||
}
|
}
|
||||||
if (!$deleted) {
|
if (!$deleted) {
|
||||||
throw new Exception('Failed to remove file from DB', 500, Exception::GENERAL_SERVER_ERROR);
|
throw new Exception('Failed to remove file from DB', 500, Exception::GENERAL_SERVER_ERROR);
|
||||||
|
|
|
@ -458,9 +458,8 @@ class DeletesV1 extends Worker
|
||||||
|
|
||||||
protected function deleteBucket(Document $document, string $projectId)
|
protected function deleteBucket(Document $document, string $projectId)
|
||||||
{
|
{
|
||||||
$bucketId = $document->getId();
|
|
||||||
$dbForProject = $this->getProjectDB($projectId);
|
$dbForProject = $this->getProjectDB($projectId);
|
||||||
$dbForProject->deleteCollection('bucket_' . $bucketId);
|
$dbForProject->deleteCollection('bucket_' . $document->getInternalId());
|
||||||
|
|
||||||
$device = new Local(APP_STORAGE_UPLOADS.'/app-'.$projectId);
|
$device = new Local(APP_STORAGE_UPLOADS.'/app-'.$projectId);
|
||||||
|
|
||||||
|
@ -483,6 +482,6 @@ class DeletesV1 extends Worker
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$device->deletePath($bucketId);
|
$device->deletePath($document->getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue