Merge and cleanup of PR #564

The namespace filter in campaigns was dropped (i.e. "Work with campaign's namespace"). Instead, we need a universal solution. For instance a namespace slector somewhere in the top-right corner, which should apply to everything (not just campaigns).

Nevertheless, I kept the ...-by-namespace rest endpoints and related functions in models because they will be useful for implementing the universal namespace selection feature.
This commit is contained in:
Tomas Bures 2019-03-27 00:41:18 +01:00
parent dcb7168322
commit 2fe7f82be3
18 changed files with 1104 additions and 1143 deletions

View file

@ -229,7 +229,6 @@ export default class CUD extends Component {
[lstPrefix + 'list']: null, [lstPrefix + 'list']: null,
[lstPrefix + 'segment']: null, [lstPrefix + 'segment']: null,
[lstPrefix + 'useSegmentation']: false, [lstPrefix + 'useSegmentation']: false,
[lstPrefix + 'work_list_current_namespace']: false,
lists: [lstUid], lists: [lstUid],
send_configuration: null, send_configuration: null,
@ -237,8 +236,6 @@ export default class CUD extends Component {
click_tracking_disabled: false, click_tracking_disabled: false,
open_tracking_disabled: false, open_tracking_disabled: false,
work_send_config_current_namespace: false,
work_template_current_namespace: false,
unsubscribe_url: '', unsubscribe_url: '',
@ -524,17 +521,11 @@ export default class CUD extends Component {
const lstsEditEntries = []; const lstsEditEntries = [];
const lsts = this.getFormValue('lists') || []; const lsts = this.getFormValue('lists') || [];
let lstOrderIdx = 0; let lstOrderIdx = 0;
const currentNamespace = this.getFormValue('namespace');
const useNamespaceSendConfig = this.getFormValue('work_send_config_current_namespace');
const useNamespaceTemplate = this.getFormValue('work_template_current_namespace');
for (const lstUid of lsts) { for (const lstUid of lsts) {
const prefix = 'lists_' + lstUid + '_'; const prefix = 'lists_' + lstUid + '_';
const lstOrderIdxClosure = lstOrderIdx; const lstOrderIdxClosure = lstOrderIdx;
const selectedList = this.getFormValue(prefix + 'list'); const selectedList = this.getFormValue(prefix + 'list');
const useNamespaceLists = this.getFormValue(prefix + 'work_list_current_namespace');
lstsEditEntries.push( lstsEditEntries.push(
<div key={lstUid} className={campaignsStyles.entry + ' ' + campaignsStyles.entryWithButtons}> <div key={lstUid} className={campaignsStyles.entry + ' ' + campaignsStyles.entryWithButtons}>
@ -571,13 +562,8 @@ export default class CUD extends Component {
} }
</div> </div>
<div className={campaignsStyles.entryContent}> <div className={campaignsStyles.entryContent}>
<CheckBox id={prefix + "work_list_current_namespace"} label={t('namespaceFiltering')} text={t('workWithCampaignNamespace')}/> <TableSelect id={prefix + 'list'} label={t('list')} withHeader dropdown dataUrl='rest/lists-table' columns={listsColumns} selectionLabelIndex={1} />
{useNamespaceLists &&
<TableSelect id={prefix + 'list'} label={t('list')} withHeader dropdown dataUrl={`rest/users-table-byNamespace/${currentNamespace}`} columns={listsColumns} selectionLabelIndex={1} />
}
{!useNamespaceLists &&
<TableSelect id={prefix + 'list'} label={t('list')} withHeader dropdown dataUrl={`rest/lists-table`} columns={listsColumns} selectionLabelIndex={1} />
}
{(campaignTypeKey === CampaignType.REGULAR || campaignTypeKey === CampaignType.RSS) && {(campaignTypeKey === CampaignType.REGULAR || campaignTypeKey === CampaignType.RSS) &&
<div> <div>
<CheckBox id={prefix + 'useSegmentation'} label={t('segment')} text={t('useAParticularSegment')}/> <CheckBox id={prefix + 'useSegmentation'} label={t('segment')} text={t('useAParticularSegment')}/>
@ -622,7 +608,7 @@ export default class CUD extends Component {
sendSettings = []; sendSettings = [];
const addOverridable = (id, label) => { const addOverridable = (id, label) => {
if(this.state.sendConfiguration[id + '_overridable'] == 1){ if(this.state.sendConfiguration[id + '_overridable']){
if (this.getFormValue(id + '_overriden')) { if (this.getFormValue(id + '_overriden')) {
sendSettings.push(<InputField label={t(label)} key={id + '_override'} id={id + '_override'}/>); sendSettings.push(<InputField label={t(label)} key={id + '_override'} id={id + '_override'}/>);
} else { } else {
@ -632,7 +618,7 @@ export default class CUD extends Component {
</StaticField> </StaticField>
); );
} }
sendSettings.push(<CheckBox key={id + '_overriden'} id={id + '_overriden'} text={t('override')} overrideFormat={true}/>); sendSettings.push(<CheckBox key={id + '_overriden'} id={id + '_overriden'} text={t('override')} className={campaignsStyles.overrideCheckbox}/>);
} }
else{ else{
sendSettings.push( sendSettings.push(
@ -681,13 +667,7 @@ export default class CUD extends Component {
// The "key" property here and in the TableSelect below is to tell React that these tables are different and should be rendered by different instances. Otherwise, React will use // The "key" property here and in the TableSelect below is to tell React that these tables are different and should be rendered by different instances. Otherwise, React will use
// only one instance, which fails because Table does not handle updates in "columns" property // only one instance, which fails because Table does not handle updates in "columns" property
if(useNamespaceTemplate){
templateEdit = <TableSelect key="templateSelect" id="data_sourceTemplate" label={t('template')} withHeader dropdown dataUrl={`rest/templates-table-byNamespace/${currentNamespace}`} columns={templatesColumns} selectionLabelIndex={1} help={help}/>;
}
else{
templateEdit = <TableSelect key="templateSelect" id="data_sourceTemplate" label={t('template')} withHeader dropdown dataUrl='rest/templates-table' columns={templatesColumns} selectionLabelIndex={1} help={help}/>; templateEdit = <TableSelect key="templateSelect" id="data_sourceTemplate" label={t('template')} withHeader dropdown dataUrl='rest/templates-table' columns={templatesColumns} selectionLabelIndex={1} help={help}/>;
}
} else if (!isEdit && sourceTypeKey === CampaignSource.CUSTOM_FROM_CAMPAIGN) { } else if (!isEdit && sourceTypeKey === CampaignSource.CUSTOM_FROM_CAMPAIGN) {
const campaignsColumns = [ const campaignsColumns = [
@ -759,32 +739,34 @@ export default class CUD extends Component {
{lstsEdit} {lstsEdit}
<Title>{t('sendSettings')}</Title> <hr/>
<CheckBox id="work_send_config_current_namespace" label={t('namespaceFiltering')} text={t('workWithCampaignNamespace')}/> <Fieldset label={t('sendSettings')}>
{useNamespaceSendConfig &&
<TableSelect id="send_configuration" label={t('sendConfiguration')} withHeader dropdown dataUrl={`rest/send-configurations-table-byNamespace/${currentNamespace}`} columns={sendConfigurationsColumns} selectionLabelIndex={1} />
}
{!useNamespaceSendConfig &&
<TableSelect id="send_configuration" label={t('sendConfiguration')} withHeader dropdown dataUrl={`rest/send-configurations-table`} columns={sendConfigurationsColumns} selectionLabelIndex={1} />
}
<TableSelect id="send_configuration" label={t('sendConfiguration')} withHeader dropdown dataUrl='rest/send-configurations-table' columns={sendConfigurationsColumns} selectionLabelIndex={1} />
{sendSettings} {sendSettings}
<InputField id="unsubscribe_url" label={t('customUnsubscribeUrl')}/> <InputField id="unsubscribe_url" label={t('customUnsubscribeUrl')}/>
</Fieldset>
<hr/> <hr/>
<Fieldset label={t('Tracking')}>
<CheckBox id="open_tracking_disabled" text={t('disableOpenedTracking')}/> <CheckBox id="open_tracking_disabled" text={t('disableOpenedTracking')}/>
<CheckBox id="click_tracking_disabled" text={t('disableClickedTracking')}/> <CheckBox id="click_tracking_disabled" text={t('disableClickedTracking')}/>
</Fieldset>
<Title>{t('template')}</Title> {sourceEdit &&
<>
<hr/>
<Fieldset label={t('template')}>
{sourceEdit} {sourceEdit}
</Fieldset>
</>
}
<CheckBox id="work_template_current_namespace" label={t('namespaceFiltering')} text={t('workWithCampaignNamespace')}/>
{templateEdit} {templateEdit}

View file

@ -89,4 +89,6 @@
margin-bottom: 30px; margin-bottom: 30px;
} }
.overrideCheckbox{
margin-top: -8px !important;
}

View file

@ -340,7 +340,7 @@ class CheckBox extends Component {
label: PropTypes.string, label: PropTypes.string,
help: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), help: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
format: PropTypes.string, format: PropTypes.string,
overrideFormat: PropTypes.bool className: PropTypes.string
} }
render() { render() {
@ -348,29 +348,16 @@ class CheckBox extends Component {
const owner = this.getFormStateOwner(); const owner = this.getFormStateOwner();
const id = this.props.id; const id = this.props.id;
const htmlId = 'form_' + id; const htmlId = 'form_' + id;
const overrideFormat = this.props.overrideFormat;
const className = owner.addFormValidationClass('form-check-input', id); const inputClassName = owner.addFormValidationClass('form-check-input', id);
if(overrideFormat){
return wrapInput(id, htmlId, owner, props.format, '', props.label, props.help, return wrapInput(id, htmlId, owner, props.format, '', props.label, props.help,
<div className={styles.overrideCheckboxForm}> <div className={`form-group form-check my-2 ${this.props.className}`}>
<input className={className} type="checkbox" checked={owner.getFormValue(id)} id={htmlId} aria-describedby={htmlId + '_help'} onChange={evt => owner.updateFormValue(id, !owner.getFormValue(id))}/> <input className={inputClassName} type="checkbox" checked={owner.getFormValue(id)} id={htmlId} aria-describedby={htmlId + '_help'} onChange={evt => owner.updateFormValue(id, !owner.getFormValue(id))}/>
<label className={styles.checkboxText} htmlFor={htmlId}>{props.text}</label> <label className={styles.checkboxText} htmlFor={htmlId}>{props.text}</label>
</div> </div>
); );
} }
else{
return wrapInput(id, htmlId, owner, props.format, '', props.label, props.help,
<div className="form-group form-check my-2">
<input className={className} type="checkbox" checked={owner.getFormValue(id)} id={htmlId} aria-describedby={htmlId + '_help'} onChange={evt => owner.updateFormValue(id, !owner.getFormValue(id))}/>
<label className={styles.checkboxText} htmlFor={htmlId}>{props.text}</label>
</div>
);
}
}
} }
@withComponentMixins([ @withComponentMixins([

View file

@ -23,7 +23,6 @@ import {
Button, Button,
DismissibleAlert, DismissibleAlert,
DropdownActionLink, DropdownActionLink,
ButtonDropdown,
Icon Icon
} from "./bootstrap-components"; } from "./bootstrap-components";
import mailtrainConfig import mailtrainConfig
@ -698,4 +697,3 @@ export function getLanguageChooser(t) {
return languageChooser; return languageChooser;
} }

View file

@ -127,12 +127,6 @@
.checkboxText{ .checkboxText{
padding-top: 3px; padding-top: 3px;
} }
.overrideCheckboxForm{
position: relative;
margin-top: -15px;
margin-bottom: 30px;
margin-left: 20px;
}
.dropZone{ .dropZone{
padding-top: 20px; padding-top: 20px;

View file

@ -108,7 +108,7 @@ class Root extends Component {
<ul className="navbar-nav mt-navbar-nav-left"> <ul className="navbar-nav mt-navbar-nav-left">
{topLevelMenu} {topLevelMenu}
<NavDropdown label={t('administration')}> <NavDropdown label={t('administration')}>
{mailtrainConfig.globalPermissions.manageUserList && <DropdownLink to="/users">{t('users')}</DropdownLink>} {mailtrainConfig.globalPermissions.displayManageUsers && <DropdownLink to="/users">{t('users')}</DropdownLink>}
<DropdownLink to="/namespaces">{t('namespaces')}</DropdownLink> <DropdownLink to="/namespaces">{t('namespaces')}</DropdownLink>
{mailtrainConfig.globalPermissions.manageSettings && <DropdownLink to="/settings">{t('globalSettings')}</DropdownLink>} {mailtrainConfig.globalPermissions.manageSettings && <DropdownLink to="/settings">{t('globalSettings')}</DropdownLink>}
<DropdownLink to="/send-configurations">{t('sendConfigurations')}</DropdownLink> <DropdownLink to="/send-configurations">{t('sendConfigurations')}</DropdownLink>

View file

@ -40,6 +40,8 @@ import {
import styles import styles
from "../lib/styles.scss"; from "../lib/styles.scss";
import sendConfigurationsStyles from "./styles.scss";
import mailtrainConfig import mailtrainConfig
from 'mailtrainConfig'; from 'mailtrainConfig';
import {withComponentMixins} from "../lib/decorator-helpers"; import {withComponentMixins} from "../lib/decorator-helpers";
@ -231,13 +233,13 @@ export default class CUD extends Component {
<Fieldset label={t('emailHeader')}> <Fieldset label={t('emailHeader')}>
<InputField id="from_email" label={t('defaultFromEmail')}/> <InputField id="from_email" label={t('defaultFromEmail')}/>
<CheckBox id="from_email_overridable" text={t('overridable')} overrideFormat={true}/> <CheckBox id="from_email_overridable" text={t('overridable')} className={sendConfigurationsStyles.overridableCheckbox}/>
<InputField id="from_name" label={t('defaultFromName')}/> <InputField id="from_name" label={t('defaultFromName')}/>
<CheckBox id="from_name_overridable" text={t('overridable')} overrideFormat={true}/> <CheckBox id="from_name_overridable" text={t('overridable')} className={sendConfigurationsStyles.overridableCheckbox}/>
<InputField id="reply_to" label={t('defaultReplytoEmail')}/> <InputField id="reply_to" label={t('defaultReplytoEmail')}/>
<CheckBox id="reply_to_overridable" text={t('overridable')} overrideFormat={true}/> <CheckBox id="reply_to_overridable" text={t('overridable')} className={sendConfigurationsStyles.overridableCheckbox}/>
<InputField id="subject" label={t('subject')}/> <InputField id="subject" label={t('subject')}/>
<CheckBox id="subject_overridable" text={t('overridable')} overrideFormat={true}/> <CheckBox id="subject_overridable" text={t('overridable')} className={sendConfigurationsStyles.overridableCheckbox}/>
<InputField id="x_mailer" label={t('xMailer')}/> <InputField id="x_mailer" label={t('xMailer')}/>
</Fieldset> </Fieldset>

View file

@ -1,3 +1,7 @@
textarea.dkimPrivateKey { textarea.dkimPrivateKey {
height: 200px; height: 200px;
} }
.overridableCheckbox {
margin-top: -8px !important;
}

View file

@ -231,7 +231,7 @@ roles:
name: Global Master name: Global Master
admin: true admin: true
description: All permissions description: All permissions
permissions: [rebuildPermissions, createJavascriptWithROAccess, manageUserList, manageBlacklist, manageSettings, setupAutomation] permissions: [rebuildPermissions, createJavascriptWithROAccess, displayManageUsers, manageBlacklist, manageSettings, setupAutomation]
rootNamespaceRole: master rootNamespaceRole: master
campaignsAdmin: campaignsAdmin:
name: Campaigns Admin name: Campaigns Admin

View file

@ -64,29 +64,30 @@ function hash(entity, content) {
return hasher.hash(filteredEntity); return hasher.hash(filteredEntity);
} }
async function listDTAjax(context, params) { async function _listDTAjax(context, namespaceId, params) {
return await dtHelpers.ajaxListWithPermissions( return await dtHelpers.ajaxListWithPermissions(
context, context,
[{ entityTypeId: 'campaign', requiredOperations: ['view'] }], [{ entityTypeId: 'campaign', requiredOperations: ['view'] }],
params, params,
builder => builder.from('campaigns') builder => {
builder = builder.from('campaigns')
.innerJoin('namespaces', 'namespaces.id', 'campaigns.namespace') .innerJoin('namespaces', 'namespaces.id', 'campaigns.namespace')
.whereNull('campaigns.parent'), .whereNull('campaigns.parent');
if (namespaceId) {
builder = builder.where('namespaces.id', namespaceId);
}
return builder;
},
['campaigns.id', 'campaigns.name', 'campaigns.cid', 'campaigns.description', 'campaigns.type', 'campaigns.status', 'campaigns.scheduled', 'campaigns.source', 'campaigns.created', 'namespaces.name'] ['campaigns.id', 'campaigns.name', 'campaigns.cid', 'campaigns.description', 'campaigns.type', 'campaigns.status', 'campaigns.scheduled', 'campaigns.source', 'campaigns.created', 'namespaces.name']
); );
} }
async function listDTAjax(context, params) {
return await _listDTAjax(context, undefined, params);
}
async function listByNamespaceDTAjax(context, namespaceId, params) { async function listByNamespaceDTAjax(context, namespaceId, params) {
return await dtHelpers.ajaxListWithPermissions( return await _listDTAjax(context, namespaceId, params);
context,
[{ entityTypeId: 'campaign', requiredOperations: ['view'] }],
params,
builder => builder.from('campaigns')
.innerJoin('namespaces', 'namespaces.id', 'campaigns.namespace')
.where('namespaces.id', namespaceId)
.whereNull('campaigns.parent'),
['campaigns.id', 'campaigns.name', 'campaigns.cid', 'campaigns.description', 'campaigns.type', 'campaigns.status', 'campaigns.scheduled', 'campaigns.source', 'campaigns.created', 'namespaces.name']
);
} }
async function listChildrenDTAjax(context, campaignId, params) { async function listChildrenDTAjax(context, campaignId, params) {
@ -556,7 +557,7 @@ async function updateWithConsistencyCheck(context, entity, content) {
} else if (content === Content.WITHOUT_SOURCE_CUSTOM) { } else if (content === Content.WITHOUT_SOURCE_CUSTOM) {
filteredEntity.data.sourceCustom = existing.data.sourceCustom; filteredEntity.data.sourceCustom = existing.data.sourceCustom;
await namespaceHelpers.validateMove(context, entity, existing, 'campaign', 'createCampaign', 'delete'); //Doesn't works with filteredEntity await namespaceHelpers.validateMove(context, filteredEntity, existing, 'campaign', 'createCampaign', 'delete'); // XXX TB - try with entity
} else if (content === Content.ONLY_SOURCE_CUSTOM) { } else if (content === Content.ONLY_SOURCE_CUSTOM) {
const data = existing.data; const data = existing.data;
@ -743,9 +744,9 @@ async function changeStatusByCampaignCidAndSubscriptionIdTx(tx, context, campaig
]) ])
.first(); .first();
//if (!message) { if (!message) {
throw new Error('Invalid campaign.') throw new Error('Invalid campaign.');
//} }
await _changeStatusByMessageTx(tx, context, message, subscriptionStatus); await _changeStatusByMessageTx(tx, context, message, subscriptionStatus);
} }

View file

@ -26,16 +26,22 @@ function hash(entity) {
} }
async function listDTAjax(context, params) { async function _listDTAjax(context, namespaceId, params) {
const campaignEntityType = entitySettings.getEntityType('campaign'); const campaignEntityType = entitySettings.getEntityType('campaign');
return await dtHelpers.ajaxListWithPermissions( return await dtHelpers.ajaxListWithPermissions(
context, context,
[{ entityTypeId: 'list', requiredOperations: ['view'] }], [{ entityTypeId: 'list', requiredOperations: ['view'] }],
params, params,
builder => builder builder => {
builder = builder
.from('lists') .from('lists')
.innerJoin('namespaces', 'namespaces.id', 'lists.namespace'), .innerJoin('namespaces', 'namespaces.id', 'lists.namespace');
if (namespaceId) {
builder = builder.where('lists.namespace', namespaceId);
}
return builder;
},
['lists.id', 'lists.name', 'lists.cid', 'lists.subscribers', 'lists.description', 'namespaces.name', ['lists.id', 'lists.name', 'lists.cid', 'lists.subscribers', 'lists.description', 'namespaces.name',
{ {
name: 'triggerCount', name: 'triggerCount',
@ -53,32 +59,12 @@ async function listDTAjax(context, params) {
); );
} }
async function listDTAjax(context, params) {
return await _listDTAjax(context, undefined, params);
}
async function listByNamespaceDTAjax(context, namespaceId, params) { async function listByNamespaceDTAjax(context, namespaceId, params) {
const campaignEntityType = entitySettings.getEntityType('campaign'); return await _listDTAjax(context, namespaceId, params);
return await dtHelpers.ajaxListWithPermissions(
context,
[{ entityTypeId: 'list', requiredOperations: ['view'] }],
params,
builder => builder
.from('lists')
.innerJoin('namespaces', 'namespaces.id', 'lists.namespace')
.where('lists.namespace', namespaceId),
['lists.id', 'lists.name', 'lists.cid', 'lists.subscribers', 'lists.description', 'namespaces.name',
{
name: 'triggerCount',
query: builder =>
builder.from('campaigns')
.innerJoin('campaign_lists', 'campaigns.id', 'campaign_lists.campaign')
.innerJoin('triggers', 'campaigns.id', 'triggers.campaign')
.innerJoin(campaignEntityType.permissionsTable, 'campaigns.id', `${campaignEntityType.permissionsTable}.entity`)
.whereRaw('campaign_lists.list = lists.id')
.where(`${campaignEntityType.permissionsTable}.operation`, 'viewTriggers')
.count()
.as('triggerCount')
}
]
);
} }
async function listWithSegmentByCampaignDTAjax(context, campaignId, params) { async function listWithSegmentByCampaignDTAjax(context, campaignId, params) {

View file

@ -22,29 +22,30 @@ function hash(entity) {
return hasher.hash(filterObject(entity, allowedKeys)); return hasher.hash(filterObject(entity, allowedKeys));
} }
async function listDTAjax(context, params) { async function _listDTAjax(context, namespaceId, params) {
return await dtHelpers.ajaxListWithPermissions( return await dtHelpers.ajaxListWithPermissions(
context, context,
[{ entityTypeId: 'sendConfiguration', requiredOperations: ['viewPublic'] }], [{ entityTypeId: 'sendConfiguration', requiredOperations: ['viewPublic'] }],
params, params,
builder => builder builder => {
builder = builder
.from('send_configurations') .from('send_configurations')
.innerJoin('namespaces', 'namespaces.id', 'send_configurations.namespace'), .innerJoin('namespaces', 'namespaces.id', 'send_configurations.namespace');
if (namespaceId) {
builder = builder.where('send_configurations.namespace', namespaceId);
}
return builder;
},
['send_configurations.id', 'send_configurations.name', 'send_configurations.cid', 'send_configurations.description', 'send_configurations.mailer_type', 'send_configurations.created', 'namespaces.name'] ['send_configurations.id', 'send_configurations.name', 'send_configurations.cid', 'send_configurations.description', 'send_configurations.mailer_type', 'send_configurations.created', 'namespaces.name']
); );
} }
async function listDTAjaxByNamespace(context, namespaceId, params) { async function listDTAjax(context, params) {
return await dtHelpers.ajaxListWithPermissions( return await _listDTAjax(context, undefined, params);
context, }
[{ entityTypeId: 'sendConfiguration', requiredOperations: ['viewPublic'] }],
params, async function listByNamespaceDTAjax(context, namespaceId, params) {
builder => builder return await _listDTAjax(context, namespaceId, params);
.from('send_configurations')
.innerJoin('namespaces', 'namespaces.id', 'send_configurations.namespace')
.where('send_configurations.namespace', namespaceId),
['send_configurations.id', 'send_configurations.name', 'send_configurations.cid', 'send_configurations.description', 'send_configurations.mailer_type', 'send_configurations.created', 'namespaces.name']
);
} }
async function listWithSendPermissionDTAjax(context, params) { async function listWithSendPermissionDTAjax(context, params) {
@ -188,7 +189,7 @@ async function getSystemSendConfiguration() {
module.exports.hash = hash; module.exports.hash = hash;
module.exports.listDTAjax = listDTAjax; module.exports.listDTAjax = listDTAjax;
module.exports.listDTAjaxByNamespace = listDTAjaxByNamespace; module.exports.listByNamespaceDTAjax = listByNamespaceDTAjax;
module.exports.listWithSendPermissionDTAjax = listWithSendPermissionDTAjax; module.exports.listWithSendPermissionDTAjax = listWithSendPermissionDTAjax;
module.exports.getByIdTx = getByIdTx; module.exports.getByIdTx = getByIdTx;
module.exports.getById = getById; module.exports.getById = getById;

View file

@ -36,24 +36,28 @@ async function getById(context, id, withPermissions = true) {
}); });
} }
async function listDTAjax(context, params) { async function _listDTAjax(context, namespaceId, params) {
return await dtHelpers.ajaxListWithPermissions( return await dtHelpers.ajaxListWithPermissions(
context, context,
[{ entityTypeId: 'template', requiredOperations: ['view'] }], [{ entityTypeId: 'template', requiredOperations: ['view'] }],
params, params,
builder => builder.from('templates').innerJoin('namespaces', 'namespaces.id', 'templates.namespace'), builder => {
builder = builder.from('templates').innerJoin('namespaces', 'namespaces.id', 'templates.namespace');
if (namespaceId) {
builder = builder.where('namespaces.id', namespaceId);
}
return builder;
},
[ 'templates.id', 'templates.name', 'templates.description', 'templates.type', 'templates.created', 'namespaces.name' ] [ 'templates.id', 'templates.name', 'templates.description', 'templates.type', 'templates.created', 'namespaces.name' ]
); );
} }
async function listByNamespaceDTAjax(context, params, namespaceId) { async function listDTAjax(context, params) {
return await dtHelpers.ajaxListWithPermissions( return await _listDTAjax(context, undefined, params);
context, }
[{ entityTypeId: 'template', requiredOperations: ['view'] }],
params, async function listByNamespaceDTAjax(context, namespaceId, params) {
builder => builder.from('templates').innerJoin('namespaces', 'namespaces.id', 'templates.namespace').where('namespaces.id', namespaceId), return await _listDTAjax(context, namespaceId, params);
[ 'templates.id', 'templates.name', 'templates.description', 'templates.type', 'templates.created', 'namespaces.name' ]
);
} }
async function _validateAndPreprocess(tx, entity) { async function _validateAndPreprocess(tx, entity) {

View file

@ -19,7 +19,7 @@ router.postAsync('/campaigns-others-by-list-table/:campaignId/:listIds', passpor
return res.json(await campaigns.listOthersWhoseListsAreIncludedDTAjax(req.context, castToInteger(req.params.campaignId), req.params.listIds.split(';').map(x => castToInteger(x)), req.body)); return res.json(await campaigns.listOthersWhoseListsAreIncludedDTAjax(req.context, castToInteger(req.params.campaignId), req.params.listIds.split(';').map(x => castToInteger(x)), req.body));
}); });
router.postAsync('/campaigns-namespace/:namespaceId', passport.loggedIn, async (req, res) => { router.postAsync('/campaigns-by-namespace-table/:namespaceId', passport.loggedIn, async (req, res) => {
return res.json(await campaigns.listByNamespaceDTAjax(req.context, castToInteger(req.params.namespaceId), req.body)); return res.json(await campaigns.listByNamespaceDTAjax(req.context, castToInteger(req.params.namespaceId), req.body));
}); });

View file

@ -11,7 +11,7 @@ router.postAsync('/lists-table', passport.loggedIn, async (req, res) => {
return res.json(await lists.listDTAjax(req.context, req.body)); return res.json(await lists.listDTAjax(req.context, req.body));
}); });
router.postAsync('/users-table-byNamespace/:namespaceId', passport.loggedIn, async (req, res) => { router.postAsync('/lists-by-namespace-table/:namespaceId', passport.loggedIn, async (req, res) => {
return res.json(await lists.listByNamespaceDTAjax(req.context, castToInteger(req.params.namespaceId), req.body)); return res.json(await lists.listByNamespaceDTAjax(req.context, castToInteger(req.params.namespaceId), req.body));
}); });

View file

@ -40,8 +40,8 @@ router.postAsync('/send-configurations-table', passport.loggedIn, async (req, re
return res.json(await sendConfigurations.listDTAjax(req.context, req.body)); return res.json(await sendConfigurations.listDTAjax(req.context, req.body));
}); });
router.postAsync('/send-configurations-table-byNamespace/:namespaceId', passport.loggedIn, async (req, res) => { router.postAsync('/send-configurations-by-namespace-table/:namespaceId', passport.loggedIn, async (req, res) => {
return res.json(await sendConfigurations.listDTAjaxByNamespace(req.context, castToInteger(req.params.namespaceId), req.body)); return res.json(await sendConfigurations.listByNamespaceDTAjax(req.context, castToInteger(req.params.namespaceId), req.body));
}); });
router.postAsync('/send-configurations-with-send-permission-table', passport.loggedIn, async (req, res) => { router.postAsync('/send-configurations-with-send-permission-table', passport.loggedIn, async (req, res) => {

View file

@ -35,8 +35,8 @@ router.postAsync('/templates-table', passport.loggedIn, async (req, res) => {
return res.json(await templates.listDTAjax(req.context, req.body)); return res.json(await templates.listDTAjax(req.context, req.body));
}); });
router.postAsync('/templates-table-byNamespace/:namespaceId', passport.loggedIn, async (req, res) => { router.postAsync('/templates-by-namespace-table/:namespaceId', passport.loggedIn, async (req, res) => {
return res.json(await templates.listByNamespaceDTAjax(req.context, req.body, castToInteger(req.params.namespaceId))); return res.json(await templates.listByNamespaceDTAjax(req.context, castToInteger(req.params.namespaceId), req.body));
}); });
router.postAsync('/template-test-send', passport.loggedIn, passport.csrfProtection, async (req, res) => { router.postAsync('/template-test-send', passport.loggedIn, passport.csrfProtection, async (req, res) => {

View file

@ -46,9 +46,9 @@ EOF
exit 1 exit 1
fi fi
#installPrerequisities installPrerequisities
installMailtrain http://localhost:3000 http://localhost:3003 http://localhost:3004 0.0.0.0 false installMailtrain http://localhost:3000 http://localhost:3003 http://localhost:3004 0.0.0.0 false
#installService installService
echo echo
echo "Success!" echo "Success!"
@ -155,11 +155,11 @@ function installMailtrain {
mysqlRoPassword=`pwgen 12 -1` mysqlRoPassword=`pwgen 12 -1`
# Setup MySQL user for Mailtrain # Setup MySQL user for Mailtrain
#mysql -u root -e "CREATE USER 'mailtrain'@'localhost' IDENTIFIED BY '$mysqlPassword';" mysql -u root -e "CREATE USER 'mailtrain'@'localhost' IDENTIFIED BY '$mysqlPassword';"
#mysql -u root -e "GRANT ALL PRIVILEGES ON mailtrain.* TO 'mailtrain'@'localhost';" mysql -u root -e "GRANT ALL PRIVILEGES ON mailtrain.* TO 'mailtrain'@'localhost';"
#mysql -u root -e "CREATE USER 'mailtrain_ro'@'localhost' IDENTIFIED BY '$mysqlRoPassword';" mysql -u root -e "CREATE USER 'mailtrain_ro'@'localhost' IDENTIFIED BY '$mysqlRoPassword';"
#mysql -u root -e "GRANT SELECT ON mailtrain.* TO 'mailtrain_ro'@'localhost';" mysql -u root -e "GRANT SELECT ON mailtrain.* TO 'mailtrain_ro'@'localhost';"
#mysql -u mailtrain --password="$mysqlPassword" -e "CREATE database mailtrain;" mysql -u mailtrain --password="$mysqlPassword" -e "CREATE database mailtrain;"
# Add new user for the mailtrain daemon to run as # Add new user for the mailtrain daemon to run as
useradd mailtrain || true useradd mailtrain || true
@ -181,7 +181,7 @@ www:
mysql: mysql:
password: "asdf1234" password: "$mysqlPassword"
redis: redis:
enabled: true enabled: true
@ -206,7 +206,7 @@ mysql:
password: "$mysqlRoPassword" password: "$mysqlRoPassword"
EOT EOT
#reinstallModules reinstallModules
(cd client && npm run build) (cd client && npm run build)