From 0fc872bd45ffb6dd17c09ae2eb51a7b0fcebcb14 Mon Sep 17 00:00:00 2001 From: Jake Rosenberg Date: Mon, 13 Nov 2023 08:58:52 -0600 Subject: [PATCH] task/DES-2610: Fix undefined DOI being logged with copy and other operations (#1124) * Fix undefined doi being logged with copy and other operations * only pass DOI if it exists --------- Co-authored-by: Jake Rosenberg --- .../data-depot-listing.component.js | 1 + .../data-depot-toolbar.component.js | 3 ++- .../published/published-view.component.js | 1 + .../data-browser-service-copy.component.js | 1 + .../data-browser-service-preview.component.js | 2 +- .../templates/prj-pub-collections-template.html | 12 ++++++++---- .../services/file-operation-service.js | 13 ++++++++----- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/designsafe/static/scripts/data-depot/components/data-depot-listing/data-depot-listing.component.js b/designsafe/static/scripts/data-depot/components/data-depot-listing/data-depot-listing.component.js index 85b77c9ae8..40f82e211f 100644 --- a/designsafe/static/scripts/data-depot/components/data-depot-listing/data-depot-listing.component.js +++ b/designsafe/static/scripts/data-depot/components/data-depot-listing/data-depot-listing.component.js @@ -246,6 +246,7 @@ class FilesListingCtrl { browse($event, file) { $event.preventDefault(); $event.stopPropagation(); + if (this.doi) file.doi = this.doi; this.onBrowse({ file }); } diff --git a/designsafe/static/scripts/data-depot/components/data-depot-toolbar/data-depot-toolbar.component.js b/designsafe/static/scripts/data-depot/components/data-depot-toolbar/data-depot-toolbar.component.js index d10cca6f00..872cc40c49 100644 --- a/designsafe/static/scripts/data-depot/components/data-depot-toolbar/data-depot-toolbar.component.js +++ b/designsafe/static/scripts/data-depot/components/data-depot-toolbar/data-depot-toolbar.component.js @@ -68,7 +68,8 @@ class DataDepotToolbarCtrl { copy() { const { api, scheme, system, path } = this.FileListingService.listings.main.params; const files = this.getAllSelected(); - this.FileOperationService.openCopyModal({api, scheme, system, path, files}); + const doi = this.FileListingService.currentDOI || this.$stateParams.doi; + this.FileOperationService.openCopyModal({api, scheme, system, path, files, doi}); } move() { const { api, scheme, system, path } = this.FileListingService.listings.main.params; diff --git a/designsafe/static/scripts/data-depot/components/published/published-view.component.js b/designsafe/static/scripts/data-depot/components/published/published-view.component.js index 04fd3adb44..f1720119fe 100644 --- a/designsafe/static/scripts/data-depot/components/published/published-view.component.js +++ b/designsafe/static/scripts/data-depot/components/published/published-view.component.js @@ -641,6 +641,7 @@ class PublishedViewCtrl { } onBrowse(file, doi) { + if (!doi) {doi = file.doi} if (!doi) {doi = this.$stateParams.doi} if (file.type === 'dir') { this.$state.go(this.$state.current.name, { filePath: file.path, query_string: null, doi: doi }); diff --git a/designsafe/static/scripts/ng-designsafe/components/modals/data-browser-service-copy/data-browser-service-copy.component.js b/designsafe/static/scripts/ng-designsafe/components/modals/data-browser-service-copy/data-browser-service-copy.component.js index 5da8644d79..b716422b22 100644 --- a/designsafe/static/scripts/ng-designsafe/components/modals/data-browser-service-copy/data-browser-service-copy.component.js +++ b/designsafe/static/scripts/ng-designsafe/components/modals/data-browser-service-copy/data-browser-service-copy.component.js @@ -118,6 +118,7 @@ class DataBrowserCopyCtrl { destSystem: dest.system, destPath: dest.path, successCallback: this.successCallback, + doi: this.resolve.doi }); } diff --git a/designsafe/static/scripts/ng-designsafe/components/modals/data-browser-service-preview/data-browser-service-preview.component.js b/designsafe/static/scripts/ng-designsafe/components/modals/data-browser-service-preview/data-browser-service-preview.component.js index e00d9846d5..c59d49b900 100644 --- a/designsafe/static/scripts/ng-designsafe/components/modals/data-browser-service-preview/data-browser-service-preview.component.js +++ b/designsafe/static/scripts/ng-designsafe/components/modals/data-browser-service-preview/data-browser-service-preview.component.js @@ -138,7 +138,7 @@ class DataBrowserServicePreviewCtrl { copy() { const { api, scheme, system, path } = this.FileListingService.listings.main.params; const files = [this.resolve.file]; - this.FileOperationService.openCopyModal({ api, scheme, system, path, files }); + this.FileOperationService.openCopyModal({ api, scheme, system, path, files, doi: this.resolve.doi }); } move() { diff --git a/designsafe/static/scripts/ng-designsafe/directives/templates/prj-pub-collections-template.html b/designsafe/static/scripts/ng-designsafe/directives/templates/prj-pub-collections-template.html index c6c5b82592..1937e644f6 100644 --- a/designsafe/static/scripts/ng-designsafe/directives/templates/prj-pub-collections-template.html +++ b/designsafe/static/scripts/ng-designsafe/directives/templates/prj-pub-collections-template.html @@ -71,7 +71,8 @@ published="true" on-scroll="$ctrl.scrollToBottom()" listing="$ctrl.FileListingService.listings[collection.uuid]" - on-browse="$ctrl.onBrowse(file)">  + on-browse="$ctrl.onBrowse(file)" + doi="mission.doi">  @@ -206,7 +207,8 @@ published="true" on-scroll="$ctrl.scrollToBottom()" listing="$ctrl.FileListingService.listings[collection.uuid]" - on-browse="$ctrl.onBrowse(file)">  + on-browse="$ctrl.onBrowse(file)" + doi="mission.doi">  @@ -299,7 +301,8 @@ published="true" on-scroll="$ctrl.scrollToBottom()" listing="$ctrl.FileListingService.listings[collection.uuid]" - on-browse="$ctrl.onBrowse(file)">  + on-browse="$ctrl.onBrowse(file)" + doi="mission.doi">  @@ -347,7 +350,8 @@ published="true" on-scroll="$ctrl.scrollToBottom()" listing="$ctrl.FileListingService.listings[collection.uuid]" - on-browse="$ctrl.onBrowse(file)">  + on-browse="$ctrl.onBrowse(file)" + doi="mission.doi">  diff --git a/designsafe/static/scripts/ng-designsafe/services/file-operation-service.js b/designsafe/static/scripts/ng-designsafe/services/file-operation-service.js index 28e5a7e191..8098ea3aa0 100644 --- a/designsafe/static/scripts/ng-designsafe/services/file-operation-service.js +++ b/designsafe/static/scripts/ng-designsafe/services/file-operation-service.js @@ -3,7 +3,7 @@ import { map, tap, catchError } from 'rxjs/operators'; import { takeLatestSubscriber } from './_rxjs-utils'; export class FileOperationService { - constructor($http, $state, $rootScope, $uibModal, $q, ProjectService, Django, toastr) { + constructor($http, $state, $stateParams, $rootScope, $uibModal, $q, ProjectService, Django, toastr) { 'ngInject'; this.$state = $state; this.$uibModal = $uibModal; @@ -12,6 +12,7 @@ export class FileOperationService { this.toastr = toastr; this.$rootScope = $rootScope; this.$http = $http; + this.$stateParams = $stateParams; this.ProjectService = ProjectService; this.from = from; // bind rxjs method for mocking @@ -125,7 +126,7 @@ export class FileOperationService { * @param {string} params.system System to copy files from. * @param {Object[]} params.files Array of file objects {name, system, path} to copy. */ - openCopyModal({ api, scheme, system, files }) { + openCopyModal({ api, scheme, system, files, doi }) { this.operations.copy.status = {}; var modal = this.$uibModal.open({ component: 'copyModal', @@ -134,6 +135,7 @@ export class FileOperationService { scheme: () => scheme, system: () => system, files: () => files, + doi: () => doi, }, size: 'lg', }); @@ -154,7 +156,7 @@ export class FileOperationService { * @param {string} params.destPath Path of directory to copy files into. * @param {function} params.successCallback Callback on successful copy of all files. */ - handleCopy({ srcApi, srcFiles, destApi, destSystem, destPath, successCallback }) { + handleCopy({ srcApi, srcFiles, destApi, destSystem, destPath, successCallback, doi}) { const copyParams = { srcApi, srcFiles, @@ -162,6 +164,7 @@ export class FileOperationService { destSystem, destPath, successCallback, + doi, }; const copyMapping = () => this.mapParamsToCopy(copyParams); @@ -180,7 +183,7 @@ export class FileOperationService { * @param {Object[]} params.files Array of file objects {name, system, path} to copy. * @param {function} params.successCallback Callback on successful copy of all files. */ - mapParamsToCopy({ srcApi, destApi, destSystem, destPath, srcFiles, successCallback }) { + mapParamsToCopy({ srcApi, destApi, destSystem, destPath, srcFiles, successCallback, doi }) { // Treat Shared Data as Agave for the purpose of copying files. if (srcApi === 'shared') { srcApi = 'agave'; @@ -193,7 +196,7 @@ export class FileOperationService { // Copying files between APIs requires the transfer endpoint. if (srcApi === destApi) { const copyUrl = this.removeDuplicateSlashes( - `/api/datafiles/${srcApi}/private/copy/${f.system}/${f.path}/` + `/api/datafiles/${srcApi}/private/copy/${f.system}/${f.path}/?doi=${doi}` ); copyRequest = this.$http.put(copyUrl, { dest_system: destSystem,