mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Remove email address from frontend
closes #2330 - added deletion email address from post.author in front end - updated tests - with some refactoring this could be done on API level
This commit is contained in:
parent
48a562d1ce
commit
d5747430e9
2 changed files with 54 additions and 6 deletions
|
@ -59,12 +59,29 @@ function getPostPage(options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatPageResponse(posts, page) {
|
function formatPageResponse(posts, page) {
|
||||||
|
// Delete email from author for frontend output
|
||||||
|
// TODO: do this on API level if no context is available
|
||||||
|
posts = _.each(posts, function (post) {
|
||||||
|
if (post.author) {
|
||||||
|
delete post.author.email;
|
||||||
|
}
|
||||||
|
return post;
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
posts: posts,
|
posts: posts,
|
||||||
pagination: page.meta.pagination
|
pagination: page.meta.pagination
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatResponse(post) {
|
||||||
|
// Delete email from author for frontend output
|
||||||
|
// TODO: do this on API level if no context is available
|
||||||
|
if (post.author) {
|
||||||
|
delete post.author.email;
|
||||||
|
}
|
||||||
|
return {post: post};
|
||||||
|
}
|
||||||
|
|
||||||
function handleError(next) {
|
function handleError(next) {
|
||||||
return function (err) {
|
return function (err) {
|
||||||
var e = new Error(err.message);
|
var e = new Error(err.message);
|
||||||
|
@ -291,7 +308,7 @@ frontendControllers = {
|
||||||
paths = config.paths.availableThemes[activeTheme.value],
|
paths = config.paths.availableThemes[activeTheme.value],
|
||||||
view = template.getThemeViewForPost(paths, post);
|
view = template.getThemeViewForPost(paths, post);
|
||||||
|
|
||||||
res.render(view, {post: post});
|
res.render(view, formatResponse(post));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,12 @@ describe('Frontend Controller', function () {
|
||||||
'slug': 'test-static-page',
|
'slug': 'test-static-page',
|
||||||
'markdown': 'Test static page content',
|
'markdown': 'Test static page content',
|
||||||
'page': 1,
|
'page': 1,
|
||||||
'published_at': new Date('2013/12/30').getTime()
|
'published_at': new Date('2013/12/30').getTime(),
|
||||||
|
'author': {
|
||||||
|
'id': 1,
|
||||||
|
'name': 'Test User',
|
||||||
|
'email': 'test@ghost.org'
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
'status': 'published',
|
'status': 'published',
|
||||||
'id': 2,
|
'id': 2,
|
||||||
|
@ -160,7 +165,12 @@ describe('Frontend Controller', function () {
|
||||||
'slug': 'test-normal-post',
|
'slug': 'test-normal-post',
|
||||||
'markdown': 'The test normal post content',
|
'markdown': 'The test normal post content',
|
||||||
'page': 0,
|
'page': 0,
|
||||||
'published_at': new Date('2014/1/2').getTime()
|
'published_at': new Date('2014/1/2').getTime(),
|
||||||
|
'author': {
|
||||||
|
'id': 1,
|
||||||
|
'name': 'Test User',
|
||||||
|
'email': 'test@ghost.org'
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
mockTags = [{
|
mockTags = [{
|
||||||
'name': 'video',
|
'name': 'video',
|
||||||
|
@ -248,6 +258,7 @@ describe('Frontend Controller', function () {
|
||||||
render: function (view, context) {
|
render: function (view, context) {
|
||||||
assert.equal(view, 'tag');
|
assert.equal(view, 'tag');
|
||||||
assert.equal(context.tag, mockTags[0]);
|
assert.equal(context.tag, mockTags[0]);
|
||||||
|
assert.equal(context.posts[0].author.email, undefined)
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -376,7 +387,12 @@ describe('Frontend Controller', function () {
|
||||||
'slug': 'test-static-page',
|
'slug': 'test-static-page',
|
||||||
'markdown': 'Test static page content',
|
'markdown': 'Test static page content',
|
||||||
'page': 1,
|
'page': 1,
|
||||||
'published_at': new Date('2013/12/30').getTime()
|
'published_at': new Date('2013/12/30').getTime(),
|
||||||
|
'author': {
|
||||||
|
'id': 1,
|
||||||
|
'name': 'Test User',
|
||||||
|
'email': 'test@ghost.org'
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
'posts': [{
|
'posts': [{
|
||||||
|
@ -386,7 +402,12 @@ describe('Frontend Controller', function () {
|
||||||
'slug': 'test-normal-post',
|
'slug': 'test-normal-post',
|
||||||
'markdown': 'The test normal post content',
|
'markdown': 'The test normal post content',
|
||||||
'page': 0,
|
'page': 0,
|
||||||
'published_at': new Date('2014/1/2').getTime()
|
'published_at': new Date('2014/1/2').getTime(),
|
||||||
|
'author': {
|
||||||
|
'id': 1,
|
||||||
|
'name': 'Test User',
|
||||||
|
'email': 'test@ghost.org'
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
'posts': [{
|
'posts': [{
|
||||||
|
@ -396,7 +417,12 @@ describe('Frontend Controller', function () {
|
||||||
'slug': 'about',
|
'slug': 'about',
|
||||||
'markdown': 'This is the about page content',
|
'markdown': 'This is the about page content',
|
||||||
'page': 1,
|
'page': 1,
|
||||||
'published_at': new Date('2014/1/30').getTime()
|
'published_at': new Date('2014/1/30').getTime(),
|
||||||
|
'author': {
|
||||||
|
'id': 1,
|
||||||
|
'name': 'Test User',
|
||||||
|
'email': 'test@ghost.org'
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
}],
|
}],
|
||||||
// Helper function to prevent unit tests
|
// Helper function to prevent unit tests
|
||||||
|
@ -460,6 +486,7 @@ describe('Frontend Controller', function () {
|
||||||
render: function (view, context) {
|
render: function (view, context) {
|
||||||
assert.equal(view, 'page-' + mockPosts[2].posts[0].slug);
|
assert.equal(view, 'page-' + mockPosts[2].posts[0].slug);
|
||||||
assert.equal(context.post, mockPosts[2].posts[0]);
|
assert.equal(context.post, mockPosts[2].posts[0]);
|
||||||
|
assert.equal(context.post.author.email, undefined);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -484,6 +511,7 @@ describe('Frontend Controller', function () {
|
||||||
render: function (view, context) {
|
render: function (view, context) {
|
||||||
assert.equal(view, 'page');
|
assert.equal(view, 'page');
|
||||||
assert.equal(context.post, mockPosts[0].posts[0]);
|
assert.equal(context.post, mockPosts[0].posts[0]);
|
||||||
|
assert.equal(context.post.author.email, undefined);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -629,6 +657,7 @@ describe('Frontend Controller', function () {
|
||||||
assert.equal(view, 'post');
|
assert.equal(view, 'post');
|
||||||
assert(context.post, 'Context object has post attribute');
|
assert(context.post, 'Context object has post attribute');
|
||||||
assert.equal(context.post, mockPosts[1].posts[0]);
|
assert.equal(context.post, mockPosts[1].posts[0]);
|
||||||
|
assert.equal(context.post.author.email, undefined);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -703,6 +732,7 @@ describe('Frontend Controller', function () {
|
||||||
assert.equal(view, 'post');
|
assert.equal(view, 'post');
|
||||||
assert(context.post, 'Context object has post attribute');
|
assert(context.post, 'Context object has post attribute');
|
||||||
assert.equal(context.post, mockPosts[1].posts[0]);
|
assert.equal(context.post, mockPosts[1].posts[0]);
|
||||||
|
assert.equal(context.post.author.email, undefined);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -793,6 +823,7 @@ describe('Frontend Controller', function () {
|
||||||
assert.equal(view, 'post');
|
assert.equal(view, 'post');
|
||||||
assert(context.post, 'Context object has post attribute');
|
assert(context.post, 'Context object has post attribute');
|
||||||
assert.equal(context.post, mockPosts[1].posts[0]);
|
assert.equal(context.post, mockPosts[1].posts[0]);
|
||||||
|
assert.equal(context.post.author.email, undefined);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue