Skip to content

Commit

Permalink
the public url is now passed as query parameters to the third party app
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'local/Third-Party-Apps' into Third-Party-Apps
  • Loading branch information
Konrad1991 committed Jan 2, 2024
2 parents 63a3ee2 + faf6f62 commit a38559d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/api/chemotion/third_party_app_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -74,6 +75,7 @@ export default class ResearchPlanDetailsAttachments extends Component {
this.getThirdPartyAppName();
this.getCurrentUser();
this.initThirdPartyAppIPList();
this.initPublicURL();
}

componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -192,6 +194,15 @@ export default class ResearchPlanDetailsAttachments extends Component {
});
}

initPublicURL() {
ThirdPartyAppFetcher.fetchPublicURL()
.then((result) => {
this.setState({
publicURL: result
})
});
}

renderThirdPartyAppList(attachment) {

return (
Expand Down Expand Up @@ -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');
}

Expand Down
10 changes: 9 additions & 1 deletion app/packs/src/fetchers/ThirdPartyAppFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -127,4 +135,4 @@ export default class ThirdPartyAppFetcher {
.catch((errorMessage) => { console.log(errorMessage); });
}

}
}

0 comments on commit a38559d

Please sign in to comment.