From f503803ef428c48e07073f676c945b3055060570 Mon Sep 17 00:00:00 2001
From: Alex Arnaud <alex.arnaud@biblibre.com>
Date: Thu, 6 Mar 2025 15:26:05 +0100
Subject: [PATCH] hotline#220612 : UserGroup form : fix getting search_id_site

---
 VERSIONS_HOTLINE/220612                       |  1 +
 .../Controller/Plugin/Manager/UserGroup.php   |  4 +-
 .../UserGroupControllerPostWithSiteTest.php   | 48 +++++++++++++++++++
 3 files changed, 51 insertions(+), 2 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/220612
 create mode 100644 tests/application/modules/admin/controllers/UserGroupControllerPostWithSiteTest.php

diff --git a/VERSIONS_HOTLINE/220612 b/VERSIONS_HOTLINE/220612
new file mode 100644
index 00000000000..804988cf6e0
--- /dev/null
+++ b/VERSIONS_HOTLINE/220612
@@ -0,0 +1 @@
+- correctif #220612 : corrige la récupération du site dans le formulaire des groupes dynamiques 
\ No newline at end of file
diff --git a/library/ZendAfi/Controller/Plugin/Manager/UserGroup.php b/library/ZendAfi/Controller/Plugin/Manager/UserGroup.php
index 980c0dd0f24..6dd1715b041 100644
--- a/library/ZendAfi/Controller/Plugin/Manager/UserGroup.php
+++ b/library/ZendAfi/Controller/Plugin/Manager/UserGroup.php
@@ -204,8 +204,8 @@ class ZendAfi_Controller_Plugin_Manager_UserGroup
                                                                             ZendAfi_Form_Admin_UserGroup::PERMISSION);
 
     $multi_lib_name = (new Class_User_SearchCriteriaMultiLibraries([]))->getName();
-    if (isset($post[$multi_lib_name]))
-      $post[$multi_lib_name] |= 'all';
+    if ( ! ($post[$multi_lib_name] ?? null))
+      $post[$multi_lib_name] = 'all';
 
     unset($post[ZendAfi_Form_Admin_UserGroup::RIGHTS_PERMISSIONS]);
     return $post;
diff --git a/tests/application/modules/admin/controllers/UserGroupControllerPostWithSiteTest.php b/tests/application/modules/admin/controllers/UserGroupControllerPostWithSiteTest.php
new file mode 100644
index 00000000000..57c2a56ce8b
--- /dev/null
+++ b/tests/application/modules/admin/controllers/UserGroupControllerPostWithSiteTest.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Copyright (c) 2012-2024, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+
+class UserGroupControllerPostSiteTest extends Admin_AbstractControllerTestCase
+{
+    public function setUp(): void
+  {
+    parent::setUp();
+    $this->fixture(Class_UserGroup::class,
+                   ['id' => 77,
+                    'protected' => false,
+                    'libelle' => 'Accés aux ressources numériques',
+                    'group_type' => Class_UserGroup::TYPE_DYNAMIC,
+                    'users' => [],
+                    'rights' => []]);
+
+    $this->postDispatch('admin/usergroup/edit/id/77',
+                        ['libelle' => 'Accés aux ressources numériques',
+                         'search_id_site' => '2']);
+  }
+
+
+  /** @test */
+  public function searchIdSiteFilterShouldBeSavedAs2()
+  {
+    $this->assertEquals('2', json_decode(Class_UserGroup::find(77)
+                                           ->getFilters())->search_id_site);
+  }
+}
-- 
GitLab