mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 07:46:23 -04:00
New template button takes user to new template page
for all services that only allow sending one type of notifications
This commit is contained in:
@@ -153,19 +153,20 @@
|
|||||||
return changed;
|
return changed;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$broadcastService = (document.querySelector('div[id=add_new_template_form]')).getAttribute("data-broadcast")
|
this.$singleNotificationChannel = (document.querySelector('div[id=add_new_template_form]')).getAttribute("data-channel");
|
||||||
|
this.$singleChannelService = (document.querySelector('div[id=add_new_template_form]')).getAttribute("data-service");
|
||||||
|
|
||||||
this.actionButtonClicked = function(event) {
|
this.actionButtonClicked = function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.currentState = $(event.currentTarget).val();
|
this.currentState = $(event.currentTarget).val();
|
||||||
|
|
||||||
if (event.currentTarget.value === 'add-new-template' && this.$broadcastService) {
|
if (event.currentTarget.value === 'add-new-template' && this.$singleNotificationChannel) {
|
||||||
return window.location = "/services/" + this.$broadcastService + "/templates/add-broadcast";
|
window.location = "/services/" + this.$singleChannelService + "/templates/add-" + this.$singleNotificationChannel;
|
||||||
} else {
|
} else {
|
||||||
if (this.stateChanged()) {
|
if (this.stateChanged()) {
|
||||||
this.render();
|
this.render();
|
||||||
};
|
}
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.selectionStatus = {
|
this.selectionStatus = {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ from app.models.service import Service
|
|||||||
from app.models.template_list import TemplateList, TemplateLists
|
from app.models.template_list import TemplateList, TemplateLists
|
||||||
from app.template_previews import TemplatePreview, get_page_count_for_letter
|
from app.template_previews import TemplatePreview, get_page_count_for_letter
|
||||||
from app.utils import (
|
from app.utils import (
|
||||||
|
NOTIFICATION_TYPES,
|
||||||
get_template,
|
get_template,
|
||||||
should_skip_template_page,
|
should_skip_template_page,
|
||||||
user_has_permissions,
|
user_has_permissions,
|
||||||
@@ -130,6 +131,11 @@ def choose_template(service_id, template_type='all', template_folder_id=None):
|
|||||||
)
|
)
|
||||||
option_hints = {template_folder_id: 'current folder'}
|
option_hints = {template_folder_id: 'current folder'}
|
||||||
|
|
||||||
|
single_notification_channel = None
|
||||||
|
notification_channels = list(set(current_service.permissions).intersection(NOTIFICATION_TYPES))
|
||||||
|
if len(notification_channels) == 1:
|
||||||
|
single_notification_channel = notification_channels[0]
|
||||||
|
|
||||||
if request.method == 'POST' and templates_and_folders_form.validate_on_submit():
|
if request.method == 'POST' and templates_and_folders_form.validate_on_submit():
|
||||||
if not current_user.has_permissions('manage_templates'):
|
if not current_user.has_permissions('manage_templates'):
|
||||||
abort(403)
|
abort(403)
|
||||||
@@ -168,6 +174,7 @@ def choose_template(service_id, template_type='all', template_folder_id=None):
|
|||||||
templates_and_folders_form=templates_and_folders_form,
|
templates_and_folders_form=templates_and_folders_form,
|
||||||
move_to_children=templates_and_folders_form.move_to.children(),
|
move_to_children=templates_and_folders_form.move_to.children(),
|
||||||
user_has_template_folder_permission=user_has_template_folder_permission,
|
user_has_template_folder_permission=user_has_template_folder_permission,
|
||||||
|
single_notification_channel=single_notification_channel,
|
||||||
option_hints=option_hints
|
option_hints=option_hints
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
{{ page_footer('Add new folder', button_name='operation', button_value='add-new-folder') }}
|
{{ page_footer('Add new folder', button_name='operation', button_value='add-new-folder') }}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div id="add_new_template_form" {% if current_service.has_permission('broadcast') %}data-broadcast="{{current_service.id}}"{% endif %}>
|
<div id="add_new_template_form" {% if single_notification_channel %}data-channel="{{single_notification_channel}}" data-service="{{current_service.id}}"{% endif %}>
|
||||||
<div class="js-will-stick-at-bottom-when-scrolling">
|
<div class="js-will-stick-at-bottom-when-scrolling">
|
||||||
{{ radios(templates_and_folders_form.add_template_by_template_type) }}
|
{{ radios(templates_and_folders_form.add_template_by_template_type) }}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ FAILURE_STATUSES = ['failed', 'temporary-failure', 'permanent-failure',
|
|||||||
'technical-failure', 'virus-scan-failed', 'validation-failed']
|
'technical-failure', 'virus-scan-failed', 'validation-failed']
|
||||||
REQUESTED_STATUSES = SENDING_STATUSES + DELIVERED_STATUSES + FAILURE_STATUSES
|
REQUESTED_STATUSES = SENDING_STATUSES + DELIVERED_STATUSES + FAILURE_STATUSES
|
||||||
|
|
||||||
|
NOTIFICATION_TYPES = ["sms", "email", "letter", "broadcast"]
|
||||||
|
|
||||||
|
|
||||||
with open('{}/email_domains.txt'.format(
|
with open('{}/email_domains.txt'.format(
|
||||||
os.path.dirname(os.path.realpath(__file__))
|
os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const helpers = require('./support/helpers');
|
const helpers = require('./support/helpers');
|
||||||
|
|
||||||
function setFixtures (hierarchy) {
|
function setFixtures (hierarchy, newTemplateDataModules = "") {
|
||||||
|
|
||||||
const foldersCheckboxesHTML = function (filter) {
|
const foldersCheckboxesHTML = function (filter) {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
@@ -27,7 +27,7 @@ function setFixtures (hierarchy) {
|
|||||||
|
|
||||||
}();
|
}();
|
||||||
|
|
||||||
function controlsHTML () {
|
function controlsHTML (newTemplateDataModules) {
|
||||||
|
|
||||||
return `<div id="sticky_template_forms">
|
return `<div id="sticky_template_forms">
|
||||||
<button type="submit" name="operation" value="unknown" hidden=""></button>
|
<button type="submit" name="operation" value="unknown" hidden=""></button>
|
||||||
@@ -78,7 +78,7 @@ function setFixtures (hierarchy) {
|
|||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div id="add_new_template_form">
|
<div id="add_new_template_form" ${newTemplateDataModules}>
|
||||||
<div class="js-will-stick-at-bottom-when-scrolling">
|
<div class="js-will-stick-at-bottom-when-scrolling">
|
||||||
<div class="form-group ">
|
<div class="form-group ">
|
||||||
<fieldset id="add_template_by_template_type">
|
<fieldset id="add_template_by_template_type">
|
||||||
@@ -127,7 +127,7 @@ function setFixtures (hierarchy) {
|
|||||||
document.body.innerHTML = `
|
document.body.innerHTML = `
|
||||||
<form method="post" data-module="template-folder-form">
|
<form method="post" data-module="template-folder-form">
|
||||||
${helpers.templatesAndFoldersCheckboxes(hierarchy)}
|
${helpers.templatesAndFoldersCheckboxes(hierarchy)}
|
||||||
${controlsHTML()}
|
${controlsHTML(newTemplateDataModules)}
|
||||||
</form>`;
|
</form>`;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -309,6 +309,37 @@ describe('TemplateFolderForm', () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Click 'New template' for single channel service", () => {
|
||||||
|
test("should redirect to new template page", () => {
|
||||||
|
setFixtures(hierarchy, "data-channel='sms' data-service='123'")
|
||||||
|
templateFolderForm = document.querySelector('form[data-module=template-folder-form]');
|
||||||
|
|
||||||
|
// start module
|
||||||
|
window.GOVUK.modules.start();
|
||||||
|
|
||||||
|
formControls = templateFolderForm.querySelector('#sticky_template_forms');
|
||||||
|
|
||||||
|
// reset sticky JS mocks called when the module starts
|
||||||
|
resetStickyMocks();
|
||||||
|
// add listener for url change
|
||||||
|
const descriptor1 = Object.getOwnPropertyDescriptor(window, 'location');
|
||||||
|
delete window.location
|
||||||
|
|
||||||
|
const mockCallback = jest.fn(x => {});
|
||||||
|
|
||||||
|
Object.defineProperty(window, 'location', {
|
||||||
|
set: mockCallback
|
||||||
|
});
|
||||||
|
// click
|
||||||
|
helpers.triggerEvent(formControls.querySelector('[value=add-new-template]'), 'click');
|
||||||
|
// expect url to change
|
||||||
|
expect(mockCallback).toHaveBeenCalledWith("/services/123/templates/add-sms")
|
||||||
|
|
||||||
|
setFixtures(hierarchy)
|
||||||
|
resetStickyMocks()
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
describe("Clicking 'New template'", () => {
|
describe("Clicking 'New template'", () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user