This is an automated email from the ASF dual-hosted git repository. machristie pushed a commit to branch AIRAVATA-3682 in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
commit 8fe3e7ac4b650be9a00840864a45bede707eb395 Author: Marcus Christie <[email protected]> AuthorDate: Tue Feb 21 16:36:43 2023 -0500 AIRAVATA-3682 Make text editor readonly when file is in shared dir --- django_airavata/apps/api/serializers.py | 14 ++++++++++++++ .../static/django_airavata_api/js/models/DataProduct.js | 1 + .../storage/storage-edit/UserStorageTextEditViewer.vue | 17 ++++++++++++++--- .../js/containers/UserStorageContainer.vue | 1 + 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/django_airavata/apps/api/serializers.py b/django_airavata/apps/api/serializers.py index 030b4a8b..618075f2 100644 --- a/django_airavata/apps/api/serializers.py +++ b/django_airavata/apps/api/serializers.py @@ -549,6 +549,7 @@ class DataProductSerializer( downloadURL = serializers.SerializerMethodField() isInputFileUpload = serializers.SerializerMethodField() filesize = serializers.SerializerMethodField() + userHasWriteAccess = serializers.SerializerMethodField() def get_downloadURL(self, data_product): """Getter for downloadURL field. Returns None if file is not available.""" @@ -572,6 +573,19 @@ class DataProductSerializer( else: return 0 + def get_userHasWriteAccess(self, data_product: DataProductModel): + request = self.context['request'] + file_metadata = user_storage.get_data_product_metadata(request, data_product_uri=data_product.productUri) + if "userHasWriteAccess" in file_metadata: + return file_metadata["userHasWriteAccess"] + else: + path = file_metadata["path"] + shared_path = view_utils.is_shared_path(path) + if shared_path: + # Only admins can edit files/directories in a shared directory + return request.is_gateway_admin + return True + # TODO move this into airavata_sdk? class FullExperiment: diff --git a/django_airavata/apps/api/static/django_airavata_api/js/models/DataProduct.js b/django_airavata/apps/api/static/django_airavata_api/js/models/DataProduct.js index 34c1e143..507d5bdb 100644 --- a/django_airavata/apps/api/static/django_airavata_api/js/models/DataProduct.js +++ b/django_airavata/apps/api/static/django_airavata_api/js/models/DataProduct.js @@ -29,6 +29,7 @@ const FIELDS = [ "downloadURL", "isInputFileUpload", "filesize", + "userHasWriteAccess", ]; const FILENAME_REGEX = /[^/]+$/; diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/storage-edit/UserStorageTextEditViewer.vue b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/storage-edit/UserStorageTextEditViewer.vue index a78a528e..aa8ff0c1 100644 --- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/storage-edit/UserStorageTextEditViewer.vue +++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/components/storage/storage-edit/UserStorageTextEditViewer.vue @@ -2,8 +2,12 @@ <div> <div class="user-storage-file-edit-viewer-status"> <div class="user-storage-file-edit-viewer-status-message"> - <span v-if="editAvailable && saved">All the changes are saved.</span> - <span v-if="editAvailable && !saved">Changes are not saved.</span> + <span v-if="editAvailable && !readOnly && saved" + >All the changes are saved.</span + > + <span v-if="editAvailable && !readOnly && !saved" + >Changes are not saved.</span + > </div> <div class="user-storage-file-edit-viewer-status-actions"> <user-storage-download-button @@ -11,7 +15,7 @@ :file-name="fileName" /> <b-button - v-if="editAvailable" + v-if="editAvailable && !readOnly" :disabled="saved" @click="fileContentChanged" >Save</b-button @@ -76,6 +80,12 @@ export default { editAvailable() { return !this.dataProduct || this.dataProduct.filesize < MAX_EDIT_FILESIZE; }, + userHasWriteAccess() { + return this.dataProduct && this.dataProduct.userHasWriteAccess; + }, + readOnly() { + return !this.userHasWriteAccess; + }, }, methods: { fileContentChanged() { @@ -124,6 +134,7 @@ export default { scrollbarStyle: "native", extraKeys: { "Ctrl-Space": "autocomplete" }, value: value, + readOnly: this.readOnly, }); this.editor.on("change", () => { this.saved = false; diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/UserStorageContainer.vue b/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/UserStorageContainer.vue index bd0e83da..919e0ab6 100644 --- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/UserStorageContainer.vue +++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/containers/UserStorageContainer.vue @@ -87,6 +87,7 @@ export default { mimeType: dataProduct.productMetadata["mime-type"], name: dataProduct.productName, size: dataProduct.productSize, + userHasWriteAccess: dataProduct.userHasWriteAccess, }, ], parts: [],
