[TikiWiki-commits] [Git][tikiwiki/tiki][28.x] [BP][FIX] manage_groups.tpl : Correctly encode userGroups and improve group selection logic
"Sammy Ndabo \(@ndabosam084\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <68933e76a5ea9_2cd5e94110dc@gitlab-sidekiq-low-urgency-cpu-bound-v2-7c76c6b777-r5zgm.mail> |
Sammy Ndabo pushed to branch 28.x at Tiki Wiki CMS Groupware / Tiki
Commits:
faf465d6 by Sammy Ndabo at 2025-08-06T11:30:38+00:00
[BP][FIX] manage_groups.tpl : Correctly encode userGroups and improve group selection logic
---
* [BP][FIX] manage_groups.tpl : Correctly encode userGroups and improve group selection logic
---
* [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
(cherry picked from commit 049bda1c205f9a39f5f37fb2f1cec0459f5b80c0)
See merge request tikiwiki/tiki!8208
(cherry picked from commit d16b986572b1b9daff46119fc636dc1895ef7b47)
See merge request tikiwiki/tiki!8209
- - - - -
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);
@@ -54,6 +53,43 @@ $("input[name=add_remove]").on("change", function () {
$("#select_groups").trigger("change.select2");
}
}).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/faf465d6bbb445e729a94ed6ba5307885f2cc57b
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/faf465d6bbb445e729a94ed6ba5307885f2cc57b
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