From d9c7fc7053584b24c8a2f3cd561f107ed20e1372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C4=9F=C4=B1zhan?= Date: Sat, 13 Sep 2025 03:08:20 +0300 Subject: [PATCH] tomselect: Automatically grab the CSRF token from the API wrapper (#2899) * Automatically grab the CSRF token from the API wrapper * Removed data-csrf fields --- .../Invoice/html_admin/mod_invoice_index.html.twig | 6 ++---- .../html_admin/mod_invoice_subscriptions.html.twig | 3 +-- .../html_admin/mod_massmailer_index.html.twig | 3 +-- .../Order/html_admin/mod_order_index.html.twig | 1 - .../mod_support_canned_selector.html.twig | 1 - .../html_admin/mod_support_tickets.html.twig | 3 +-- src/themes/admin_default/assets/js/tomselect.js | 14 +++----------- 7 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/modules/Invoice/html_admin/mod_invoice_index.html.twig b/src/modules/Invoice/html_admin/mod_invoice_index.html.twig index 05a7245ea..02d84754f 100644 --- a/src/modules/Invoice/html_admin/mod_invoice_index.html.twig +++ b/src/modules/Invoice/html_admin/mod_invoice_index.html.twig @@ -32,8 +32,7 @@ placeholder="{{ 'Start typing the client name or ID'|trans }}" id="client_id" name="client_id" - data-resturl="admin/client/get_pairs" - data-csrf="{{ CSRFToken }}"> + data-resturl="admin/client/get_pairs"> {% if not request.client_id %} {% else %} {% set client = admin.client_get({ 'id': request.client_id }) %} @@ -303,8 +302,7 @@ placeholder="{{ 'Start typing the client name or ID'|trans }}" id="client_id" name="client_id" - data-resturl="admin/client/get_pairs" - data-csrf="{{ CSRFToken }}"> + data-resturl="admin/client/get_pairs"> {% else %} {% set client = admin.client_get({ 'id': request.client_id }) %} diff --git a/src/modules/Invoice/html_admin/mod_invoice_subscriptions.html.twig b/src/modules/Invoice/html_admin/mod_invoice_subscriptions.html.twig index 01327074c..53e70ee69 100644 --- a/src/modules/Invoice/html_admin/mod_invoice_subscriptions.html.twig +++ b/src/modules/Invoice/html_admin/mod_invoice_subscriptions.html.twig @@ -106,8 +106,7 @@ placeholder="{{ 'Start typing the client name or ID'|trans }}" id="client_id" name="client_id" - data-resturl="admin/client/get_pairs" - data-csrf="{{ CSRFToken }}"> + data-resturl="admin/client/get_pairs"> {% else %} {% set client = admin.client_get({ 'id': request.client_id }) %} diff --git a/src/modules/Massmailer/html_admin/mod_massmailer_index.html.twig b/src/modules/Massmailer/html_admin/mod_massmailer_index.html.twig index 870caa23a..15e2581e2 100644 --- a/src/modules/Massmailer/html_admin/mod_massmailer_index.html.twig +++ b/src/modules/Massmailer/html_admin/mod_massmailer_index.html.twig @@ -127,8 +127,7 @@ placeholder="{{ 'Start typing the client name or ID'|trans }}" id="test_client_id" name="test_client_id" - data-resturl="admin/client/get_pairs" - data-csrf="{{ CSRFToken }}"> + data-resturl="admin/client/get_pairs"> {% else %} {% set test_client = admin.client_get({ 'id': request.test_client_id }) %} diff --git a/src/modules/Order/html_admin/mod_order_index.html.twig b/src/modules/Order/html_admin/mod_order_index.html.twig index 1a719f5fc..ad66e01c2 100644 --- a/src/modules/Order/html_admin/mod_order_index.html.twig +++ b/src/modules/Order/html_admin/mod_order_index.html.twig @@ -282,7 +282,6 @@ id="client_id" name="client_id" data-resturl="admin/client/get_pairs" - data-csrf="{{ CSRFToken }}" required aria-required="true"> {% else %} diff --git a/src/modules/Support/html_admin/mod_support_canned_selector.html.twig b/src/modules/Support/html_admin/mod_support_canned_selector.html.twig index c0ff51c80..13292027a 100644 --- a/src/modules/Support/html_admin/mod_support_canned_selector.html.twig +++ b/src/modules/Support/html_admin/mod_support_canned_selector.html.twig @@ -2,7 +2,6 @@ name="canned_response" placeholder="Canned Responses" class="canned_ticket_response" - data-csrf="{{CSRFToken}}" data-resturl="admin/support/canned_get" > {% for ctitle, cat in admin.support_canned_pairs %} diff --git a/src/modules/Support/html_admin/mod_support_tickets.html.twig b/src/modules/Support/html_admin/mod_support_tickets.html.twig index 8082ed6e9..8e77653bb 100644 --- a/src/modules/Support/html_admin/mod_support_tickets.html.twig +++ b/src/modules/Support/html_admin/mod_support_tickets.html.twig @@ -299,8 +299,7 @@ placeholder="{{ 'Start typing the client name or ID'|trans }}" id="client_id" name="client_id" - data-resturl="admin/client/get_pairs" - data-csrf="{{ CSRFToken }}"> + data-resturl="admin/client/get_pairs"> {% else %} {% set client = admin.client_get({ 'id': request.client_id }) %} diff --git a/src/themes/admin_default/assets/js/tomselect.js b/src/themes/admin_default/assets/js/tomselect.js index 14dc4e14c..74e8877a8 100644 --- a/src/themes/admin_default/assets/js/tomselect.js +++ b/src/themes/admin_default/assets/js/tomselect.js @@ -58,14 +58,9 @@ document.addEventListener('DOMContentLoaded', () => { searchField: ["label", "value"], load: (query, callback) => { let items; - let restUrl = new URL( - bb.restUrl(autocompleteSelectorEl.dataset.resturl) - ); + let restUrl = new URL(bb.restUrl(autocompleteSelectorEl.dataset.resturl)); restUrl.searchParams.append("search", query); - restUrl.searchParams.append( - "CSRFToken", - autocompleteSelectorEl.dataset.csrf - ); + restUrl.searchParams.append("CSRFToken", Tools.getCSRFToken()); restUrl.searchParams.append("per_page", 5); fetch(restUrl) .then((response) => response.json()) @@ -106,10 +101,7 @@ document.addEventListener('DOMContentLoaded', () => { bb.restUrl(cannedResponseSelectorEl.dataset.resturl) ); restUrl.searchParams.append('id', value); - restUrl.searchParams.append( - 'CSRFToken', - cannedResponseSelectorEl.dataset.csrf, - ); + restUrl.searchParams.append('CSRFToken', Tools.getCSRFToken()); fetch(restUrl) .then((response) => response.json()) .then((json) => {