Skip to content

Commit

Permalink
Merge branch 'pu/ps/246896' into '2024.11'
Browse files Browse the repository at this point in the history
fix(Tinebase/User/AD): user id must be set for addGroupMemberInSyncBackend

See merge request tine20/tine20!6569
  • Loading branch information
pschuele committed Feb 11, 2025
2 parents 701870c + f44a27d commit cf2b169
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions tests/tine20/Tinebase/Auth/MFATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ public function testGenericSmsAdapter()

public function testWebAuthNPwdLessLogin(): void
{
$this->_skipIfLDAPBackend('fails with TypeError in \Tinebase_Model_MFA_UserConfig::updateUserOldRecordCallback');

$this->_originalTestUser->mfa_configs = new Tinebase_Record_RecordSet(
Tinebase_Model_MFA_UserConfig::class, [[
Tinebase_Model_MFA_UserConfig::FLD_ID => 'unittest',
Expand Down
6 changes: 4 additions & 2 deletions tine20/Tinebase/User/ActiveDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ public function addUserToSyncBackend(Tinebase_Model_FullUser $_user)

// add user to primary group and set primary group
/** @noinspection PhpUndefinedMethodInspection */
Tinebase_Group::getInstance()->addGroupMemberInSyncBackend(Tinebase_Config::getInstance()->{Tinebase_Config::USERBACKEND}->{Tinebase_Config::SYNCOPTIONS}->{Tinebase_Config::SYNC_DEVIATED_PRIMARY_GROUP_UUID} ?: $_user->accountPrimaryGroup, $_user, false);
Tinebase_Group::getInstance()->addGroupMemberInSyncBackend(Tinebase_Config::getInstance()->
{Tinebase_Config::USERBACKEND}->{Tinebase_Config::SYNCOPTIONS}->{Tinebase_Config::SYNC_DEVIATED_PRIMARY_GROUP_UUID}
?: $_user->accountPrimaryGroup, $userId, false);

// set primary group id
$this->_ldap->updateProperty($dn, array('primarygroupid' => $primaryGroupId));

$user = $this->getUserByPropertyFromSyncBackend('accountId', $_user, 'Tinebase_Model_FullUser');
$user = $this->getUserByPropertyFromSyncBackend('accountId', $userId, 'Tinebase_Model_FullUser');

if (Tinebase_Config::getInstance()->{Tinebase_Config::USERBACKEND}->{Tinebase_Config::SYNCOPTIONS}->{Tinebase_Config::PWD_CANT_CHANGE}) {
$user->accountId = $_user->accountId;
Expand Down
9 changes: 7 additions & 2 deletions tine20/Tinebase/User/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public function getLdap()
}

/**
* get user by login name
* get user by given property
*
* @param string $_property
* @param string $_accountId
Expand All @@ -364,8 +364,13 @@ public function getUserByPropertyFromSyncBackend($_property, $_accountId, $_acco
throw new Tinebase_Exception_NotFound("can't get user by property $_property. property not supported by ldap backend.");
}

// TODO this seems not to be correct - only do this in certain cases?
if ('accountId' === $_property && ! $_accountId instanceof Tinebase_Model_FullUser) {
$_accountId = $this->getFullUserById($_accountId);
try {
$_accountId = $this->getFullUserById($_accountId);
} catch (Tinebase_Exception_NotFound $tenf) {
// user might not exist, yet (i.e. was just added via \Tinebase_User_ActiveDirectory::addUserToSyncBackend)
}
}
$ldapEntry = $this->_getLdapEntry($_property, $_accountId);

Expand Down

0 comments on commit cf2b169

Please sign in to comment.