From e55317ec43c1db7f0ede22245c1655b8dcd00b16 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 5 Aug 2019 13:31:56 +0200 Subject: [PATCH 1/3] Clone existing template BUG fixed --- client/src/templates/CUD.js | 6 ++++-- server/models/templates.js | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/client/src/templates/CUD.js b/client/src/templates/CUD.js index 39bab165..b253f129 100644 --- a/client/src/templates/CUD.js +++ b/client/src/templates/CUD.js @@ -152,8 +152,10 @@ export default class CUD extends Component { } const typeKey = state.getIn(['type', 'value']); - if (!typeKey) { + if (!typeKey && !state.getIn(['fromExistingEntity', 'value'])) { state.setIn(['type', 'error'], t('typeMustBeSelected')); + }else{ + state.setIn(['type', 'error'], null); } if (!state.getIn(['tag_language', 'value'])) { @@ -168,7 +170,7 @@ export default class CUD extends Component { validateNamespace(t, state); - if (typeKey) { + if (typeKey && !state.getIn(['fromExistingEntity', 'value'])) { this.templateTypes[typeKey].validate(state); } } diff --git a/server/models/templates.js b/server/models/templates.js index 68d34c28..5a278a7d 100644 --- a/server/models/templates.js +++ b/server/models/templates.js @@ -92,12 +92,13 @@ async function create(context, entity) { await shares.rebuildPermissionsTx(tx, { entityTypeId: 'template', entityId: id }); - if (entity.fromExistingEntity) { + //Returns an error + /*if (entity.fromExistingEntity) { await files.copyAllTx(tx, context, 'template', 'file', entity.existingEntity, 'template', 'file', id); convertFileURLs(entity, 'template', entity.existingEntity, 'template', id); await tx('templates').update(filterObject(entity, allowedKeys)).where('id', id); - } + }*/ return id; }); From b08fd079091ff4a55c9a9ae3b8d92baca42f6f3b Mon Sep 17 00:00:00 2001 From: root Date: Tue, 6 Aug 2019 09:25:22 +0200 Subject: [PATCH 2/3] convertFileURLs fix --- server/lib/campaign-content.js | 4 ++-- server/models/templates.js | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/server/lib/campaign-content.js b/server/lib/campaign-content.js index 965b6bfb..1f6901d8 100644 --- a/server/lib/campaign-content.js +++ b/server/lib/campaign-content.js @@ -1,6 +1,6 @@ 'use strict'; -function convertFileURLs(sourceCustom, fromEntityType, fromEntityId, toEntityType, toEntityId) { +function convertFileURLs(sourceCustom, fromEntityType, fromEntityId, toEntityType, toEntityId, campaign) { function convertText(text) { if (text) { @@ -22,7 +22,7 @@ function convertFileURLs(sourceCustom, fromEntityType, fromEntityId, toEntityTyp sourceCustom.html = convertText(sourceCustom.html); sourceCustom.text = convertText(sourceCustom.text); - if (sourceCustom.type === 'mosaico' || sourceCustom.type === 'mosaicoWithFsTemplate') { + if ((sourceCustom.type === 'mosaico' || sourceCustom.type === 'mosaicoWithFsTemplate') && campaign){ sourceCustom.data.model = convertText(sourceCustom.data.model); sourceCustom.data.model = convertText(sourceCustom.data.model); sourceCustom.data.metadata = convertText(sourceCustom.data.metadata); diff --git a/server/models/templates.js b/server/models/templates.js index 5a278a7d..0f311f77 100644 --- a/server/models/templates.js +++ b/server/models/templates.js @@ -77,7 +77,7 @@ async function create(context, entity) { if (entity.fromExistingEntity) { const existing = await getByIdTx(tx, context, entity.existingEntity, false); - + entity.type = existing.type; entity.tag_language = existing.tag_language; entity.data = existing.data; @@ -92,13 +92,11 @@ async function create(context, entity) { await shares.rebuildPermissionsTx(tx, { entityTypeId: 'template', entityId: id }); - //Returns an error - /*if (entity.fromExistingEntity) { + if (entity.fromExistingEntity) { await files.copyAllTx(tx, context, 'template', 'file', entity.existingEntity, 'template', 'file', id); - - convertFileURLs(entity, 'template', entity.existingEntity, 'template', id); + convertFileURLs(entity, 'template', entity.existingEntity, 'template', id, false); await tx('templates').update(filterObject(entity, allowedKeys)).where('id', id); - }*/ + } return id; }); From 2929048ebeba303e6c482f3f3c699acaba5c07fc Mon Sep 17 00:00:00 2001 From: root Date: Tue, 6 Aug 2019 09:26:44 +0200 Subject: [PATCH 3/3] Fix --- server/models/campaigns.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/models/campaigns.js b/server/models/campaigns.js index 2e6aaa8f..a8f6e8f3 100644 --- a/server/models/campaigns.js +++ b/server/models/campaigns.js @@ -529,8 +529,7 @@ async function _createTx(tx, context, entity, content) { if (copyFilesFrom) { await files.copyAllTx(tx, context, copyFilesFrom.entityType, 'file', copyFilesFrom.entityId, 'campaign', 'file', id); - - convertFileURLs(data.sourceCustom, copyFilesFrom.entityType, copyFilesFrom.entityId, 'campaign', id); + convertFileURLs(data.sourceCustom, copyFilesFrom.entityType, copyFilesFrom.entityId, 'campaign', id, true); await tx('campaigns') .update({ data: JSON.stringify(data)