Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4dbad921 authored by theronakpatel's avatar theronakpatel
Browse files

check at isusernametaken function

parent 6347ca61
Loading
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -122,10 +122,12 @@ class SyncMissingUsersToCommon extends Command {

		$this->userManager->callForAllUsers(function (IUser $user) use ($ipAddress, $isDryRun, $output, &$stats) {
			$username = $user->getUID();
			
			// Get user metadata from LDAP to obtain usernameWithoutDomain
			$userMetadata = $this->ldapConnectionService->getUserMetadata($username);
			$usernameWithoutDomain = $userMetadata['usernameWithoutDomain'] ?? $username;
			// Check if user is missing from common database
			// Strip legacy domain from username before checking in common DB
			$usernameWithoutDomain = $this->userService->stripLegacyDomainFromUsername($username);
			if ($this->userService->isUsernameTaken($usernameWithoutDomain)) {
				return; // Skip if already exists
			}
+7 −0
Original line number Diff line number Diff line
@@ -490,4 +490,11 @@ class UserService {
	private function getDefaultQuota() {
		return $this->config->getSystemValueInt('default_quota_in_megabytes', 1024);
	}
	/**
	 * Remove legacy domain from username if present
	 */
	public function stripLegacyDomainFromUsername(string $username): string {
		$legacyDomain = $this->config->getSystemValue('legacy_domain', '');
		return str_ireplace('@' . $legacyDomain, '', $username);
	}
}