mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
Reverted dropped model usage in post serializer
refs 6b07d4b2a0
- The model is needed here, because it contains full set of fields. In some cases, like email-preview, the "plaintext" field is not present in "attrs" which causes the logic to fail.
- This should be sorted along with https://github.com/TryGhost/Ghost/issues/10396
This commit is contained in:
parent
6b07d4b2a0
commit
b5de4f4cf5
6 changed files with 54 additions and 33 deletions
|
@ -1,4 +1,5 @@
|
|||
const readingMinutes = require('@tryghost/helpers').utils.readingMinutes;
|
||||
const urlUtils = require('../../../../../../../shared/url-utils');
|
||||
|
||||
module.exports.forPost = (frame, model, attrs) => {
|
||||
const _ = require('lodash');
|
||||
|
@ -6,9 +7,10 @@ module.exports.forPost = (frame, model, attrs) => {
|
|||
if (!Object.prototype.hasOwnProperty.call(frame.options, 'columns') ||
|
||||
(frame.options.columns.includes('excerpt') && frame.options.formats && frame.options.formats.includes('plaintext'))) {
|
||||
if (_.isEmpty(attrs.custom_excerpt)) {
|
||||
const plaintext = attrs.plaintext;
|
||||
let plaintext = model.get('plaintext');
|
||||
|
||||
if (plaintext) {
|
||||
plaintext = urlUtils.transformReadyToAbsolute(plaintext);
|
||||
attrs.excerpt = plaintext.substring(0, 500);
|
||||
} else {
|
||||
attrs.excerpt = null;
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
const urlUtils = require('../../../../../../../shared/url-utils');
|
||||
|
||||
module.exports.forPost = (frame, model, attrs) => {
|
||||
const _ = require('lodash');
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(frame.options, 'columns') ||
|
||||
(frame.options.columns.includes('excerpt') && frame.options.formats && frame.options.formats.includes('plaintext'))) {
|
||||
if (_.isEmpty(attrs.custom_excerpt)) {
|
||||
const plaintext = attrs.plaintext;
|
||||
let plaintext = model.get('plaintext');
|
||||
|
||||
if (plaintext) {
|
||||
plaintext = urlUtils.transformReadyToAbsolute(plaintext);
|
||||
attrs.excerpt = plaintext.substring(0, 500);
|
||||
} else {
|
||||
attrs.excerpt = null;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const readingMinutes = require('@tryghost/helpers').utils.readingMinutes;
|
||||
const urlUtils = require('../../../../../../../shared/url-utils');
|
||||
|
||||
module.exports.forPost = (frame, model, attrs) => {
|
||||
const _ = require('lodash');
|
||||
|
@ -6,9 +7,10 @@ module.exports.forPost = (frame, model, attrs) => {
|
|||
if (!Object.prototype.hasOwnProperty.call(frame.options, 'columns') ||
|
||||
(frame.options.columns.includes('excerpt') && frame.options.formats && frame.options.formats.includes('plaintext'))) {
|
||||
if (_.isEmpty(attrs.custom_excerpt)) {
|
||||
const plaintext = attrs.plaintext;
|
||||
let plaintext = model.get('plaintext');
|
||||
|
||||
if (plaintext) {
|
||||
plaintext = urlUtils.transformReadyToAbsolute(plaintext);
|
||||
attrs.excerpt = plaintext.substring(0, 500);
|
||||
} else {
|
||||
attrs.excerpt = null;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const extraAttrsUtil = require('../../../../../../../../core/server/api/canary/utils/serializers/output/utils/extra-attrs');
|
||||
|
||||
describe('Unit: canary/utils/serializers/output/utils/extra-attrs', function () {
|
||||
|
@ -8,34 +9,38 @@ describe('Unit: canary/utils/serializers/output/utils/extra-attrs', function ()
|
|||
|
||||
let model;
|
||||
|
||||
beforeEach(function () {
|
||||
model = sinon.stub();
|
||||
model.get = sinon.stub();
|
||||
model.get.withArgs('plaintext').returns(new Array(5000).join('A'));
|
||||
});
|
||||
|
||||
describe('for post', function () {
|
||||
it('respects custom excerpt', function () {
|
||||
const attrs = {
|
||||
custom_excerpt: 'custom excerpt',
|
||||
plaintext: new Array(5000).join('A')
|
||||
};
|
||||
const attrs = {custom_excerpt: 'custom excerpt'};
|
||||
|
||||
extraAttrsUtil.forPost(frame, model, attrs);
|
||||
model.get.called.should.be.false();
|
||||
|
||||
attrs.excerpt.should.eql(attrs.custom_excerpt);
|
||||
});
|
||||
|
||||
it('no custom excerpt', function () {
|
||||
const attrs = {
|
||||
plaintext: new Array(5000).join('A')
|
||||
};
|
||||
const attrs = {};
|
||||
|
||||
extraAttrsUtil.forPost(frame, model, attrs);
|
||||
model.get.called.should.be.true();
|
||||
|
||||
attrs.excerpt.should.eql(new Array(501).join('A'));
|
||||
});
|
||||
|
||||
it('has excerpt when plaintext is null', function () {
|
||||
const attrs = {
|
||||
plaintext: null
|
||||
};
|
||||
model.get.withArgs('plaintext').returns(null);
|
||||
|
||||
const attrs = {};
|
||||
|
||||
extraAttrsUtil.forPost(frame, model, attrs);
|
||||
model.get.called.should.be.true();
|
||||
|
||||
attrs.should.have.property('excerpt');
|
||||
(attrs.excerpt === null).should.be.true();
|
||||
|
|
|
@ -9,34 +9,38 @@ describe('Unit: v2/utils/serializers/output/utils/extra-attrs', function () {
|
|||
|
||||
let model;
|
||||
|
||||
beforeEach(function () {
|
||||
model = sinon.stub();
|
||||
model.get = sinon.stub();
|
||||
model.get.withArgs('plaintext').returns(new Array(5000).join('A'));
|
||||
});
|
||||
|
||||
describe('for post', function () {
|
||||
it('respects custom excerpt', function () {
|
||||
const attrs = {
|
||||
custom_excerpt: 'custom excerpt',
|
||||
plaintext: new Array(5000).join('A')
|
||||
};
|
||||
const attrs = {custom_excerpt: 'custom excerpt'};
|
||||
|
||||
extraAttrsUtil.forPost(frame, model, attrs);
|
||||
model.get.called.should.be.false();
|
||||
|
||||
attrs.excerpt.should.eql(attrs.custom_excerpt);
|
||||
});
|
||||
|
||||
it('no custom excerpt', function () {
|
||||
const attrs = {
|
||||
plaintext: new Array(5000).join('A')
|
||||
};
|
||||
const attrs = {};
|
||||
|
||||
extraAttrsUtil.forPost(frame, model, attrs);
|
||||
model.get.called.should.be.true();
|
||||
|
||||
attrs.excerpt.should.eql(new Array(501).join('A'));
|
||||
});
|
||||
|
||||
it('has excerpt when plaintext is null', function () {
|
||||
const attrs = {
|
||||
plaintext: null
|
||||
};
|
||||
model.get.withArgs('plaintext').returns(null);
|
||||
|
||||
const attrs = {};
|
||||
|
||||
extraAttrsUtil.forPost(frame, model, attrs);
|
||||
model.get.called.should.be.true();
|
||||
|
||||
attrs.should.have.property('excerpt');
|
||||
(attrs.excerpt === null).should.be.true();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const extraAttrsUtil = require('../../../../../../../../core/server/api/v3/utils/serializers/output/utils/extra-attrs');
|
||||
|
||||
describe('Unit: v3/utils/serializers/output/utils/extra-attrs', function () {
|
||||
|
@ -8,34 +9,38 @@ describe('Unit: v3/utils/serializers/output/utils/extra-attrs', function () {
|
|||
|
||||
let model;
|
||||
|
||||
beforeEach(function () {
|
||||
model = sinon.stub();
|
||||
model.get = sinon.stub();
|
||||
model.get.withArgs('plaintext').returns(new Array(5000).join('A'));
|
||||
});
|
||||
|
||||
describe('for post', function () {
|
||||
it('respects custom excerpt', function () {
|
||||
const attrs = {
|
||||
custom_excerpt: 'custom excerpt',
|
||||
plaintext: new Array(5000).join('A')
|
||||
};
|
||||
const attrs = {custom_excerpt: 'custom excerpt'};
|
||||
|
||||
extraAttrsUtil.forPost(frame, model, attrs);
|
||||
model.get.called.should.be.false();
|
||||
|
||||
attrs.excerpt.should.eql(attrs.custom_excerpt);
|
||||
});
|
||||
|
||||
it('no custom excerpt', function () {
|
||||
const attrs = {
|
||||
plaintext: new Array(5000).join('A')
|
||||
};
|
||||
const attrs = {};
|
||||
|
||||
extraAttrsUtil.forPost(frame, model, attrs);
|
||||
model.get.called.should.be.true();
|
||||
|
||||
attrs.excerpt.should.eql(new Array(501).join('A'));
|
||||
});
|
||||
|
||||
it('has excerpt when plaintext is null', function () {
|
||||
const attrs = {
|
||||
plaintext: null
|
||||
};
|
||||
model.get.withArgs('plaintext').returns(null);
|
||||
|
||||
const attrs = {};
|
||||
|
||||
extraAttrsUtil.forPost(frame, model, attrs);
|
||||
model.get.called.should.be.true();
|
||||
|
||||
attrs.should.have.property('excerpt');
|
||||
(attrs.excerpt === null).should.be.true();
|
||||
|
|
Loading…
Add table
Reference in a new issue