| Server IP : 185.252.147.100 / Your IP : 216.73.217.33 Web Server : nginx/1.27.3 System : Linux mitrofanov.ru 6.1.0-37-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.140-1 (2025-05-22) x86_64 User : mitr ( 1000) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /www/html/kanboard/app/Core/User/ |
Upload File : |
<?php
namespace Kanboard\Core\User;
use Kanboard\Core\Base;
/**
* Group Synchronization
*
* @package user
* @author Frederic Guillot
*/
class GroupSync extends Base
{
/**
* Synchronize group membership
*
* @access public
* @param integer $userId
* @param string[] $externalGroupIds
*/
public function synchronize($userId, array $externalGroupIds)
{
$userGroups = $this->groupMemberModel->getGroups($userId);
$this->addGroups($userId, $userGroups, $externalGroupIds);
$this->removeGroups($userId, $userGroups, $externalGroupIds);
}
/**
* Add missing groups to the user
*
* @access protected
* @param integer $userId
* @param array $userGroups
* @param string[] $externalGroupIds
*/
protected function addGroups($userId, array $userGroups, array $externalGroupIds)
{
$userGroupIds = array_column($userGroups, 'external_id', 'external_id');
$externalGroups = $this->groupModel->getByExternalIds($externalGroupIds);
foreach ($externalGroups as $externalGroup) {
if (! isset($userGroupIds[$externalGroup['external_id']])) {
$this->groupMemberModel->addUser($externalGroup['id'], $userId);
}
}
}
/**
* Remove groups from the user
*
* @access protected
* @param integer $userId
* @param array $userGroups
* @param string[] $externalGroupIds
*/
protected function removeGroups($userId, array $userGroups, array $externalGroupIds)
{
foreach ($userGroups as $userGroup) {
if (! empty($userGroup['external_id']) && ! in_array($userGroup['external_id'], $externalGroupIds)) {
$this->groupMemberModel->removeUser($userGroup['id'], $userId);
}
}
}
}