From 57c2cb19b4f440e6903a81eba926f232a7c75ba8 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 24 Jul 2015 09:26:32 -0500 Subject: [PATCH] org: Fix matching of empty domain name If a user is created with an empty domain name (e.g. <user@>), then the user would be associated with the first organization without a main domain specified. This patch ensures that the domain is not empty when making a match with an organization. --- include/class.organization.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/class.organization.php b/include/class.organization.php index 6594d8a9b..f2c092d9d 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -166,6 +166,8 @@ class Organization extends OrganizationModel { } function isMappedToDomain($domain) { + if (!$domain || !$this->domain) + return false; foreach (explode(',', $this->domain) as $d) { $d = trim($d); if ($d[0] == '.') { @@ -182,8 +184,12 @@ class Organization extends OrganizationModel { } static function forDomain($domain) { - foreach (static::objects() - ->filter(array('domain__contains'=>$domain)) as $org) { + if (!$domain) + return null; + foreach (static::objects()->filter(array( + 'domain__gt'=>'', + 'domain__contains'=>$domain + )) as $org) { if ($org->isMappedToDomain($domain)) { return $org; } -- GitLab