Skip to content

Commit ac3feb9

Browse files
authored
🐛 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
1 parent c20a6aa commit ac3feb9

File tree

4 files changed

+64
-30
lines changed

4 files changed

+64
-30
lines changed

core/server/data/slack/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,9 @@ function makeRequest(reqOptions, reqPayload) {
4343
req.end();
4444
}
4545

46-
function ping(post, options) {
47-
options = options || {};
48-
46+
function ping(post) {
4947
var message, reqOptions;
5048

51-
// CASE: do not ping slack if we import a database
52-
if (options.importing) {
53-
return Promise.resolve();
54-
}
55-
5649
// If this is a post, we want to send the link of the post
5750
if (schema.isPost(post)) {
5851
message = utils.url.urlFor('post', {post: post}, true);
@@ -107,7 +100,13 @@ function ping(post, options) {
107100
}
108101

109102
function listener(model, options) {
110-
ping(model.toJSON(), options);
103+
// CASE: do not ping slack if we import a database
104+
// TODO: refactor post.published events to never fire on importing
105+
if (options && options.importing) {
106+
return;
107+
}
108+
109+
ping(model.toJSON());
111110
}
112111

113112
function testPing() {

core/server/data/xml/xmlrpc.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
var _ = require('lodash'),
2-
http = require('http'),
3-
xml = require('xml'),
4-
config = require('../../config'),
5-
utils = require('../../utils'),
6-
errors = require('../../errors'),
7-
logging = require('../../logging'),
8-
events = require('../../events'),
9-
i18n = require('../../i18n'),
1+
var _ = require('lodash'),
2+
http = require('http'),
3+
xml = require('xml'),
4+
config = require('../../config'),
5+
utils = require('../../utils'),
6+
errors = require('../../errors'),
7+
logging = require('../../logging'),
8+
events = require('../../events'),
9+
i18n = require('../../i18n'),
10+
settingsCache = require('../../settings/cache'),
1011
pingList;
1112

1213
// ToDo: Make this configurable
@@ -32,7 +33,7 @@ function ping(post) {
3233
'themes'
3334
];
3435

35-
if (post.page || config.isPrivacyDisabled('useRpcPing')) {
36+
if (post.page || config.isPrivacyDisabled('useRpcPing') || settingsCache.get('is_private')) {
3637
return;
3738
}
3839

@@ -90,7 +91,13 @@ function ping(post) {
9091
});
9192
}
9293

93-
function listener(model) {
94+
function listener(model, options) {
95+
// CASE: do not rpc ping if we import a database
96+
// TODO: refactor post.published events to never fire on importing
97+
if (options && options.importing) {
98+
return;
99+
}
100+
94101
ping(model.toJSON());
95102
}
96103

core/test/unit/slack_spec.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,25 @@ describe('Slack', function () {
8282
resetSlack();
8383
});
8484

85+
it('listener() does not call ping() when importing', function () {
86+
var testPost = _.clone(testUtils.DataGenerator.Content.posts[2]),
87+
testModel = {
88+
toJSON: function () {
89+
return testPost;
90+
}
91+
},
92+
pingStub = sandbox.stub(),
93+
resetSlack = slack.__set__('ping', pingStub),
94+
listener = slack.__get__('listener');
95+
96+
listener(testModel, {importing: true});
97+
98+
pingStub.calledOnce.should.be.false();
99+
100+
// Reset slack ping method
101+
resetSlack();
102+
});
103+
85104
it('testPing() calls ping() with default message', function () {
86105
var pingStub = sandbox.stub(),
87106
resetSlack = slack.__set__('ping', pingStub),
@@ -294,15 +313,5 @@ describe('Slack', function () {
294313
done();
295314
});
296315
});
297-
298-
it('do not ping if content is imported', function (done) {
299-
ping({}, {importing: true}).then(function () {
300-
isPostStub.called.should.be.false();
301-
urlForSpy.called.should.be.false();
302-
settingsAPIStub.called.should.be.false();
303-
makeRequestSpy.called.should.be.false();
304-
done();
305-
}).catch(done);
306-
});
307316
});
308317
});

core/test/unit/xmlrpc_spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ describe('XMLRPC', function () {
5252
resetXmlRpc();
5353
});
5454

55+
it('listener() does not call ping() when importing', function () {
56+
var testPost = _.clone(testUtils.DataGenerator.Content.posts[2]),
57+
testModel = {
58+
toJSON: function () {
59+
return testPost;
60+
}
61+
},
62+
pingStub = sandbox.stub(),
63+
resetXmlRpc = xmlrpc.__set__('ping', pingStub),
64+
listener = xmlrpc.__get__('listener');
65+
66+
listener(testModel, {importing: true});
67+
68+
pingStub.calledOnce.should.be.false();
69+
70+
// Reset xmlrpc ping method
71+
resetXmlRpc();
72+
});
73+
5574
describe('ping()', function () {
5675
var ping = xmlrpc.__get__('ping');
5776

0 commit comments

Comments
 (0)