From faf6f6257fd3d5b1db7fc1c5a1e7046f10b56758 Mon Sep 17 00:00:00 2001 From: Konrad1991 Date: Tue, 2 Jan 2024 09:56:30 +0100 Subject: [PATCH] the public url of the ELN is send now as query parameter to third party apps. The third party app uses this ip address to make get and post request --- app/api/chemotion/third_party_app_api.rb | 5 +++++ .../ResearchPlanDetailsAttachments.js | 13 ++++++++++++- app/packs/src/fetchers/ThirdPartyAppFetcher.js | 10 +++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/api/chemotion/third_party_app_api.rb b/app/api/chemotion/third_party_app_api.rb index 534b75b2c3..b6d2885c82 100644 --- a/app/api/chemotion/third_party_app_api.rb +++ b/app/api/chemotion/third_party_app_api.rb @@ -203,6 +203,11 @@ def cache_key_for_encoded_token(payload) { error: error_msg } end + desc 'get public ip address of ELN' + get 'public_IP' do + uri = URI.parse(ENV['PUBLIC_URL'] || 'http://localhost:3000') + end + desc 'create token for use in download public_api' params do requires :attID, type: String, desc: 'Attachment ID' diff --git a/app/packs/src/apps/mydb/elements/details/researchPlans/attachmentsTab/ResearchPlanDetailsAttachments.js b/app/packs/src/apps/mydb/elements/details/researchPlans/attachmentsTab/ResearchPlanDetailsAttachments.js index 1b12812ebf..31a23168e9 100644 --- a/app/packs/src/apps/mydb/elements/details/researchPlans/attachmentsTab/ResearchPlanDetailsAttachments.js +++ b/app/packs/src/apps/mydb/elements/details/researchPlans/attachmentsTab/ResearchPlanDetailsAttachments.js @@ -62,6 +62,7 @@ export default class ResearchPlanDetailsAttachments extends Component { updateDropDownThirdPartyApps: false, currentUser: '', attachmentToken: '', + publicURL: '', }; this.editorInitial = this.editorInitial.bind(this); this.createAttachmentPreviews = this.createAttachmentPreviews.bind(this); @@ -74,6 +75,7 @@ export default class ResearchPlanDetailsAttachments extends Component { this.getThirdPartyAppName(); this.getCurrentUser(); this.initThirdPartyAppIPList(); + this.initPublicURL(); } componentDidUpdate(prevProps) { @@ -192,6 +194,15 @@ export default class ResearchPlanDetailsAttachments extends Component { }); } + initPublicURL() { + ThirdPartyAppFetcher.fetchPublicURL() + .then((result) => { + this.setState({ + publicURL: result + }) + }); + } + renderThirdPartyAppList(attachment) { return ( @@ -295,7 +306,7 @@ export default class ResearchPlanDetailsAttachments extends Component { }; NotificationActions.add(notification); } else { - const url = `${ip.obj}?token=${this.state.attachmentToken}`; + const url = `${ip.obj}?token=${this.state.attachmentToken}&url=${this.state.publicURL}`; window.open(url, '_blank'); } diff --git a/app/packs/src/fetchers/ThirdPartyAppFetcher.js b/app/packs/src/fetchers/ThirdPartyAppFetcher.js index 4804ee43c3..6a65663e9f 100644 --- a/app/packs/src/fetchers/ThirdPartyAppFetcher.js +++ b/app/packs/src/fetchers/ThirdPartyAppFetcher.js @@ -116,6 +116,14 @@ export default class ThirdPartyAppFetcher { .catch((errorMessage) => { console.log(errorMessage); }); } + static fetchPublicURL() { + return fetch('/api/v1/third_party_apps/public_IP.json', { + credentials: 'same-origin' + }).then(response => response.json()) + .then(json => json) + .catch((errorMessage) => { console.log(errorMessage); }); + } + static fetchAttachmentToken(attID, userID, nameThirdPartyApp) { const obj = { attID, userID, nameThirdPartyApp }; const queryParams = new URLSearchParams(obj).toString(); @@ -127,4 +135,4 @@ export default class ThirdPartyAppFetcher { .catch((errorMessage) => { console.log(errorMessage); }); } -} \ No newline at end of file +}