Fixed 500 errors when accessing editor routes without post/page

no issue
This commit is contained in:
Kevin Ansfield 2019-03-07 17:31:03 +00:00
parent 8514372dad
commit 856c4000c8
2 changed files with 19 additions and 5 deletions

View File

@ -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'));
},

View File

@ -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]})
));
},