Updated file update form

This commit is contained in:
eldadfux
2019-08-28 15:29:45 +03:00
parent 07b3929f26
commit 2e590007be
5 changed files with 75 additions and 4 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
<?php
const VERSION = '0.1.9';
const VERSION = 'latest';
return VERSION;
+35
View File
@@ -521,6 +521,41 @@ $utopia->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')
+1 -1
View File
@@ -44,7 +44,7 @@ use Utopia\Locale\Locale;
<label for="name">Name</label>
<input name="name" id="name" type="text" autocomplete="off" data-ls-bind="{{console-project.name}}" data-forms-text-direction required>
<label for="name">Project ID</label>
<label for="name">Project UID</label>
<div class="input-copy">
<input data-forms-copy type="text" disabled data-ls-bind="{{console-project.$uid}}" />
</div>
+37 -1
View File
@@ -98,7 +98,43 @@ use Utopia\Locale\Locale;
<img src="" data-ls-attrs="src=//{{env.DOMAIN}}/v1/storage/files/{{file.$uid}}/preview?width=45&height=45&project={{router.params.project}}&mode=admin" class="pull-start avatar" loading="lazy" width="30" height="30" />
</td>
<td data-title="Name: ">
<small data-ls-bind="{{file.name}}"></small>
<div data-ui-modal class="box modal close" data-button-text="{{file.name}}" data-button-class="link">
<button type="button" class="close pull-end" data-ui-modal-close=""><i class="icon-cancel"></i></button>
<h1>Update File</h1>
<form
data-service="storage.updateFile"
data-event="submit"
data-scope="sdk"
data-success="alert,trigger"
data-success-param-alert-text="File uploaded successfully"
data-success-param-trigger-events="file-update,modal-close"
data-failure="alert"
data-failure-param-alert-text="Failed to upload file"
data-failure-param-alert-classname="error">
<label for="files-uid">File UID</label>
<div class="input-copy">
<input data-forms-copy type="text" id="files-uid" disabled data-ls-bind="{{file.$uid}}" />
</div>
<input type="hidden" name="folderId" id="files-folderId" data-cast-to="int" value="1">
<label for="file-read">Read Permissions</label>
<input type="hidden" id="file-read" name="read" required data-forms-tags data-cast-to="json" data-ls-bind="{{file.$permissions.read}}" />
<label for="file-write">Write Permissions</label>
<input type="hidden" id="file-write" name="write" required data-forms-tags data-cast-to="json" data-ls-bind="{{file.$permissions.write}}" />
<hr />
<div class="pull-end">
<a href="" data-ls-attrs="href=//{{env.DOMAIN}}/v1/storage/files/{{file.$uid}}/preview?project={{router.params.project}}&mode=admin" target="_blank">Open preview in new window <i class="icon-link-ext"></i></a>
</div>
<button type="submit">Update</button> &nbsp; <button data-ui-modal-close="" type="button" class="reverse">Cancel</button>
</form>
</div>
</td>
<td data-title="Type: ">
<span data-ls-bind="{{file.mimeType}}" class="tag"></span>
+1 -1
View File
@@ -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;