mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +03:00
Added an /email/
root route for email-only posts
refs https://github.com/TryGhost/Team/issues/948 - The frontend route `/email/:uuid` is aliased to the preview as a temporary solution. It fulfills the premise of the email-only post anyway - not being accessible publicly and only shared through email. - The tests for the new route are missing as adding them was way more problematic than I envisoned. They are in the works and will be added as a follow up commit next.
This commit is contained in:
parent
e2c78e0634
commit
06a6dcb2d1
@ -1,5 +1,6 @@
|
||||
const ParentRouter = require('./ParentRouter');
|
||||
const urlUtils = require('../../../shared/url-utils');
|
||||
const labs = require('../../../shared/labs');
|
||||
const controllers = require('./controllers');
|
||||
|
||||
/**
|
||||
@ -27,6 +28,12 @@ class PreviewRouter extends ParentRouter {
|
||||
|
||||
// REGISTER: actual preview route
|
||||
this.mountRoute(urlUtils.urlJoin(this.route.value, ':uuid', ':options?'), controllers.preview);
|
||||
|
||||
// NOTE: temporary hack aliasing /email/ route to /p/ preview route
|
||||
// /email/ will become it's own Router once the feature enters beta stage
|
||||
if (labs.isSet('emailOnlyPosts')) {
|
||||
this.mountRoute(urlUtils.urlJoin('/email/', ':uuid', ':options?'), controllers.preview);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,6 @@
|
||||
const urlService = require('../../../../../../../frontend/services/url');
|
||||
const urlUtils = require('../../../../../../../shared/url-utils');
|
||||
const labs = require('../../../../../../../shared/labs');
|
||||
const localUtils = require('../../../index');
|
||||
|
||||
const forPost = (id, attrs, frame) => {
|
||||
@ -23,9 +24,15 @@ const forPost = (id, attrs, frame) => {
|
||||
*/
|
||||
if (!localUtils.isContentAPI(frame)) {
|
||||
if (attrs.status !== 'published' && attrs.url.match(/\/404\//)) {
|
||||
attrs.url = urlUtils.urlFor({
|
||||
relativeUrl: urlUtils.urlJoin('/p', attrs.uuid, '/')
|
||||
}, null, true);
|
||||
if (labs.isSet('emailOnlyPosts') && attrs.posts_meta && attrs.posts_meta.email_only) {
|
||||
attrs.url = urlUtils.urlFor({
|
||||
relativeUrl: urlUtils.urlJoin('/email', attrs.uuid, '/')
|
||||
}, null, true);
|
||||
} else {
|
||||
attrs.url = urlUtils.urlFor({
|
||||
relativeUrl: urlUtils.urlJoin('/p', attrs.uuid, '/')
|
||||
}, null, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ const localUtils = require('./utils');
|
||||
const ghost = testUtils.startGhost;
|
||||
let request;
|
||||
|
||||
describe('Posts API (canary)', function () {
|
||||
describe.only('Posts API (canary)', function () {
|
||||
let ghostServer;
|
||||
|
||||
before(function () {
|
||||
@ -642,14 +642,14 @@ describe('Posts API (canary)', function () {
|
||||
|
||||
it('can edit post_meta field that has default value and no previously created posts_meta relation', function () {
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[0].id}/`))
|
||||
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[3].id}/`))
|
||||
.set('Origin', config.get('url'))
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
should.equal(res.body.posts[0].email_only, false);
|
||||
|
||||
return request
|
||||
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[1].id + '/'))
|
||||
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[3].id + '/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
posts: [{
|
||||
@ -666,6 +666,7 @@ describe('Posts API (canary)', function () {
|
||||
|
||||
should.exist(res.body.posts);
|
||||
should.equal(res.body.posts[0].email_only, true);
|
||||
should.equal(res.body.posts[0].url, 'http://127.0.0.1:2369/email/d52c42ae-2755-455c-80ec-70b2ec55c903/');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user