Fixes of functions around viewTestSubscriptions
This commit is contained in:
parent
ed3ed1a202
commit
712a905518
3 changed files with 19 additions and 15 deletions
|
@ -20,7 +20,7 @@ export default class List extends Component {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>{t('Mailtrain 2 beta')}</h2>
|
<h2>{t('Mailtrain 2 beta')}</h2>
|
||||||
<div>{t('Build') + ' 2019-07-29-0959'}</div>
|
<div>{t('Build') + ' 2019-08-01-0745'}</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ async function listTestUsersDTAjax(context, campaignId, params) {
|
||||||
return await dtHelpers.ajaxListWithPermissionsTx(
|
return await dtHelpers.ajaxListWithPermissionsTx(
|
||||||
tx,
|
tx,
|
||||||
context,
|
context,
|
||||||
[{ entityTypeId: 'list', requiredOperations: ['viewSubscriptions'], column: 'subs.list_id' }],
|
[{ entityTypeId: 'list', requiredOperations: ['viewTestSubscriptions'], column: 'subs.list_id' }],
|
||||||
params,
|
params,
|
||||||
builder => {
|
builder => {
|
||||||
return builder.from(function () {
|
return builder.from(function () {
|
||||||
|
@ -960,7 +960,7 @@ async function fetchRssCampaign(context, cid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testSend(context, data) {
|
async function testSend(context, data) {
|
||||||
// Though it's a bit counterintuitive, this handles also test sends of a template (i.e. without any campaign id)
|
// Though it's a bit counter-intuitive, this handles also test sends of a template (i.e. without any campaign id)
|
||||||
|
|
||||||
await knex.transaction(async tx => {
|
await knex.transaction(async tx => {
|
||||||
const processSubscriber = async (sendConfigurationId, listId, subscriptionId, messageData) => {
|
const processSubscriber = async (sendConfigurationId, listId, subscriptionId, messageData) => {
|
||||||
|
@ -1014,7 +1014,7 @@ async function testSend(context, data) {
|
||||||
await enforceSendPermissionTx(tx, context, campaign, true, listId);
|
await enforceSendPermissionTx(tx, context, campaign, true, listId);
|
||||||
|
|
||||||
if (data.subscriptionCid) {
|
if (data.subscriptionCid) {
|
||||||
const subscriber = await subscriptions.getByCidTx(tx, context, listId, data.subscriptionCid);
|
const subscriber = await subscriptions.getByCidTx(tx, context, listId, data.subscriptionCid, true, true);
|
||||||
await processSubscriber(sendConfigurationId, listId, subscriber.id, messageData);
|
await processSubscriber(sendConfigurationId, listId, subscriber.id, messageData);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -1050,7 +1050,7 @@ async function testSend(context, data) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const list = await lists.getByCidTx(tx, context, data.listCid);
|
const list = await lists.getByCidTx(tx, context, data.listCid);
|
||||||
const subscriber = await subscriptions.getByCidTx(tx, context, list.id, data.subscriptionCid);
|
const subscriber = await subscriptions.getByCidTx(tx, context, list.id, data.subscriptionCid, true, true);
|
||||||
await processSubscriber(data.sendConfigurationId, list.id, subscriber.id, messageData);
|
await processSubscriber(data.sendConfigurationId, list.id, subscriber.id, messageData);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -201,11 +201,15 @@ async function hashByList(listId, entity) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _getByTx(tx, context, listId, key, value, grouped) {
|
async function _getByTx(tx, context, listId, key, value, grouped, isTest) {
|
||||||
await shares.enforceEntityPermissionTx(tx, context, 'list', listId, 'viewSubscriptions');
|
await shares.enforceEntityPermissionTx(tx, context, 'list', listId, isTest ? 'viewTestSubscriptions' : 'viewSubscriptions');
|
||||||
|
|
||||||
const entity = await tx(getSubscriptionTableName(listId)).where(key, value).first();
|
const entity = await tx(getSubscriptionTableName(listId)).where(key, value).first();
|
||||||
|
|
||||||
|
if (isTest && (!entity || !entity.is_test)) {
|
||||||
|
shares.throwPermissionDenied();
|
||||||
|
}
|
||||||
|
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
throw new interoperableErrors.NotFoundError('Subscription not found in this list');
|
throw new interoperableErrors.NotFoundError('Subscription not found in this list');
|
||||||
}
|
}
|
||||||
|
@ -219,18 +223,18 @@ async function _getByTx(tx, context, listId, key, value, grouped) {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _getBy(context, listId, key, value, grouped) {
|
async function _getBy(context, listId, key, value, grouped, isTest) {
|
||||||
return await knex.transaction(async tx => {
|
return await knex.transaction(async tx => {
|
||||||
return _getByTx(tx, context, listId, key, value, grouped);
|
return _getByTx(tx, context, listId, key, value, grouped, isTest);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getById(context, listId, id, grouped = true) {
|
async function getById(context, listId, id, grouped = true) {
|
||||||
return await _getBy(context, listId, 'id', id, grouped);
|
return await _getBy(context, listId, 'id', id, grouped, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getByEmail(context, listId, email, grouped = true) {
|
async function getByEmail(context, listId, email, grouped = true) {
|
||||||
const result = await _getBy(context, listId, 'hash_email', hashEmail(email), grouped);
|
const result = await _getBy(context, listId, 'hash_email', hashEmail(email), grouped, false);
|
||||||
if (result.email === null) {
|
if (result.email === null) {
|
||||||
throw new interoperableErrors.NotFoundError('Subscription not found in this list');
|
throw new interoperableErrors.NotFoundError('Subscription not found in this list');
|
||||||
}
|
}
|
||||||
|
@ -238,12 +242,12 @@ async function getByEmail(context, listId, email, grouped = true) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getByCid(context, listId, cid, grouped = true) {
|
async function getByCid(context, listId, cid, grouped = true, isTest = true) {
|
||||||
return await _getBy(context, listId, 'cid', cid, grouped);
|
return await _getBy(context, listId, 'cid', cid, grouped, isTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getByCidTx(tx, context, listId, cid, grouped = true) {
|
async function getByCidTx(tx, context, listId, cid, grouped = true, isTest = true) {
|
||||||
return await _getByTx(tx, context, listId, 'cid', cid, grouped);
|
return await _getByTx(tx, context, listId, 'cid', cid, grouped, isTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listDTAjax(context, listId, segmentId, params) {
|
async function listDTAjax(context, listId, segmentId, params) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue