Commit 456d1f86 authored by Patrick Barroca's avatar Patrick Barroca 🐧

Merge branch…

Merge branch 'hotline#108358_gestion_des_groupes_abonnement_valide_pas_pris_en_compte' into 'hotline'

hotline #108358 : manuel link to dynamic user groups are ignored

See merge request !3447
parents a3d3d130 db1bfdb3
Pipeline #9742 passed with stage
in 42 minutes and 35 seconds
- ticket #108358 : Gestion des groupes : Les affectations manuelles à des groupes dynamiques ne sont plus supportées
\ No newline at end of file
......@@ -305,8 +305,9 @@ class Class_UserGroup extends Storm_Model_Abstract {
* @return array
*/
public function getUsers() {
return $this->isManual() ?
parent::_get('users') : $this->getDynamicUsers();
return $this->isManual()
? parent::_get('users')
: $this->getDynamicUsers();
}
......
......@@ -811,8 +811,7 @@ class Class_Users extends Storm_Model_Abstract {
*/
public function getUserGroupsIds() {
$groups = $this->getUserGroups();
return array_map(
function($group) { return $group->getId();},
return array_map(function($group) { return $group->getId();},
$groups);
}
......@@ -828,7 +827,11 @@ class Class_Users extends Storm_Model_Abstract {
* @return array
*/
public function getUserGroups() {
return array_merge(parent::_get('user_groups'),
return array_merge(array_filter(parent::_get('user_groups'),
function($group)
{
return !$group->isDynamic();
}),
$this->getDynamicUserGroups());
}
......
......@@ -78,10 +78,14 @@ class ZendAfi_Controller_Plugin_Manager_User extends ZendAfi_Controller_Plugin_M
protected function _getPost($key = null, $default = null) {
$post = $this->_request->getPost();
$post['user_groups'] = array_filter(
array_map(function($id) { return Class_UserGroup::find((int)$id);},
explode('-', $this->_getParam('user_group_ids','')))
);
$mapper = function($id) {
return ($group = Class_UserGroup::find((int)$id)) && !$group->isDynamic()
? $group
: null;
};
$post['user_groups'] = array_filter(array_map($mapper,
explode('-', $this->_getParam('user_group_ids',''))));
$post['date_fin'] = isset($post['date_fin']) && trim($post['date_fin'])
? Class_Date::frToIso(trim($post['date_fin']))
......
......@@ -2198,4 +2198,59 @@ class UsersControllerMassDeleteRunStepMatchingSuperAdminUserTest
$this->assertEquals(2, $json->done);
$this->assertEquals(2, $json->total);
}
}
\ No newline at end of file
}
/** @see http://forge.afi-sa.fr/issues/108358#note-9 */
class UsersControllerPostEditWithDynamicGroupTest extends Admin_UsersControllerEditAdminTestCase {
public function setUp() {
parent::setUp();
$this->fixture('Class_UserGroup',
['id' => 33,
'group_type' => Class_UserGroup::TYPE_DYNAMIC]);
$this->fixture('Class_UserGroup',
['id' => 34,
'group_type' => Class_UserGroup::TYPE_MANUAL]);
Class_Crypt::setPhpCommand(null);
$this->postDispatch('/admin/users/edit/id/10', ['login' => 'Tom',
'password' => 'tutu',
'nom' => 'Davis',
'prenom' => 'Miles',
'pseudo' => 'Dave',
'mail' => 'mdavis@free.fr',
'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL,
'id_site' => '7',
'idabon' => '2341',
'ordreabon' => '2',
'telephone' => '',
'adresse' => '12 rue miles',
'code_postal' => '75000',
'ville' => 'Paris',
'civilite' => 1,
'mobile' => '',
'naissance' => '1976-02-17',
'date_debut' => '',
'date_fin' => '14/10/2015',
'user_group_ids' => '33-34',
'redmine_library' => '15']);
}
/** @test */
public function membershipShouldNotBeCreatedForDynamicGroup() {
$this->assertNull(Class_UserGroupMembership::findFirstBy(['user_id' => 10,
'user_group_id' => 33]));
}
/** @test */
public function membershipShouldBeCreatedForManualGroup() {
$this->assertNotNull(Class_UserGroupMembership::findFirstBy(['user_id' => 10,
'user_group_id' => 34]));
}
}
......@@ -170,8 +170,24 @@ class DynamicUserGroupModoBibTest extends DynamicUserGroupTestCase {
['id' => 13,
'libelle' => 'Abonnés',
'group_type' => Class_UserGroup::TYPE_DYNAMIC,
'filters' => json_encode(['search_valid_subscription' => 1
])]);
'filters' => json_encode(['search_role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
'search_valid_subscription' => 1])]);
// @see http://forge.afi-sa.fr/issues/108358#note-9, manually linked to dynamic
$this->_max = $this->fixture('Class_Users',
['id' => 32,
'login' => 'max',
'password' => 'zemenace',
'id_site' => 1,
'idabon' => '88308ID',
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB,
'date_fin' => '2019-01-01',
'user_group_memberships' => [$this->fixture('Class_UserGroupMembership',
['id' => 1000,
'user_id' => 32,
'user_group_id' => 13])],
]);
;
$this->_late_subscribers = $this
->fixture('Class_UserGroup',
......@@ -293,6 +309,7 @@ class DynamicUserGroupModoBibTest extends DynamicUserGroupTestCase {
['_gontran', '_adults'],
['_shella', '_abonnes'],
['_gontran', '_abonnes'],
['_max', '_abonnes'],
];
}
......@@ -322,6 +339,7 @@ class DynamicUserGroupModoBibTest extends DynamicUserGroupTestCase {
['_gontran', '_subscription_ended'],
['_shella', '_adults'],
['_gontran', '_minors'],
['_max', '_subscribers'],
];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment