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

Commit 79a9ca74 authored by theronakpatel's avatar theronakpatel
Browse files

remove domain from username

parent 8109e889
Loading
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -194,6 +194,9 @@ class SyncMissingUsersToCommon extends Command {
		// Get user metadata from LDAP
		$userMetadata = $this->ldapConnectionService->getUserMetadata($username);

		// Remove domain from username using UserService
		$usernameWithoutDomain = $this->userService->stripLegacyDomainFromUsername($username);

		// Convert LDAP createTimestamp to MySQL datetime format
		$ldapTimestamp = $userMetadata['createTimestamp'] ?? null;
		$createdAt = $ldapTimestamp;
@@ -205,17 +208,17 @@ class SyncMissingUsersToCommon extends Command {
			}
		}

		$output->writeln(sprintf('  Found user in LDAP: %s (created: %s)', $userMetadata['usernameWithoutDomain'], $createdAt));
		$output->writeln(sprintf('  Found user in LDAP: %s (created: %s)', $usernameWithoutDomain, $createdAt));

		if (!$isDryRun) {
			// Add user to common database
			$this->userService->addUsernameToCommonDataStore(
				$username,
				$usernameWithoutDomain,
				$ipAddress,
				$userMetadata['recoveryMailAddress'],
				$createdAt
			);
			$output->writeln(sprintf('  <info>✓ User synced successfully to common database: %s</info>', $username));
			$output->writeln(sprintf('  <info>✓ User synced successfully to common database: %s</info>', $usernameWithoutDomain));
		} else {
			$output->writeln(sprintf('  <comment>Would sync user to common database with recovery email: %s and created_at: %s</comment>', $userMetadata['recoveryMailAddress'], $createdAt));
		}
+10 −0
Original line number Diff line number Diff line
@@ -490,4 +490,14 @@ 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', '');
		if ($legacyDomain && str_ends_with($username, '@' . $legacyDomain)) {
			return substr($username, 0, -strlen('@' . $legacyDomain));
		}
		return $username;
	}
}