mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Persisted post revision author and title (#16653)
no issue Persisted post revision author and title
This commit is contained in:
parent
7e349d0bf8
commit
9911e6be78
@ -908,6 +908,7 @@ Post = ghostBookshelf.Model.extend({
|
|||||||
max_revisions: POST_REVISIONS_COUNT
|
max_revisions: POST_REVISIONS_COUNT
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
const authorId = this.contextUser(options);
|
||||||
ops.push(async function updateRevisions() {
|
ops.push(async function updateRevisions() {
|
||||||
const revisionModels = await ghostBookshelf.model('PostRevision')
|
const revisionModels = await ghostBookshelf.model('PostRevision')
|
||||||
.findAll(Object.assign({
|
.findAll(Object.assign({
|
||||||
@ -919,12 +920,16 @@ Post = ghostBookshelf.Model.extend({
|
|||||||
const previous = {
|
const previous = {
|
||||||
id: model.id,
|
id: model.id,
|
||||||
lexical: model.previous('lexical'),
|
lexical: model.previous('lexical'),
|
||||||
html: model.previous('html')
|
html: model.previous('html'),
|
||||||
|
author_id: model.previous('updated_by'),
|
||||||
|
title: model.previous('title')
|
||||||
};
|
};
|
||||||
const current = {
|
const current = {
|
||||||
id: model.id,
|
id: model.id,
|
||||||
lexical: model.get('lexical'),
|
lexical: model.get('lexical'),
|
||||||
html: model.get('html')
|
html: model.get('html'),
|
||||||
|
author_id: authorId,
|
||||||
|
title: model.get('title')
|
||||||
};
|
};
|
||||||
|
|
||||||
const newRevisions = await postRevisions.getRevisions(previous, current, revisions);
|
const newRevisions = await postRevisions.getRevisions(previous, current, revisions);
|
||||||
|
@ -693,13 +693,13 @@ Object {
|
|||||||
"og_title": null,
|
"og_title": null,
|
||||||
"post_revisions": Array [
|
"post_revisions": Array [
|
||||||
Object {
|
Object {
|
||||||
"author_id": null,
|
"author_id": "1",
|
||||||
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
|
||||||
"created_at_ts": Any<Number>,
|
"created_at_ts": Any<Number>,
|
||||||
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||||
"lexical": "{\\"root\\":{\\"children\\":[{\\"children\\":[{\\"detail\\":0,\\"format\\":0,\\"mode\\":\\"normal\\",\\"style\\":\\"\\",\\"text\\":\\"Testing post creation with lexical\\",\\"type\\":\\"text\\",\\"version\\":1}],\\"direction\\":\\"ltr\\",\\"format\\":\\"\\",\\"indent\\":0,\\"type\\":\\"paragraph\\",\\"version\\":1}],\\"direction\\":\\"ltr\\",\\"format\\":\\"\\",\\"indent\\":0,\\"type\\":\\"root\\",\\"version\\":1}}",
|
"lexical": "{\\"root\\":{\\"children\\":[{\\"children\\":[{\\"detail\\":0,\\"format\\":0,\\"mode\\":\\"normal\\",\\"style\\":\\"\\",\\"text\\":\\"Testing post creation with lexical\\",\\"type\\":\\"text\\",\\"version\\":1}],\\"direction\\":\\"ltr\\",\\"format\\":\\"\\",\\"indent\\":0,\\"type\\":\\"paragraph\\",\\"version\\":1}],\\"direction\\":\\"ltr\\",\\"format\\":\\"\\",\\"indent\\":0,\\"type\\":\\"root\\",\\"version\\":1}}",
|
||||||
"post_id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
"post_id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
|
||||||
"title": null,
|
"title": "Post Revisions Test",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"published_at": null,
|
"published_at": null,
|
||||||
@ -722,7 +722,7 @@ exports[`Posts API Can read with post_revisions included 4: [headers] 1`] = `
|
|||||||
Object {
|
Object {
|
||||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||||
"content-length": "1480",
|
"content-length": "1496",
|
||||||
"content-type": "application/json; charset=utf-8",
|
"content-type": "application/json; charset=utf-8",
|
||||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||||
@ -831,7 +831,7 @@ exports[`Posts API Create Can create a post with lexical 2: [headers] 1`] = `
|
|||||||
Object {
|
Object {
|
||||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||||
"content-length": "4565",
|
"content-length": "4574",
|
||||||
"content-type": "application/json; charset=utf-8",
|
"content-type": "application/json; charset=utf-8",
|
||||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||||
@ -1261,7 +1261,7 @@ exports[`Posts API Update Can update a post with lexical 2: [headers] 1`] = `
|
|||||||
Object {
|
Object {
|
||||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||||
"content-length": "4495",
|
"content-length": "4511",
|
||||||
"content-type": "application/json; charset=utf-8",
|
"content-type": "application/json; charset=utf-8",
|
||||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||||
@ -1371,7 +1371,7 @@ exports[`Posts API Update Can update a post with lexical 4: [headers] 1`] = `
|
|||||||
Object {
|
Object {
|
||||||
"access-control-allow-origin": "http://127.0.0.1:2369",
|
"access-control-allow-origin": "http://127.0.0.1:2369",
|
||||||
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
|
||||||
"content-length": "5012",
|
"content-length": "5044",
|
||||||
"content-type": "application/json; charset=utf-8",
|
"content-type": "application/json; charset=utf-8",
|
||||||
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
|
||||||
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
* @property {string} id
|
* @property {string} id
|
||||||
* @property {string} lexical
|
* @property {string} lexical
|
||||||
* @property {string} html
|
* @property {string} html
|
||||||
|
* @property {string} author_id
|
||||||
|
* @property {string} title
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,6 +12,8 @@
|
|||||||
* @property {string} post_id
|
* @property {string} post_id
|
||||||
* @property {string} lexical
|
* @property {string} lexical
|
||||||
* @property {number} created_at_ts
|
* @property {number} created_at_ts
|
||||||
|
* @property {string} author_id
|
||||||
|
* @property {string} title
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class PostRevisions {
|
class PostRevisions {
|
||||||
@ -35,7 +39,7 @@ class PostRevisions {
|
|||||||
if (revisions.length === 0) {
|
if (revisions.length === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return previous.html !== current.html;
|
return previous.html !== current.html || previous.title !== current.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +61,7 @@ class PostRevisions {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [...revisions, currentRevision].slice(-this.config.max_revisions);
|
return [currentRevision, ...revisions].slice(0, this.config.max_revisions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,7 +72,9 @@ class PostRevisions {
|
|||||||
return {
|
return {
|
||||||
post_id: input.id,
|
post_id: input.id,
|
||||||
lexical: input.lexical,
|
lexical: input.lexical,
|
||||||
created_at_ts: Date.now() - offset
|
created_at_ts: Date.now() - offset,
|
||||||
|
author_id: input.author_id,
|
||||||
|
title: input.title
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,25 @@ describe('PostRevisions', function () {
|
|||||||
|
|
||||||
assert.equal(actual, expected);
|
assert.equal(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return true if the current and previous title values are different', function () {
|
||||||
|
const postRevisions = new PostRevisions({config});
|
||||||
|
|
||||||
|
const expected = true;
|
||||||
|
const actual = postRevisions.shouldGenerateRevision({
|
||||||
|
lexical: 'blah',
|
||||||
|
html: 'blah',
|
||||||
|
title: 'blah'
|
||||||
|
}, {
|
||||||
|
lexical: 'blah',
|
||||||
|
html: 'blah',
|
||||||
|
title: 'blah2'
|
||||||
|
}, [{
|
||||||
|
lexical: 'blah'
|
||||||
|
}]);
|
||||||
|
|
||||||
|
assert.equal(actual, expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getRevisions', function () {
|
describe('getRevisions', function () {
|
||||||
@ -93,21 +112,27 @@ describe('PostRevisions', function () {
|
|||||||
assert.deepEqual(actual, expected);
|
assert.deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns one revisions when there are no existing revisions', async function () {
|
it('returns one revision when there are no existing revisions', async function () {
|
||||||
const postRevisions = new PostRevisions({config});
|
const postRevisions = new PostRevisions({config});
|
||||||
|
|
||||||
const actual = await postRevisions.getRevisions({
|
const actual = await postRevisions.getRevisions({
|
||||||
id: '1',
|
id: '1',
|
||||||
lexical: 'previous',
|
lexical: 'previous',
|
||||||
html: 'previous'
|
html: 'previous',
|
||||||
|
author_id: '123',
|
||||||
|
title: 'foo bar baz'
|
||||||
}, {
|
}, {
|
||||||
id: '1',
|
id: '1',
|
||||||
lexical: 'current',
|
lexical: 'current',
|
||||||
html: 'current'
|
html: 'current',
|
||||||
|
author_id: '123',
|
||||||
|
title: 'foo bar baz'
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
assert.equal(actual.length, 1);
|
assert.equal(actual.length, 1);
|
||||||
assert.equal(actual[0].lexical, 'current');
|
assert.equal(actual[0].lexical, 'current');
|
||||||
|
assert.equal(actual[0].author_id, '123');
|
||||||
|
assert.equal(actual[0].title, 'foo bar baz');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('limits the number of revisions to the max_revisions count', async function () {
|
it('limits the number of revisions to the max_revisions count', async function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user