From c8c46eaa392ab255479717b9b1e2c1c804817088 Mon Sep 17 00:00:00 2001 From: Thorsten Rinne Date: Mon, 13 Jan 2025 19:17:57 +0100 Subject: [PATCH] fix: corrected check to selected FAQ permissions from group and category (#3330) --- phpmyfaq/admin/assets/src/content/faqs.js | 48 +++++++++++------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/phpmyfaq/admin/assets/src/content/faqs.js b/phpmyfaq/admin/assets/src/content/faqs.js index 28b38b1dea..ced0972c41 100644 --- a/phpmyfaq/admin/assets/src/content/faqs.js +++ b/phpmyfaq/admin/assets/src/content/faqs.js @@ -12,6 +12,7 @@ * @link https://www.phpmyfaq.de * @since 2022-07-22 */ + import { deleteAttachments } from '../api/attachment'; import { pushNotification } from '../utils'; @@ -59,8 +60,7 @@ export const handleFaqForm = () => { const categoryOptions = document.querySelector('#phpmyfaq-categories'); if (categoryOptions) { - let categories = Array.from(categoryOptions.selectedOptions).map(({ value }) => value); - + Array.from(categoryOptions.selectedOptions).map(({ value }) => value); // Override FAQ permissions with Category permission to avoid confused users categoryOptions.addEventListener('click', (event) => { event.preventDefault(); @@ -101,33 +101,31 @@ const setPermissions = (permissions) => { } // Groups - if (-1 === parseInt(perms.group[0])) { - document.getElementById('restrictedgroups').checked = false; - document.getElementById('restrictedgroups').disabled = false; - document.getElementById('allgroups').checked = true; - document.getElementById('allgroups').disabled = false; - } else { - document.getElementById('allgroups').checked = false; - document.getElementById('allgroups').disabled = true; - document.getElementById('restrictedgroups').checked = true; - document.getElementById('restrictedgroups').disabled = false; - perms.group.forEach((value) => { - document.querySelector(`#selected-groups option[value='${value}']`).selected = true; + const restrictedGroups = document.getElementById('restrictedgroups'); + if (restrictedGroups) { + const options = document.querySelectorAll('#restrictedgroups option'); + const allGroups = document.getElementById('allgroups'); + options.forEach((option) => { + option.removeAttribute('selected'); }); + if (-1 === parseInt(perms.group[0])) { + restrictedGroups.checked = false; + restrictedGroups.disabled = false; + allGroups.checked = true; + allGroups.disabled = false; + } else { + allGroups.checked = false; + allGroups.disabled = true; + restrictedGroups.checked = true; + restrictedGroups.disabled = false; + perms.group.forEach((value) => { + const optionSelected = document.querySelector(`#restrictedgroups option[value='${value}']`); + optionSelected.setAttribute('selected', 'selected'); + }); + } } }; -const getFaqPermissions = (faqId) => { - const csrfToken = document.getElementById('csrf').value; - fetch(`./api/faq/permissions/${faqId}`) - .then((response) => { - return response.json(); - }) - .then((permissions) => { - setPermissions(permissions); - }); -}; - const checkForHash = () => { const questionInputValue = document.getElementById('question').value; const questionHelp = document.getElementById('questionHelp');