From 2e590007be61c74d4b6eff68eb7e8822d2f0d09b Mon Sep 17 00:00:00 2001 From: eldadfux Date: Wed, 28 Aug 2019 15:29:45 +0300 Subject: [PATCH] Updated file update form --- app/config/version.php | 2 +- app/controllers/storage.php | 35 ++++++++++++++++++++++++ app/views/console/settings/index.phtml | 2 +- app/views/console/storage/index.phtml | 38 +++++++++++++++++++++++++- public/styles/scopes/console.less | 2 +- 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/app/config/version.php b/app/config/version.php index 321c779fb0..1b8fe0cf2f 100644 --- a/app/config/version.php +++ b/app/config/version.php @@ -1,4 +1,4 @@ post('/v1/storage/files') } ); +$utopia->put('/v1/storage/files/:fileId') + ->desc('Update File') + ->label('scope', 'files.write') + ->label('sdk.namespace', 'storage') + ->label('sdk.method', 'updateFile') + ->label('sdk.description', 'Update file by its unique ID. Only users with write permissions have access to update this resource.') + ->param('fileId', '', function () {return new UID();}, 'File unique ID.') + ->param('read', [], function () {return new ArrayList(new Text(64));}, 'An array of read permissions. [Learn more about permissions and roles](/docs/permissions).', true) + ->param('write', [], function () {return new ArrayList(new Text(64));}, 'An array of write permissions. [Learn more about permissions and roles](/docs/permissions).', true) + ->param('folderId', '', function () {return new UID();}, 'Folder to associate files with.', true) + ->action( + function($fileId, $read, $write, $folderId) use ($response, $projectDB) + { + $file = $projectDB->getDocument($fileId); + + if(empty($file->getUid()) || Database::SYSTEM_COLLECTION_FILES != $file->getCollection()) { + throw new Exception('File not found', 404); + } + + $file = $projectDB->updateDocument(array_merge($file->getArrayCopy(), [ + '$permissions' => [ + 'read' => $read, + 'write' => $write, + ], + 'folderId' => $folderId, + ])); + + if(false === $file) { + throw new Exception('Failed saving file to DB', 500); + } + + $response->json($file->getArrayCopy()); + } + ); + $utopia->delete('/v1/storage/files/:fileId') ->desc('Delete File') ->label('scope', 'files.write') diff --git a/app/views/console/settings/index.phtml b/app/views/console/settings/index.phtml index 4e9ace0a48..40fdfabe30 100644 --- a/app/views/console/settings/index.phtml +++ b/app/views/console/settings/index.phtml @@ -44,7 +44,7 @@ use Utopia\Locale\Locale; - +
diff --git a/app/views/console/storage/index.phtml b/app/views/console/storage/index.phtml index 77c6ffaac9..2240a9abab 100644 --- a/app/views/console/storage/index.phtml +++ b/app/views/console/storage/index.phtml @@ -98,7 +98,43 @@ use Utopia\Locale\Locale; - + diff --git a/public/styles/scopes/console.less b/public/styles/scopes/console.less index 9ddc9353cc..3b38691f95 100644 --- a/public/styles/scopes/console.less +++ b/public/styles/scopes/console.less @@ -610,7 +610,7 @@ background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%, #d6249f 60%, #285AEB 90%); } } - + .premium { z-index: 3; margin-top: 320px;