Skip to content

Commit

Permalink
Let already published conflicted property to continue republish
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja committed Dec 9, 2024
1 parent f509adf commit 4247219
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/model/query/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ const createOrMerge = (parsedDataset, form, fields) => async ({ context, one, Ac

// Check properties with same name but different capitualization
const duplicateProperties = newNames
.filter(newName => !existingNames.includes(newName))
.map(newName => ({
current: existingNames.find(existingName => existingName !== newName && newName.toLowerCase() === existingName.toLowerCase()),
current: existingNames.find(existingName => newName.toLowerCase() === existingName.toLowerCase()),
provided: newName
}))
.filter(property => property.current);
Expand Down Expand Up @@ -290,6 +291,7 @@ const publishIfExists = (formDefId, publishedAt) => async ({ all, context, maybe
AND dp.name != existing_properties.name
WHERE dpf."formDefId" = ${formDefId}
AND existing_properties."publishedAt" IS NOT NULL
AND dp."publishedAt" IS NULL
`;

const d = await maybeOne(_datasetNameConflict());
Expand Down
17 changes: 17 additions & 0 deletions test/integration/api/datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4063,6 +4063,23 @@ describe('datasets and entities', () => {
});

}));

it('should reject when publishing duplicate property with different capitalization', testService(async (service, container) => {
const alice = await service.login('alice');

await alice.post('/v1/projects/1/forms?publish=True')
.send(testData.forms.simpleEntity)
.set('Content-Type', 'application/xml')
.expect(200);

await container.run(sql`UPDATE ds_properties SET name='FIRST_NAME' WHERE name='age'`);

await alice.post('/v1/projects/1/forms/simpleEntity/draft')
.expect(200);

await alice.post('/v1/projects/1/forms/simpleEntity/draft/publish?version=v2')
.expect(200);
}));
});

describe('updating datasets through new form drafts', () => {
Expand Down

0 comments on commit 4247219

Please sign in to comment.