From 856c4000c8409ce0e577144ce3906a392d7d6155 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 7 Mar 2019 17:31:03 +0000 Subject: [PATCH] Fixed 500 errors when accessing editor routes without post/page no issue --- ghost/admin/app/routes/editor/edit.js | 13 ++++++++++--- ghost/admin/app/routes/editor/new.js | 11 +++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ghost/admin/app/routes/editor/edit.js b/ghost/admin/app/routes/editor/edit.js index fd92413ec6..a6636d8682 100644 --- a/ghost/admin/app/routes/editor/edit.js +++ b/ghost/admin/app/routes/editor/edit.js @@ -14,13 +14,20 @@ export default AuthenticatedRoute.extend({ } }, - model(params) { + model(params, transition) { + let {type: modelName, post_id} = params; + + if (!['post', 'page'].includes(modelName)) { + let path = transition.intent.url.replace(/^\//, ''); + return this.replaceWith('error404', {path, status: 404}); + } + let query = { - id: params.post_id, + id: post_id, status: 'all' }; - return this.store.query(params.type, query) + return this.store.query(modelName, query) .then(records => records.get('firstObject')); }, diff --git a/ghost/admin/app/routes/editor/new.js b/ghost/admin/app/routes/editor/new.js index 63373860c7..b22d540585 100644 --- a/ghost/admin/app/routes/editor/new.js +++ b/ghost/admin/app/routes/editor/new.js @@ -1,9 +1,16 @@ import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; export default AuthenticatedRoute.extend({ - model(params) { + model(params, transition) { + let {type: modelName} = params; + + if (!['post','page'].includes(modelName)) { + let path = transition.intent.url.replace(/^\//, ''); + return this.replaceWith('error404', {path, status: 404}); + } + return this.get('session.user').then(user => ( - this.store.createRecord(params.type, {authors: [user]}) + this.store.createRecord(modelName, {authors: [user]}) )); },