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

Commit 6390fcd9 authored by Arnau Vàzquez's avatar Arnau Vàzquez
Browse files

Merge branch 'dev/optimize-get-by-email' into 'main'

Add patch for get by email

See merge request !164
parents 495df48a 0949cb5b
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ ARG ECLOUD_DASHBOARD_JOB_ID="525503"
ARG SNAPPY_VERSION="2.26.3"
ARG SNAPPY_THEME_VERSION="1.2.2"

RUN sed -i 's/24,0,10,1/24,0,10,7/' ${BASE_DIR}/version.php
RUN sed -i 's/24,0,10,1/24,0,10,8/' ${BASE_DIR}/version.php
COPY custom_entrypoint.sh /
RUN chmod +x /custom_entrypoint.sh
RUN mkdir -p /var/www/skeleton/Documents && mkdir -p /var/www/skeleton/Images
@@ -165,6 +165,7 @@ RUN cd ${BASE_DIR}/custom_apps && patch -p0 < ${TMP_PATCH_DIR}/005-autocomplete-
RUN patch -u ${BASE_DIR}/core/templates/layout.guest.php -i ${TMP_PATCH_DIR}/016-login-screen.patch
RUN patch -u ${BASE_DIR}/lib/private/Notification/Manager.php -i ${TMP_PATCH_DIR}/020-fairuse-notification-fix.patch
RUN cd ${BASE_DIR} && patch -u ${BASE_DIR}/apps/user_ldap/lib/User_LDAP.php -i ${TMP_PATCH_DIR}/023-ldap-check-pwd-optimization.patch
RUN patch -u ${BASE_DIR}/lib/private/User/Manager.php -i ${TMP_PATCH_DIR}/025-optimize-get-by-email.patch
RUN rm -rf ${TMP_PATCH_DIR}

RUN curl -fsSL -o ldap_write_support.tar.gz \
+44 −0
Original line number Diff line number Diff line
From: Akhil <akhil@e.email>
Date: Tue, 10 Mar 2023 10:00 +0530
Subject: [PATCH] To optimize getByEmail as we have boundary conditions that email is unique per-user and can only match one of the two domains

--- ./lib/private/User/Manager.php	2023-03-10 10:01:44.729561986 +0530
+++ ./lib/private/User/Manager-new.php	2023-03-10 10:05:18.767230727 +0530
@@ -706,11 +706,33 @@
 	 */
 	public function getByEmail($email) {
 		// looking for 'email' only (and not primary_mail) is intentional
-		$userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email);
+		$mailDomain = $this->config->getSystemValue('mail_domain', '');
+		$altMailDomain = $this->config->getSystemValue('alt_mail_domain', '');
+		$users = [];
+		
+		if(empty($mailDomain) && empty($altMailDomain)) {
+			$userIds = $this->config->getUsersForUserValueCaseInsensitive('settings', 'email', $email);
 
-		$users = array_map(function ($uid) {
-			return $this->get($uid);
-		}, $userIds);
+			$users = array_map(function ($uid) {
+				return $this->get($uid);
+			}, $userIds);
+		} else {
+			$uid = '';
+			$mailDomainSuffix = empty($mailDomain) ?  '' : '@' . $mailDomain;
+			$altMailDomainSuffix = empty($altMailDomain) ? '' : '@' . $altMailDomain;
+
+			if (!empty($mailDomainSuffix) && stristr($email, $mailDomainSuffix) !== FALSE) {
+				// In case of mail_domain, username is email
+				$uid = $email;
+			} else if (!empty($altMailDomainSuffix) && stristr($email, $altMailDomainSuffix) !== FALSE) {
+				// In case of alt_mail_domain, username is email without domain suffix
+				$uid =  str_replace($altMailDomainSuffix, '', $email);
+			}
+			// If no match of domain, no user
+			if(!empty($uid)) {
+				$users = [$this->get($uid)];
+			}
+		}
 
 		return array_values(array_filter($users, function ($u) {
 			return ($u instanceof IUser);