From 7919c15e562a2551b932f1fd75aa488a8aac2795 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 30 Jul 2014 17:44:49 +0100 Subject: [PATCH] Post list: authors see their own posts issue #3446 --- core/client/routes/editor/edit.js | 27 ++++++++++++++++++--------- core/client/routes/posts.js | 15 +++++++++++---- core/client/routes/posts/post.js | 27 ++++++++++++++++++--------- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/core/client/routes/editor/edit.js b/core/client/routes/editor/edit.js index 9bcdfa35b6..1ba1e85f31 100644 --- a/core/client/routes/editor/edit.js +++ b/core/client/routes/editor/edit.js @@ -6,7 +6,8 @@ var EditorEditRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, bas model: function (params) { var self = this, post, - postId; + postId, + paginationSettings; postId = Number(params.post_id); @@ -20,18 +21,26 @@ var EditorEditRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, bas return post; } - return this.store.find('post', { - id: params.post_id, + paginationSettings = { + id: postId, status: 'all', - staticPages: 'all', - }).then(function (records) { - var post = records.get('firstObject'); + staticPages: 'all' + }; - if (post) { - return post; + return this.store.find('user', 'me').then(function (user) { + if (user.get('isAuthor')) { + paginationSettings.author = user.get('slug'); } - return self.transitionTo('posts.index'); + return self.store.find('post', paginationSettings).then(function (records) { + var post = records.get('firstObject'); + + if (post) { + return post; + } + + return self.transitionTo('posts.index'); + }); }); }, diff --git a/core/client/routes/posts.js b/core/client/routes/posts.js index 9df1982cbd..8b4e409443 100644 --- a/core/client/routes/posts.js +++ b/core/client/routes/posts.js @@ -13,10 +13,17 @@ var PostsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, Shortcut classNames: ['manage'], model: function () { - // using `.filter` allows the template to auto-update when new models are pulled in from the server. - // we just need to 'return true' to allow all models by default. - return this.store.filter('post', paginationSettings, function () { - return true; + var self = this; + + return this.store.find('user', 'me').then(function (user) { + if (user.get('isAuthor')) { + paginationSettings.author = user.get('slug'); + } + // using `.filter` allows the template to auto-update when new models are pulled in from the server. + // we just need to 'return true' to allow all models by default. + return self.store.filter('post', paginationSettings, function () { + return true; + }); }); }, diff --git a/core/client/routes/posts/post.js b/core/client/routes/posts/post.js index 87a7cd4764..4ab2074636 100644 --- a/core/client/routes/posts/post.js +++ b/core/client/routes/posts/post.js @@ -5,7 +5,8 @@ var PostsPostRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, load model: function (params) { var self = this, post, - postId; + postId, + paginationSettings; postId = Number(params.post_id); @@ -20,18 +21,26 @@ var PostsPostRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, load return post; } - return this.store.find('post', { - id: params.post_id, + paginationSettings = { + id: postId, status: 'all', - staticPages: 'all', - }).then(function (records) { - var post = records.get('firstObject'); + staticPages: 'all' + }; - if (post) { - return post; + return this.store.find('user', 'me').then(function (user) { + if (user.get('isAuthor')) { + paginationSettings.author = user.get('slug'); } - return self.transitionTo('posts.index'); + return self.store.find('post', paginationSettings).then(function (records) { + var post = records.get('firstObject'); + + if (post) { + return post; + } + + return self.transitionTo('posts.index'); + }); }); }, setupController: function (controller, model) {