From 1a22998ff881257b6e5f1e819d4bd78899fefaea Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Fri, 13 Jan 2017 17:32:06 -0500 Subject: [PATCH] warn user of session change when deleting a project or saving a new project --- client/modules/IDE/actions/project.js | 14 ++++++++++---- client/modules/IDE/actions/projects.js | 11 +++++++++++ server/controllers/project.controller.js | 6 +++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/client/modules/IDE/actions/project.js b/client/modules/IDE/actions/project.js index 2f17bf1a..385e55c8 100644 --- a/client/modules/IDE/actions/project.js +++ b/client/modules/IDE/actions/project.js @@ -107,10 +107,16 @@ export function saveProject(autosave = false) { } } }) - .catch(response => dispatch({ - type: ActionTypes.PROJECT_SAVE_FAIL, - error: response.data - })); + .catch(response => { + if (response.status === 403) { + dispatch(showAuthenticationError()); + } else { + dispatch({ + type: ActionTypes.PROJECT_SAVE_FAIL, + error: response.data + }); + } + }); } }; } diff --git a/client/modules/IDE/actions/projects.js b/client/modules/IDE/actions/projects.js index 2b613dc9..43892453 100644 --- a/client/modules/IDE/actions/projects.js +++ b/client/modules/IDE/actions/projects.js @@ -1,5 +1,6 @@ import * as ActionTypes from '../../../constants'; import axios from 'axios'; +import { showAuthenticationError } from './ide'; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; @@ -33,6 +34,16 @@ export function deleteProject(id) { type: ActionTypes.DELETE_PROJECT, id }); + }) + .catch(response => { + if (response.status === 403) { + dispatch(showAuthenticationError()); + } else { + dispatch({ + type: ActionTypes.ERROR, + error: response.data + }); + } }); }; } diff --git a/server/controllers/project.controller.js b/server/controllers/project.controller.js index 0f75ee3c..db401e41 100644 --- a/server/controllers/project.controller.js +++ b/server/controllers/project.controller.js @@ -5,8 +5,12 @@ import request from 'request'; export function createProject(req, res) { + if (!req.user) { + return res.status(403).send({ success: false, message: 'Session does not match owner of project.'}); + } + let projectValues = { - user: req.user ? req.user._id : undefined // eslint-disable-line no-underscore-dangle + user: req.user._id }; projectValues = Object.assign(projectValues, req.body);