use authorUsername, not users own username, in hitting logProjectView endpoint; use cookie and tokens in request

This commit is contained in:
Ben Wheeler 2018-12-07 11:00:43 -05:00
parent 5c3300dd68
commit 8dd239ebe5
2 changed files with 9 additions and 6 deletions

View file

@ -885,11 +885,14 @@ module.exports.updateProjectThumbnail = (id, blob) => (dispatch => {
});
});
module.exports.logProjectView = (id, username) => (dispatch => {
module.exports.logProjectView = (id, authorUsername, token) => (dispatch => {
dispatch(module.exports.setFetchStatus('project-log-view', module.exports.Status.FETCHING));
api({
uri: `/users/${username}/projects/${id}/views`,
method: 'POST'
uri: `/users/${authorUsername}/projects/${id}/views`,
method: 'POST',
authentication: token,
withCredentials: true,
useCsrf: true
}, (err, body, res) => {
if (err || res.statusCode !== 200) {
dispatch(module.exports.setFetchStatus('project-log-view', module.exports.Status.ERROR));

View file

@ -343,7 +343,7 @@ class Preview extends React.Component {
this.props.reportProject(this.state.projectId, formData, this.props.user.token);
}
handleGreenFlag () {
this.props.logProjectView(this.props.projectInfo.id, this.props.user.username);
this.props.logProjectView(this.props.projectInfo.id, this.props.authorUsername, this.props.user.token);
}
handlePopState () {
const path = window.location.pathname.toLowerCase();
@ -890,8 +890,8 @@ const mapDispatchToProps = dispatch => ({
getLovedStatus: (id, username, token) => {
dispatch(previewActions.getLovedStatus(id, username, token));
},
logProjectView: (id, username) => {
dispatch(previewActions.logProjectView(id, username));
logProjectView: (id, authorUsername, token) => {
dispatch(previewActions.logProjectView(id, authorUsername, token));
},
setLovedStatus: (loved, id, username, token) => {
dispatch(previewActions.setLovedStatus(loved, id, username, token));