Changeset View
Changeset View
Standalone View
Standalone View
src/app/Rules/SharedFolderName.php
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | |||||
// Check the max length, according to the database column length | // Check the max length, according to the database column length | ||||
if (strlen($name) > 191) { | if (strlen($name) > 191) { | ||||
$this->message = \trans('validation.max.string', ['max' => 191]); | $this->message = \trans('validation.max.string', ['max' => 191]); | ||||
return false; | return false; | ||||
} | } | ||||
// Check if specified domain belongs to the user | // Check if specified domain belongs to the user | ||||
$domains = \collect($this->owner->domains(true, false))->pluck('namespace')->all(); | if (!$this->owner->domains(true, false)->where('namespace', $this->domain)->exists()) { | ||||
if (!in_array($this->domain, $domains)) { | |||||
$this->message = \trans('validation.domaininvalid'); | $this->message = \trans('validation.domaininvalid'); | ||||
return false; | return false; | ||||
} | } | ||||
// Check if the name is unique in the domain | // Check if the name is unique in the domain | ||||
// FIXME: Maybe just using the whole shared_folders table would be faster than sharedFolders()? | // FIXME: Maybe just using the whole shared_folders table would be faster than sharedFolders()? | ||||
$exists = $this->owner->sharedFolders() | $exists = $this->owner->sharedFolders() | ||||
->where('shared_folders.name', $name) | ->where('name', $name) | ||||
->where('shared_folders.email', 'like', '%@' . $this->domain) | ->where('email', 'like', '%@' . $this->domain) | ||||
->exists(); | ->exists(); | ||||
if ($exists) { | if ($exists) { | ||||
$this->message = \trans('validation.nameexists'); | $this->message = \trans('validation.nameexists'); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
Show All 12 Lines |