From 5a24e9d7d6b9f54306221845fa185ae82dc35ac1 Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Fri, 26 Apr 2019 16:34:22 -0400 Subject: [PATCH 1/2] change studios for project API request to use admin status, owner status and token --- src/redux/preview.js | 5 +++-- src/views/preview/project-view.jsx | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/redux/preview.js b/src/redux/preview.js index 0a3eb2a5d..4fbf21241 100644 --- a/src/redux/preview.js +++ b/src/redux/preview.js @@ -763,10 +763,11 @@ module.exports.getRemixes = id => (dispatch => { }); }); -module.exports.getProjectStudios = id => (dispatch => { +module.exports.getProjectStudios = (id, ownerUsername, isAdmin, token) => (dispatch => { dispatch(module.exports.setFetchStatus('projectStudios', module.exports.Status.FETCHING)); api({ - uri: `/projects/${id}/studios` + uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${id}/studios`, + authentication: token }, (err, body, res) => { if (err) { dispatch(module.exports.setFetchStatus('projectStudios', module.exports.Status.ERROR)); diff --git a/src/views/preview/project-view.jsx b/src/views/preview/project-view.jsx index 903d01fd4..eac5fe7aa 100644 --- a/src/views/preview/project-view.jsx +++ b/src/views/preview/project-view.jsx @@ -160,7 +160,10 @@ class Preview extends React.Component { if (typeof this.props.projectInfo.id === 'undefined') { this.initCounts(0, 0); } else { + const token = this.props.user ? this.props.user.token : null; this.initCounts(this.props.projectInfo.stats.favorites, this.props.projectInfo.stats.loves); + this.props.getProjectStudios(this.props.projectInfo.id, + this.props.authorUsername, this.props.isAdmin, token); if (this.props.projectInfo.remix.parent !== null) { this.props.getParentInfo(this.props.projectInfo.remix.parent); } @@ -216,7 +219,6 @@ class Preview extends React.Component { } this.props.getProjectInfo(this.state.projectId, token); this.props.getRemixes(this.state.projectId, token); - this.props.getProjectStudios(this.state.projectId, token); this.props.getCuratedStudios(username); this.props.getFavedStatus(this.state.projectId, username, token); this.props.getLovedStatus(this.state.projectId, username, token); @@ -228,7 +230,6 @@ class Preview extends React.Component { } this.props.getProjectInfo(this.state.projectId); this.props.getRemixes(this.state.projectId); - this.props.getProjectStudios(this.state.projectId); } } setScreenFromOrientation () { @@ -984,8 +985,8 @@ const mapDispatchToProps = dispatch => ({ getRemixes: id => { dispatch(previewActions.getRemixes(id)); }, - getProjectStudios: id => { - dispatch(previewActions.getProjectStudios(id)); + getProjectStudios: (id, ownerUsername, isAdmin, token) => { + dispatch(previewActions.getProjectStudios(id, ownerUsername, isAdmin, token)); }, getCuratedStudios: (username, token) => { dispatch(previewActions.getCuratedStudios(username, token)); From 975a9c964555523616055e6287a46ccfc16e6a1c Mon Sep 17 00:00:00 2001 From: Ben Wheeler Date: Tue, 28 May 2019 15:11:17 -0400 Subject: [PATCH 2/2] omit token if null or falsy --- src/redux/preview.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/redux/preview.js b/src/redux/preview.js index 4fbf21241..239a4a93e 100644 --- a/src/redux/preview.js +++ b/src/redux/preview.js @@ -763,12 +763,16 @@ module.exports.getRemixes = id => (dispatch => { }); }); + module.exports.getProjectStudios = (id, ownerUsername, isAdmin, token) => (dispatch => { dispatch(module.exports.setFetchStatus('projectStudios', module.exports.Status.FETCHING)); - api({ - uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${id}/studios`, - authentication: token - }, (err, body, res) => { + const opts = { + uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${id}/studios` + }; + if (token) { + Object.assign(opts, {authentication: token}); + } + api(opts, (err, body, res) => { if (err) { dispatch(module.exports.setFetchStatus('projectStudios', module.exports.Status.ERROR)); dispatch(module.exports.setError(err));