-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/release'
- Loading branch information
Showing
47 changed files
with
2,554 additions
and
4,377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/api/migrations/migrations/28-remove_not_allowed_metadata_properties/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-disable no-await-in-loop */ | ||
export default { | ||
delta: 28, | ||
|
||
name: 'remove_not_allowed_metadata_properties', | ||
|
||
description: | ||
'remove metadata properties from entities that is no longer on the template they belong', | ||
|
||
async up(db) { | ||
const cursor = db.collection('entities').find({}); | ||
let index = 1; | ||
const templatesProperties = {}; | ||
|
||
while (await cursor.hasNext()) { | ||
const entity = await cursor.next(); | ||
const entityTemplate = entity.template ? entity.template.toString() : 'empty'; | ||
|
||
if (!templatesProperties[entityTemplate]) { | ||
const template = await db.collection('templates').findOne({ _id: entity.template }); | ||
templatesProperties[entityTemplate] = []; | ||
|
||
if (template) { | ||
templatesProperties[entityTemplate] = template.properties.map(p => p.name); | ||
} | ||
} | ||
|
||
const propertiesOnTemplate = templatesProperties[entityTemplate]; | ||
const metadata = propertiesOnTemplate.reduce((newMetadata, prop) => { | ||
if (entity.metadata && entity.metadata[prop]) { | ||
//eslint-disable-next-line no-param-reassign | ||
newMetadata[prop] = entity.metadata[prop]; | ||
} | ||
return newMetadata; | ||
}, {}); | ||
|
||
await db.collection('entities').updateOne({ _id: entity._id }, { $set: { metadata } }); | ||
|
||
process.stdout.write(`-> processed: ${index} \r`); | ||
index += 1; | ||
} | ||
|
||
process.stdout.write('\r\n'); | ||
}, | ||
}; |
63 changes: 63 additions & 0 deletions
63
...e_not_allowed_metadata_properties/specs/28-remove_not_allowed_metadata_properties.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { testingDB } from 'api/utils/testing_db'; | ||
import migration from '../index.js'; | ||
import fixtures, { template1, template2 } from './fixtures.js'; | ||
|
||
describe('migration remove_not_allowed_metadata_properties', () => { | ||
beforeEach(async () => { | ||
spyOn(process.stdout, 'write'); | ||
await testingDB.clearAllAndLoad(fixtures); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testingDB.disconnect(); | ||
}); | ||
|
||
it('should have a delta number', () => { | ||
expect(migration.delta).toBe(28); | ||
}); | ||
|
||
it('should remove metadata properties from entities that do not exist on the template they belong', async () => { | ||
await migration.up(testingDB.mongodb); | ||
|
||
const template1Entities = await testingDB.mongodb | ||
.collection('entities') | ||
.find({ template: template1 }) | ||
.toArray(); | ||
|
||
const template2Entities = await testingDB.mongodb | ||
.collection('entities') | ||
.find({ template: template2 }) | ||
.toArray(); | ||
|
||
const entitiesNoTemplate = await testingDB.mongodb | ||
.collection('entities') | ||
.find({ template: { $exists: false } }) | ||
.toArray(); | ||
|
||
expect(entitiesNoTemplate).toEqual([expect.objectContaining({ metadata: {} })]); | ||
|
||
expect(template1Entities).toEqual([ | ||
expect.objectContaining({ | ||
metadata: { | ||
text: [{ value: 'value' }], | ||
text_2: [{ value: 'value2' }], | ||
}, | ||
}), | ||
expect.objectContaining({ | ||
metadata: { | ||
text: [{ value: 'value' }], | ||
text_2: [{ value: 'value2' }], | ||
}, | ||
}), | ||
]); | ||
|
||
expect(template2Entities).toEqual([ | ||
expect.objectContaining({ | ||
metadata: { | ||
text_3: [{ value: 'value3' }], | ||
}, | ||
}), | ||
expect.objectContaining({ title: 'entity without metadata' }), | ||
]); | ||
}); | ||
}); |
65 changes: 65 additions & 0 deletions
65
app/api/migrations/migrations/28-remove_not_allowed_metadata_properties/specs/fixtures.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { testingDB } from 'api/utils/testing_db'; | ||
|
||
const template1 = testingDB.id(); | ||
const template2 = testingDB.id(); | ||
|
||
export default { | ||
templates: [ | ||
{ | ||
_id: template1, | ||
properties: [ | ||
{ id: '1', type: 'text', name: 'text' }, | ||
{ id: '2', type: 'text', name: 'text_2' }, | ||
{ id: '3', type: 'text', name: 'not_present_on_entity' }, | ||
], | ||
}, | ||
{ | ||
_id: template2, | ||
properties: [{ id: '1', type: 'text', name: 'text_3' }], | ||
}, | ||
], | ||
entities: [ | ||
{ | ||
template: template1, | ||
metadata: { | ||
text: [{ value: 'value' }], | ||
text_2: [{ value: 'value2' }], | ||
text_3: [{ value: 'value3' }], | ||
text_4: [{ value: 'value4' }], | ||
}, | ||
}, | ||
{ | ||
title: 'entity without template', | ||
metadata: { | ||
text: [{ value: 'value' }], | ||
text_2: [{ value: 'value2' }], | ||
text_3: [{ value: 'value3' }], | ||
text_4: [{ value: 'value4' }], | ||
}, | ||
}, | ||
{ | ||
template: template1, | ||
metadata: { | ||
text: [{ value: 'value' }], | ||
text_2: [{ value: 'value2' }], | ||
text_3: [{ value: 'value3' }], | ||
text_4: [{ value: 'value4' }], | ||
}, | ||
}, | ||
{ | ||
template: template2, | ||
metadata: { | ||
text: [{ value: 'value' }], | ||
text_2: [{ value: 'value2' }], | ||
text_3: [{ value: 'value3' }], | ||
text_4: [{ value: 'value4' }], | ||
}, | ||
}, | ||
{ | ||
title: 'entity without metadata', | ||
template: template2, | ||
}, | ||
], | ||
}; | ||
|
||
export { template1, template2 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -295,6 +295,7 @@ mark.searchTerm { | |
|
||
.copy-from { | ||
flex: 1; | ||
min-width: 50%; | ||
|
||
.copy-from-buttons { | ||
position: absolute; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
app/react/Connections/reducers/specs/connectionReducer.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.