mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
🐛 Prevents xmlrpc pings happening on import (#9165)
closes #9164 - check options.importing on xmlrpc - also don't ping if private - cleanup slack to work the same way - update tests - TODO: we need to prevent this event happening altogether
This commit is contained in:
parent
c20a6aa7f7
commit
ac3feb96d6
4 changed files with 64 additions and 30 deletions
|
@ -43,16 +43,9 @@ function makeRequest(reqOptions, reqPayload) {
|
|||
req.end();
|
||||
}
|
||||
|
||||
function ping(post, options) {
|
||||
options = options || {};
|
||||
|
||||
function ping(post) {
|
||||
var message, reqOptions;
|
||||
|
||||
// CASE: do not ping slack if we import a database
|
||||
if (options.importing) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// If this is a post, we want to send the link of the post
|
||||
if (schema.isPost(post)) {
|
||||
message = utils.url.urlFor('post', {post: post}, true);
|
||||
|
@ -107,7 +100,13 @@ function ping(post, options) {
|
|||
}
|
||||
|
||||
function listener(model, options) {
|
||||
ping(model.toJSON(), options);
|
||||
// CASE: do not ping slack if we import a database
|
||||
// TODO: refactor post.published events to never fire on importing
|
||||
if (options && options.importing) {
|
||||
return;
|
||||
}
|
||||
|
||||
ping(model.toJSON());
|
||||
}
|
||||
|
||||
function testPing() {
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
var _ = require('lodash'),
|
||||
http = require('http'),
|
||||
xml = require('xml'),
|
||||
config = require('../../config'),
|
||||
utils = require('../../utils'),
|
||||
errors = require('../../errors'),
|
||||
logging = require('../../logging'),
|
||||
events = require('../../events'),
|
||||
i18n = require('../../i18n'),
|
||||
var _ = require('lodash'),
|
||||
http = require('http'),
|
||||
xml = require('xml'),
|
||||
config = require('../../config'),
|
||||
utils = require('../../utils'),
|
||||
errors = require('../../errors'),
|
||||
logging = require('../../logging'),
|
||||
events = require('../../events'),
|
||||
i18n = require('../../i18n'),
|
||||
settingsCache = require('../../settings/cache'),
|
||||
pingList;
|
||||
|
||||
// ToDo: Make this configurable
|
||||
|
@ -32,7 +33,7 @@ function ping(post) {
|
|||
'themes'
|
||||
];
|
||||
|
||||
if (post.page || config.isPrivacyDisabled('useRpcPing')) {
|
||||
if (post.page || config.isPrivacyDisabled('useRpcPing') || settingsCache.get('is_private')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -90,7 +91,13 @@ function ping(post) {
|
|||
});
|
||||
}
|
||||
|
||||
function listener(model) {
|
||||
function listener(model, options) {
|
||||
// CASE: do not rpc ping if we import a database
|
||||
// TODO: refactor post.published events to never fire on importing
|
||||
if (options && options.importing) {
|
||||
return;
|
||||
}
|
||||
|
||||
ping(model.toJSON());
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,25 @@ describe('Slack', function () {
|
|||
resetSlack();
|
||||
});
|
||||
|
||||
it('listener() does not call ping() when importing', function () {
|
||||
var testPost = _.clone(testUtils.DataGenerator.Content.posts[2]),
|
||||
testModel = {
|
||||
toJSON: function () {
|
||||
return testPost;
|
||||
}
|
||||
},
|
||||
pingStub = sandbox.stub(),
|
||||
resetSlack = slack.__set__('ping', pingStub),
|
||||
listener = slack.__get__('listener');
|
||||
|
||||
listener(testModel, {importing: true});
|
||||
|
||||
pingStub.calledOnce.should.be.false();
|
||||
|
||||
// Reset slack ping method
|
||||
resetSlack();
|
||||
});
|
||||
|
||||
it('testPing() calls ping() with default message', function () {
|
||||
var pingStub = sandbox.stub(),
|
||||
resetSlack = slack.__set__('ping', pingStub),
|
||||
|
@ -294,15 +313,5 @@ describe('Slack', function () {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('do not ping if content is imported', function (done) {
|
||||
ping({}, {importing: true}).then(function () {
|
||||
isPostStub.called.should.be.false();
|
||||
urlForSpy.called.should.be.false();
|
||||
settingsAPIStub.called.should.be.false();
|
||||
makeRequestSpy.called.should.be.false();
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -52,6 +52,25 @@ describe('XMLRPC', function () {
|
|||
resetXmlRpc();
|
||||
});
|
||||
|
||||
it('listener() does not call ping() when importing', function () {
|
||||
var testPost = _.clone(testUtils.DataGenerator.Content.posts[2]),
|
||||
testModel = {
|
||||
toJSON: function () {
|
||||
return testPost;
|
||||
}
|
||||
},
|
||||
pingStub = sandbox.stub(),
|
||||
resetXmlRpc = xmlrpc.__set__('ping', pingStub),
|
||||
listener = xmlrpc.__get__('listener');
|
||||
|
||||
listener(testModel, {importing: true});
|
||||
|
||||
pingStub.calledOnce.should.be.false();
|
||||
|
||||
// Reset xmlrpc ping method
|
||||
resetXmlRpc();
|
||||
});
|
||||
|
||||
describe('ping()', function () {
|
||||
var ping = xmlrpc.__get__('ping');
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue