mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
parent
7c4e1584a6
commit
6c18ceef25
3 changed files with 30 additions and 11 deletions
|
@ -1,7 +1,8 @@
|
|||
const debug = require('ghost-ignition').debug('importer:clients'),
|
||||
Promise = require('bluebird'),
|
||||
_ = require('lodash'),
|
||||
BaseImporter = require('./base');
|
||||
BaseImporter = require('./base'),
|
||||
models = require('../../../../models');
|
||||
|
||||
class TrustedDomainsImporter extends BaseImporter {
|
||||
constructor(allDataFromFile) {
|
||||
|
@ -20,9 +21,25 @@ class TrustedDomainsImporter extends BaseImporter {
|
|||
};
|
||||
}
|
||||
|
||||
fetchExisting(modelOptions) {
|
||||
return models.ClientTrustedDomain.findAll(_.merge({columns: ['id', 'trusted_domain']}, modelOptions))
|
||||
.then((existingData) => {
|
||||
this.existingData = existingData.toJSON();
|
||||
});
|
||||
}
|
||||
|
||||
beforeImport() {
|
||||
debug('beforeImport');
|
||||
|
||||
// CASE: compare with existing trusted domains
|
||||
this.dataToImport = _.filter(this.dataToImport, (domainToImport) => {
|
||||
if (_.find(this.existingData, {trusted_domain: domainToImport.trusted_domain})) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return super.beforeImport();
|
||||
}
|
||||
|
||||
|
|
|
@ -1911,7 +1911,7 @@ describe('Import (new test structure)', function () {
|
|||
|
||||
describe('import clients/trusted_domains', function () {
|
||||
beforeEach(function doImport() {
|
||||
return testUtils.initFixtures('roles', 'owner', 'settings', 'clients');
|
||||
return testUtils.initFixtures('roles', 'owner', 'settings', 'clients', 'client:trusted-domain');
|
||||
});
|
||||
|
||||
it('skips importing clients, trusted domains by default', function () {
|
||||
|
@ -1953,17 +1953,15 @@ describe('Import (new test structure)', function () {
|
|||
should.exist(model);
|
||||
model.get('secret').should.eql('11111');
|
||||
|
||||
return models.ClientTrustedDomain.findOne({trusted_domain: 'https://test.com'}, testUtils.context.internal);
|
||||
return models.ClientTrustedDomain.findAll(testUtils.context.internal);
|
||||
})
|
||||
.then(function (model) {
|
||||
should.exist(model);
|
||||
model.get('client_id').should.eql(testUtils.DataGenerator.forKnex.clients[0].id);
|
||||
.then((models) => {
|
||||
models.length.should.eql(3);
|
||||
models = models.toJSON();
|
||||
|
||||
return models.ClientTrustedDomain.findOne({trusted_domain: 'https://example.com'}, testUtils.context.internal);
|
||||
})
|
||||
.then((model) => {
|
||||
should.exist(model);
|
||||
model.get('client_id').should.eql(somethingClient.id);
|
||||
_.find(models, {trusted_domain: 'https://test.com'}).client_id.should.eql(testUtils.DataGenerator.forKnex.clients[0].id);
|
||||
should.exist(_.find(models, {trusted_domain: 'https://example.com'}));
|
||||
_.find(models, {trusted_domain: 'https://lol.com'}).client_id.should.eql(somethingClient.id);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -33,6 +33,10 @@
|
|||
{
|
||||
"client_id": "59a952be7d79ed06b0d21127",
|
||||
"trusted_domain": "https://example.com"
|
||||
},
|
||||
{
|
||||
"client_id": "59a952be7d79ed06b0d21127",
|
||||
"trusted_domain": "https://lol.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue