Merge pull request #2615 from benjiwheeler/hotfix/proxy-love-favorite

[MASTER] love and favorite proxy, and use x-requested-with header
This commit is contained in:
Benjamin Wheeler 2019-01-07 14:38:15 -05:00 committed by GitHub
commit 5db6f40f5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 100 additions and 11 deletions

View file

@ -88,7 +88,7 @@
"general.copyLink": "Copy Link",
"general.report": "Report",
"general.notAvailableHeadline": "Whoops! Our server is Scratch'ing its head",
"general.notAvailableSubtitle": "We couldn't find the page you're looking for. Check to make sure you've typed the url correctly.",
"general.notAvailableSubtitle": "We couldn't find the page you're looking for. Check to make sure you've typed the URL correctly.",
"general.seeAllComments": "See all comments",
"general.all": "All",

View file

@ -12,7 +12,7 @@ const urlParams = require('./url-params');
* CSRF forgeries (see: https://www.squarefree.com/securitytips/web-developers.html#CSRF)
*
* It also takes in other arguments specified in the xhr library spec.
*
*
* @param {object} opts optional xhr args (see above)
* @param {Function} callback [description]
*/

View file

@ -574,6 +574,51 @@ module.exports.setFavedStatus = (faved, id, username, token) => (dispatch => {
}
});
module.exports.setFavedStatusViaProxy = (faved, id, username, token) => (dispatch => {
dispatch(module.exports.setFetchStatus('faved', module.exports.Status.FETCHING));
if (faved) {
api({
uri: `/proxy/projects/${id}/favorites/user/${username}`,
authentication: token,
withCredentials: true,
method: 'POST',
useCsrf: true,
headers: {'X-Requested-With': 'XMLHttpRequest'}
}, (err, body, res) => {
if (err || res.statusCode !== 200) {
dispatch(module.exports.setError(err));
return;
}
if (typeof body === 'undefined') {
dispatch(module.exports.setError('Set favorites returned no data'));
return;
}
dispatch(module.exports.setFetchStatus('faved', module.exports.Status.FETCHED));
dispatch(module.exports.setFaved(body.userFavorite));
});
} else {
api({
uri: `/proxy/projects/${id}/favorites/user/${username}`,
authentication: token,
withCredentials: true,
method: 'DELETE',
useCsrf: true,
headers: {'X-Requested-With': 'XMLHttpRequest'}
}, (err, body, res) => {
if (err || res.statusCode !== 200) {
dispatch(module.exports.setError(err));
return;
}
if (typeof body === 'undefined') {
dispatch(module.exports.setError('Set favorites returned no data'));
return;
}
dispatch(module.exports.setFetchStatus('faved', module.exports.Status.FETCHED));
dispatch(module.exports.setFaved(false));
});
}
});
module.exports.getLovedStatus = (id, username, token) => (dispatch => {
dispatch(module.exports.setFetchStatus('loved', module.exports.Status.FETCHING));
api({
@ -634,6 +679,51 @@ module.exports.setLovedStatus = (loved, id, username, token) => (dispatch => {
}
});
module.exports.setLovedStatusViaProxy = (loved, id, username, token) => (dispatch => {
dispatch(module.exports.setFetchStatus('loved', module.exports.Status.FETCHING));
if (loved) {
api({
uri: `/proxy/projects/${id}/loves/user/${username}`,
authentication: token,
withCredentials: true,
method: 'POST',
useCsrf: true,
headers: {'X-Requested-With': 'XMLHttpRequest'}
}, (err, body, res) => {
if (err || res.statusCode !== 200) {
dispatch(module.exports.setError(err));
return;
}
if (typeof body === 'undefined') {
dispatch(module.exports.setError('Set loved returned no data'));
return;
}
dispatch(module.exports.setFetchStatus('loved', module.exports.Status.FETCHED));
dispatch(module.exports.setLoved(body.userLove));
});
} else {
api({
uri: `/proxy/projects/${id}/loves/user/${username}`,
authentication: token,
withCredentials: true,
method: 'DELETE',
useCsrf: true,
headers: {'X-Requested-With': 'XMLHttpRequest'}
}, (err, body, res) => {
if (err || res.statusCode !== 200) {
dispatch(module.exports.setError(err));
return;
}
if (typeof body === 'undefined') {
dispatch(module.exports.setError('Set loved returned no data'));
return;
}
dispatch(module.exports.setFetchStatus('loved', module.exports.Status.FETCHED));
dispatch(module.exports.setLoved(body.userLove));
});
}
});
module.exports.getRemixes = id => (dispatch => {
dispatch(module.exports.setFetchStatus('remixes', module.exports.Status.FETCHING));
api({

View file

@ -379,8 +379,7 @@ const PreviewPresentation = ({
})
}}
validations={{
// TODO: actual 5000
maxLength: 1000
maxLength: 5000
}}
value={projectInfo.instructions}
/>
@ -423,8 +422,7 @@ const PreviewPresentation = ({
})
}}
validations={{
// TODO: actual 5000
maxLength: 1000
maxLength: 5000
}}
value={projectInfo.description}
/>
@ -522,7 +520,7 @@ const PreviewPresentation = ({
<FlexRow className="comments-root-reply">
{projectInfo.comments_allowed ? (
isLoggedIn ? (
<ComposeComment
isShared && <ComposeComment
projectId={projectId}
onAddComment={onAddComment}
/>
@ -543,7 +541,7 @@ const PreviewPresentation = ({
<TopLevelComment
author={comment.author}
canDelete={canDeleteComments}
canReply={isLoggedIn && projectInfo.comments_allowed}
canReply={isLoggedIn && projectInfo.comments_allowed && isShared}
canReport={isLoggedIn}
canRestore={canRestoreComments}
content={comment.content}

View file

@ -470,7 +470,8 @@ $stage-width: 480px;
&.has-error {
.validation-message {
transform: translate(26rem, 0);
top: 100%;
right: 0;
}
}

View file

@ -948,7 +948,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(previewActions.getFavedStatus(id, username, token));
},
setFavedStatus: (faved, id, username, token) => {
dispatch(previewActions.setFavedStatus(faved, id, username, token));
dispatch(previewActions.setFavedStatusViaProxy(faved, id, username, token));
},
getLovedStatus: (id, username, token) => {
dispatch(previewActions.getLovedStatus(id, username, token));
@ -957,7 +957,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(previewActions.logProjectView(id, authorUsername, token));
},
setLovedStatus: (loved, id, username, token) => {
dispatch(previewActions.setLovedStatus(loved, id, username, token));
dispatch(previewActions.setLovedStatusViaProxy(loved, id, username, token));
},
shareProject: (id, token) => {
dispatch(previewActions.shareProject(id, token));