[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] manage_groups.tpl : Correctly encode userGroups and improve group selection logic
Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <68925c31b2be1_2cd5cc897314@gitlab-sidekiq-low-urgency-cpu-bound-v2-6b9b65f69d-fkxg8.mail> |
Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
049bda1c by Sammy Ndabo at 2025-08-05T19:23:43+00:00
[FIX] manage_groups.tpl : Correctly encode userGroups and improve group selection logic
---
* Revert "[FIX] wikiplugin_tracker: Allow not having a preview button"
This reverts commit f2fc77d7e8fe9bdb4dea06d0fe705d52d4312222.
* [FIX] Manage groups: Correctly encode userGroups and improve group selection logic
* [FIX] wikiplugin_tracker: Allow not having a preview button
See merge request tikiwiki/tiki!8038
- - - - -
2 changed files:
- lib/core/Services/User/Controller.php
- templates/user/manage_groups.tpl
Changes:
=====================================
lib/core/Services/User/Controller.php
=====================================
@@ -589,7 +589,7 @@ class Services_User_Controller
'fields' => $extraFields
],
'modal' => '1',
- 'userGroups' => str_replace(['\'','&'], ['%39;','%26'], json_encode($userGroups)),
+ 'userGroups' => json_encode($userGroups),
];
}
} else {
=====================================
templates/user/manage_groups.tpl
=====================================
@@ -25,7 +25,7 @@
<label for="select_groups" class="col-form-label">
{tr}These groups:{/tr}
</label>
- <select name="checked_groups[]" multiple="multiple" size="{$countgrps}" class="form-control" id="select_groups" data-usergroups='{$userGroups}'>
+ <select name="checked_groups[]" multiple="multiple" size="{$countgrps}" class="form-control" id="select_groups" data-usergroups="{$userGroups|escape}">
{section name=ix loop=$all_groups}
{if $all_groups[ix] != 'Anonymous' && $all_groups[ix] != 'Registered'}
<option value="{$all_groups[ix]|escape}">{$all_groups[ix]|escape}</option>
@@ -39,11 +39,10 @@
{/if}
{jq}
$("input[name=add_remove]").on("change", function () {
- var userGroups = $("#select_groups").data("usergroups"), mode = false;
+ const userGroups = $("#select_groups").data("usergroups");
+ const mode = $("input[name=add_remove]:checked").val() === "add";
if ($(this).prop("checked") && userGroups) {
- if ($(this).val() === "add") { // filter the group list to ones this user is not in
- mode = true;
- }
+ // filter the group list to ones this user is not in
$("option", "#select_groups").each(function () {
if ($.inArray($(this).val(), userGroups) > -1) {
$(this).prop("disabled", mode).css("opacity", mode ? .3 : 1);
@@ -53,6 +52,43 @@ $("input[name=add_remove]").on("change", function () {
});
}
}).trigger("change");
+
+$("#select_groups").on("change", function () {
+ const mode = $("input[name=add_remove]:checked").val() === "add";
+ const $defaultGroup = $("#default_group");
+
+ const userGroups = $("#select_groups").data("usergroups");
+ const selectedGroups = $(this).val();
+ let setAndSelectedGroups = [];
+ if (mode) {
+ setAndSelectedGroups = [...userGroups, ...selectedGroups];
+ } else {
+ setAndSelectedGroups = [...selectedGroups];
+ }
+
+ // add or remove selected groups from default group
+ setAndSelectedGroups.forEach(function (group) {
+ const pattern = group;
+ const $matches = $defaultGroup.find("option").filter(function() {
+ // groups can contains single and/or double quotes so use regex
+ return $(this).val() === pattern;
+ });
+
+ if (mode && $matches.length === 0) {
+ $defaultGroup.prepend($("<option>").val(group).text(group));
+ } else if (! mode && $matches.length > 0) {
+ $matches.remove();
+ }
+ });
+
+ if (mode) {
+ $defaultGroup.find("option").each(function () {
+ if (setAndSelectedGroups.indexOf($(this).val()) === -1) {
+ $(this).remove();
+ }
+ });
+ }
+});
{/jq}
</div>
<div class="mb-3 row mx-0" >
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/049bda1c205f9a39f5f37fb2f1cec0459f5b80c0
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/049bda1c205f9a39f5f37fb2f1cec0459f5b80c0
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs