Work in progress on introducing tag language. Not tested yet.
This commit is contained in:
parent
450b930cc5
commit
00e328a914
21 changed files with 2154 additions and 1909 deletions
|
@ -10,6 +10,7 @@ const shares = require('./shares');
|
|||
const namespaceHelpers = require('../lib/namespace-helpers');
|
||||
const files = require('./files');
|
||||
const templates = require('./templates');
|
||||
const { allTagLanguages } = require('../../shared/templates');
|
||||
const { CampaignStatus, CampaignSource, CampaignType, getSendConfigurationPermissionRequiredForSend } = require('../../shared/campaigns');
|
||||
const sendConfigurations = require('./send-configurations');
|
||||
const triggers = require('./triggers');
|
||||
|
@ -445,6 +446,10 @@ async function _validateAndPreprocess(tx, context, entity, isCreate, content) {
|
|||
|
||||
await shares.enforceEntityPermissionTx(tx, context, 'sendConfiguration', entity.send_configuration, 'viewPublic');
|
||||
}
|
||||
|
||||
if ((isCreate && entity.source === CampaignSource.CUSTOM) || (content === Content.ONLY_SOURCE_CUSTOM)) {
|
||||
enforce(allTagLanguages.includes(entity.data.sourceCustom.tag_language), `Invalid tag language '${entity.data.sourceCustom.tag_language}'`);
|
||||
}
|
||||
}
|
||||
|
||||
async function _createTx(tx, context, entity, content) {
|
||||
|
@ -462,6 +467,7 @@ async function _createTx(tx, context, entity, content) {
|
|||
|
||||
entity.data.sourceCustom = {
|
||||
type: template.type,
|
||||
tag_language: template.tag_language,
|
||||
data: template.data,
|
||||
html: template.html,
|
||||
text: template.text
|
||||
|
|
|
@ -9,8 +9,9 @@ const namespaceHelpers = require('../lib/namespace-helpers');
|
|||
const shares = require('./shares');
|
||||
const files = require('./files');
|
||||
const dependencyHelpers = require('../lib/dependency-helpers');
|
||||
const { allTagLanguages } = require('../../shared/templates');
|
||||
|
||||
const allowedKeys = new Set(['name', 'description', 'type', 'data', 'namespace']);
|
||||
const allowedKeys = new Set(['name', 'description', 'type', 'tag_language', 'data', 'namespace']);
|
||||
|
||||
function hash(entity) {
|
||||
return hasher.hash(filterObject(entity, allowedKeys));
|
||||
|
@ -32,11 +33,25 @@ async function listDTAjax(context, params) {
|
|||
[{ entityTypeId: 'mosaicoTemplate', requiredOperations: ['view'] }],
|
||||
params,
|
||||
builder => builder.from('mosaico_templates').innerJoin('namespaces', 'namespaces.id', 'mosaico_templates.namespace'),
|
||||
[ 'mosaico_templates.id', 'mosaico_templates.name', 'mosaico_templates.description', 'mosaico_templates.type', 'mosaico_templates.created', 'namespaces.name' ]
|
||||
[ 'mosaico_templates.id', 'mosaico_templates.name', 'mosaico_templates.description', 'mosaico_templates.type', 'mosaico_templates.tag_language', 'mosaico_templates.created', 'namespaces.name' ]
|
||||
);
|
||||
}
|
||||
|
||||
async function listByTagLanguageDTAjax(context, tagLanguage, params) {
|
||||
return await dtHelpers.ajaxListWithPermissions(
|
||||
context,
|
||||
[{ entityTypeId: 'mosaicoTemplate', requiredOperations: ['view'] }],
|
||||
params,
|
||||
builder => builder.from('mosaico_templates')
|
||||
.innerJoin('namespaces', 'namespaces.id', 'mosaico_templates.namespace')
|
||||
.where('mosaico_templates.tag_language', tagLanguage),
|
||||
[ 'mosaico_templates.id', 'mosaico_templates.name', 'mosaico_templates.description', 'mosaico_templates.type', 'mosaico_templates.tag_language', 'mosaico_templates.created', 'namespaces.name' ]
|
||||
);
|
||||
}
|
||||
|
||||
async function _validateAndPreprocess(tx, entity) {
|
||||
enforce(allTagLanguages.includes(entity.tag_language), `Invalid tag language '${entity.tag_language}'`);
|
||||
|
||||
entity.data = JSON.stringify(entity.data);
|
||||
await namespaceHelpers.validateEntity(tx, entity);
|
||||
}
|
||||
|
@ -119,6 +134,7 @@ async function remove(context, id) {
|
|||
module.exports.hash = hash;
|
||||
module.exports.getById = getById;
|
||||
module.exports.listDTAjax = listDTAjax;
|
||||
module.exports.listByTagLanguageDTAjax = listByTagLanguageDTAjax;
|
||||
module.exports.create = create;
|
||||
module.exports.updateWithConsistencyCheck = updateWithConsistencyCheck;
|
||||
module.exports.remove = remove;
|
||||
|
|
|
@ -14,11 +14,11 @@ const {convertFileURLs} = require('../lib/campaign-content');
|
|||
const mailers = require('../lib/mailers');
|
||||
const tools = require('../lib/tools');
|
||||
const sendConfigurations = require('./send-configurations');
|
||||
const { getMergeTagsForBases } = require('../../shared/templates');
|
||||
const { getMergeTagsForBases, allTagLanguages } = require('../../shared/templates');
|
||||
const { getTrustedUrl, getSandboxUrl, getPublicUrl } = require('../lib/urls');
|
||||
const htmlToText = require('html-to-text');
|
||||
|
||||
const allowedKeys = new Set(['name', 'description', 'type', 'data', 'html', 'text', 'namespace']);
|
||||
const allowedKeys = new Set(['name', 'description', 'type', 'tag_language', 'data', 'html', 'text', 'namespace']);
|
||||
|
||||
function hash(entity) {
|
||||
return hasher.hash(filterObject(entity, allowedKeys));
|
||||
|
@ -54,7 +54,7 @@ async function _listDTAjax(context, namespaceId, params) {
|
|||
}
|
||||
return builder;
|
||||
},
|
||||
[ 'templates.id', 'templates.name', 'templates.description', 'templates.type', 'templates.created', 'namespaces.name' ]
|
||||
[ 'templates.id', 'templates.name', 'templates.description', 'templates.type', 'templates.tag_language', 'templates.created', 'namespaces.name' ]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -69,6 +69,8 @@ async function listByNamespaceDTAjax(context, namespaceId, params) {
|
|||
async function _validateAndPreprocess(tx, entity) {
|
||||
await namespaceHelpers.validateEntity(tx, entity);
|
||||
|
||||
enforce(allTagLanguages.includes(entity.tag_language), `Invalid tag language '${entity.tag_language}'`);
|
||||
|
||||
// We don't check contents of the "data" because it is processed solely on the client. The client generates the HTML code we use when sending out campaigns.
|
||||
|
||||
entity.data = JSON.stringify(entity.data);
|
||||
|
@ -82,6 +84,7 @@ async function create(context, entity) {
|
|||
const template = await getByIdTx(tx, context, entity.sourceTemplate, false);
|
||||
|
||||
entity.type = template.type;
|
||||
entity.tag_language = template.tag_language;
|
||||
entity.data = template.data;
|
||||
entity.html = template.html;
|
||||
entity.text = template.text;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue