Page MenuHomePhorge

No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None
diff --git a/src/app/Traits/EmailPropertyTrait.php b/src/app/Traits/EmailPropertyTrait.php
index 00416eac..08f93da9 100644
--- a/src/app/Traits/EmailPropertyTrait.php
+++ b/src/app/Traits/EmailPropertyTrait.php
@@ -1,94 +1,94 @@
<?php
namespace App\Traits;
trait EmailPropertyTrait
{
/** @var ?string Domain name for the to-be-created object */
public $domainName;
/**
* Boot function from Laravel.
*/
protected static function bootEmailPropertyTrait()
{
static::creating(function ($model) {
if (empty($model->email) && defined('static::EMAIL_TEMPLATE')) {
$template = static::EMAIL_TEMPLATE; // @phpstan-ignore-line
$defaults = [
'type' => 'mail',
];
foreach (['id', 'domainName', 'type'] as $prop) {
if (strpos($template, "{{$prop}}") === false) {
continue;
}
$value = $model->{$prop} ?? ($defaults[$prop] ?? '');
if ($value === '' || $value === null) {
throw new \Exception("Missing '{$prop}' property for " . static::class);
}
$template = str_replace("{{$prop}}", $value, $template);
}
$model->email = strtolower($template);
}
});
}
/**
* Returns the object's domain (including soft-deleted).
*
* @return ?\App\Domain The domain to which the object belongs to, NULL if it does not exist
*/
public function domain(): ?\App\Domain
{
if (empty($this->email) && isset($this->domainName)) {
$domainName = $this->domainName;
- } else if (strpos($this->email, '@')) {
+ } elseif (strpos($this->email, '@')) {
list($local, $domainName) = explode('@', $this->email);
} else {
return null;
}
return \App\Domain::withTrashed()->where('namespace', $domainName)->first();
}
/**
* Find whether an email address exists as a model object (including soft-deleted).
*
* @param string $email Email address
* @param bool $return_object Return model instance instead of a boolean
*
* @return static|bool True or Model object if found, False otherwise
*/
public static function emailExists(string $email, bool $return_object = false)
{
if (strpos($email, '@') === false) {
return false;
}
$email = \strtolower($email);
$object = static::withTrashed()->where('email', $email)->first();
if ($object) {
return $return_object ? $object : true;
}
return false;
}
/**
* Ensure the email is appropriately cased.
*
* @param string $email Email address
*/
public function setEmailAttribute(string $email): void
{
$this->attributes['email'] = strtolower($email);
}
}
diff --git a/src/tests/Feature/Jobs/Group/UpdateTest.php b/src/tests/Feature/Jobs/Group/UpdateTest.php
index a3916559..5328d180 100644
--- a/src/tests/Feature/Jobs/Group/UpdateTest.php
+++ b/src/tests/Feature/Jobs/Group/UpdateTest.php
@@ -1,81 +1,82 @@
<?php
namespace Tests\Feature\Jobs\Group;
use App\Backends\LDAP;
use App\Group;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
class UpdateTest extends TestCase
{
/**
* {@inheritDoc}
*/
public function setUp(): void
{
parent::setUp();
$this->deleteTestGroup('group@kolab.org');
}
public function tearDown(): void
{
$this->deleteTestGroup('group@kolab.org');
parent::tearDown();
}
/**
* Test job handle
*
* @group ldap
*/
public function testHandle(): void
{
Queue::fake();
// Test non-existing group ID
$job = new \App\Jobs\Group\UpdateJob(123);
$job->handle();
$this->assertTrue($job->hasFailed());
$this->assertSame("Group 123 could not be found in the database.", $job->failureMessage);
// Create the group
$group = $this->getTestGroup('group@kolab.org', ['members' => []]);
LDAP::createGroup($group);
// Test if group properties (members) actually changed in LDAP
$group->members = ['test1@gmail.com'];
$group->status |= Group::STATUS_LDAP_READY;
$group->save();
$job = new \App\Jobs\Group\UpdateJob($group->id);
$job->handle();
$ldapGroup = LDAP::getGroup($group->email);
$root_dn = \config('ldap.hosted.root_dn');
$this->assertSame('uid=test1@gmail.com,ou=People,ou=kolab.org,' . $root_dn, $ldapGroup['uniquemember']);
// Test that suspended group is removed from LDAP
$group->suspend();
$job = new \App\Jobs\Group\UpdateJob($group->id);
$job->handle();
$this->assertNull(LDAP::getGroup($group->email));
// Test that unsuspended group is added back to LDAP
$group->unsuspend();
$job = new \App\Jobs\Group\UpdateJob($group->id);
$job->handle();
/** @var array */
$ldapGroup = LDAP::getGroup($group->email);
+ $this->assertNotNull($ldapGroup);
$this->assertSame($group->email, $ldapGroup['mail']);
$this->assertSame('uid=test1@gmail.com,ou=People,ou=kolab.org,' . $root_dn, $ldapGroup['uniquemember']);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Feb 6, 7:18 AM (8 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
428149
Default Alt Text
(5 KB)

Event Timeline