Post list: authors see their own posts

issue #3446
This commit is contained in:
Hannah Wolfe 2014-07-30 17:44:49 +01:00
parent cc995e8ef6
commit 7919c15e56
3 changed files with 47 additions and 22 deletions

View File

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

View File

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

View File

@ -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) {