Campaign preview as a particular user.
This commit is contained in:
parent
5670d21e76
commit
2d667523a1
3 changed files with 30 additions and 24 deletions
|
@ -26,7 +26,7 @@ import {getCampaignLabels} from './helpers';
|
|||
import {Table} from "../lib/table";
|
||||
import {Button} from "../lib/bootstrap-components";
|
||||
import axios from "../lib/axios";
|
||||
import {getUrl} from "../lib/urls";
|
||||
import {getUrl, getPublicUrl} from "../lib/urls";
|
||||
import interoperableErrors from '../../../shared/interoperable-errors';
|
||||
import {CampaignStatus} from "../../../shared/campaigns";
|
||||
import moment from 'moment';
|
||||
|
@ -66,13 +66,10 @@ class TestUser extends Component {
|
|||
|
||||
async previewAsync() {
|
||||
if (this.isFormWithoutErrors()) {
|
||||
const data = this.getFormValues();
|
||||
const campaignCid = this.props.entity.cid;
|
||||
const [listCid, subscriptionCid] = this.getFormValue('testUser').split(':');
|
||||
|
||||
console.log(this.props.entity);
|
||||
console.log(data);
|
||||
|
||||
// FIXME - navigate to campaign preview
|
||||
// window.location =
|
||||
window.open(getPublicUrl(`archive/${campaignCid}/${listCid}/${subscriptionCid}`), '_blank');
|
||||
} else {
|
||||
this.showFormValidation();
|
||||
}
|
||||
|
@ -83,10 +80,10 @@ class TestUser extends Component {
|
|||
|
||||
const testUsersColumns = [
|
||||
{ data: 1, title: t('Email') },
|
||||
{ data: 4, title: t('List ID'), render: data => <code>{data}</code> },
|
||||
{ data: 5, title: t('List') },
|
||||
{ data: 6, title: t('Segment') },
|
||||
{ data: 7, title: t('List namespace') }
|
||||
{ data: 2, title: t('Subscription ID'), render: data => <code>{data}</code> },
|
||||
{ data: 3, title: t('List ID'), render: data => <code>{data}</code> },
|
||||
{ data: 4, title: t('List') },
|
||||
{ data: 5, title: t('List namespace') }
|
||||
];
|
||||
|
||||
return (
|
||||
|
|
|
@ -110,12 +110,14 @@ async function ajaxListWithPermissionsTx(tx, context, fetchSpecs, params, queryF
|
|||
const permCols = [];
|
||||
for (const fetchSpec of fetchSpecs) {
|
||||
const entityType = entitySettings.getEntityType(fetchSpec.entityTypeId);
|
||||
const entityIdColumn = fetchSpec.column ? fetchSpec.column : entityType.entitiesTable + '.id';
|
||||
|
||||
permCols.push({
|
||||
name: `permissions_${fetchSpec.entityTypeId}`,
|
||||
query: builder => builder
|
||||
.from(entityType.permissionsTable)
|
||||
.select(knex.raw('GROUP_CONCAT(operation SEPARATOR \';\')'))
|
||||
.whereRaw(`${entityType.permissionsTable}.entity = ${entityType.entitiesTable}.id`)
|
||||
.whereRaw(`${entityType.permissionsTable}.entity = ${entityIdColumn}`)
|
||||
.where(`${entityType.permissionsTable}.user`, context.user.id)
|
||||
.as(`permissions_${fetchSpec.entityTypeId}`)
|
||||
});
|
||||
|
@ -131,11 +133,13 @@ async function ajaxListWithPermissionsTx(tx, context, fetchSpecs, params, queryF
|
|||
const entityType = entitySettings.getEntityType(fetchSpec.entityTypeId);
|
||||
|
||||
if (fetchSpec.requiredOperations) {
|
||||
const entityIdColumn = fetchSpec.column ? fetchSpec.column : entityType.entitiesTable + '.id';
|
||||
|
||||
query = query.innerJoin(
|
||||
function () {
|
||||
return this.from(entityType.permissionsTable).select('entity').where('user', context.user.id).whereIn('operation', fetchSpec.requiredOperations).as(`permitted__${fetchSpec.entityTypeId}`);
|
||||
},
|
||||
`permitted__${fetchSpec.entityTypeId}.entity`, `${entityType.entitiesTable}.id`)
|
||||
`permitted__${fetchSpec.entityTypeId}.entity`, entityIdColumn)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -101,9 +101,9 @@ async function listTestUsersDTAjax(context, campaignId, params) {
|
|||
This is supposed to produce queries like this:
|
||||
|
||||
select * from (
|
||||
(select `subscription__1`.`email`, 2 AS campaign_list_id, 1 AS list, NULL AS segment from `subscription__1` where `subscription__1`.`status` = 1 and `subscription__1`.`is_test` = true)
|
||||
(select `subscription__1`.`email`, `subscription__1`.`cid`, 1 AS list, NULL AS segment from `subscription__1` where `subscription__1`.`status` = 1 and `subscription__1`.`is_test` = true)
|
||||
UNION ALL
|
||||
(select `subscription__2`.`email`, 4 AS campaign_list_id, 2 AS list, NULL AS segment from `subscription__2` where `subscription__2`.`status` = 1 and `subscription__2`.`is_test` = true)
|
||||
(select `subscription__2`.`email`, `subscription__2`.`cid`, 2 AS list, NULL AS segment from `subscription__2` where `subscription__2`.`status` = 1 and `subscription__2`.`is_test` = true)
|
||||
) as `test_subscriptions` inner join `lists` on `test_subscriptions`.`list` = `lists`.`id` inner join `segments` on `test_subscriptions`.`segment` = `segments`.`id`
|
||||
inner join `namespaces` on `lists`.`namespace` = `namespaces`.`id`
|
||||
|
||||
|
@ -123,7 +123,7 @@ async function listTestUsersDTAjax(context, campaignId, params) {
|
|||
.where(function() {
|
||||
addSegmentQuery(this);
|
||||
})
|
||||
.select([subsTable + '.email', knex.raw('? AS campaign_list_id', [cpgList.id]), knex.raw('? AS list', [cpgList.list]), knex.raw('? AS segment', [cpgList.segment])])
|
||||
.select([subsTable + '.email', subsTable + '.cid', knex.raw('? AS list', [cpgList.list]), knex.raw('? AS segment', [cpgList.segment])])
|
||||
.toSQL().toNative();
|
||||
|
||||
subsQrys.push(sqlQry);
|
||||
|
@ -146,17 +146,22 @@ async function listTestUsersDTAjax(context, campaignId, params) {
|
|||
|
||||
return await dtHelpers.ajaxListWithPermissions(
|
||||
context,
|
||||
[{ entityTypeId: 'list', requiredOperations: ['viewSubscriptions'] }],
|
||||
[{ entityTypeId: 'list', requiredOperations: ['viewSubscriptions'], column: 'subs.list_id' }],
|
||||
params,
|
||||
builder => {
|
||||
const qry = builder.from(subsQry)
|
||||
.innerJoin('lists', 'test_subscriptions.list', 'lists.id')
|
||||
.leftJoin('segments', 'test_subscriptions.segment', 'segments.id')
|
||||
.innerJoin('namespaces', 'lists.namespace', 'namespaces.id')
|
||||
|
||||
return qry
|
||||
return builder.from(function () {
|
||||
return this.from(subsQry)
|
||||
.innerJoin('lists', 'test_subscriptions.list', 'lists.id')
|
||||
.innerJoin('namespaces', 'lists.namespace', 'namespaces.id')
|
||||
.select([
|
||||
knex.raw('CONCAT_WS(":", lists.cid, test_subscriptions.cid) AS cid'),
|
||||
'test_subscriptions.email', 'test_subscriptions.cid AS subscription_cid', 'lists.cid AS list_cid',
|
||||
'lists.name as list_name', 'namespaces.name AS namespace_name', 'lists.id AS list_id'
|
||||
])
|
||||
.as('subs');
|
||||
});
|
||||
},
|
||||
['test_subscriptions.campaign_list_id', 'test_subscriptions.email', 'test_subscriptions.list', 'test_subscriptions.segment', 'lists.cid', 'lists.name', 'segments.name', 'namespaces.name']
|
||||
[ 'subs.cid', 'subs.email', 'subs.subscription_cid', 'subs.list_cid', 'subs.list_name', 'subs.namespace_name' ]
|
||||
);
|
||||
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue