MINOR moved File validation to the model (from r92044) (from r96742)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102368 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-04-12 02:34:38 +00:00
parent c672061024
commit 1bb7bfa71f

View File

@ -618,6 +618,24 @@ class File extends DataObject {
return $labels;
}
function validate() {
if(!AssetAdmin::$apply_restrictions_to_admin && Permission::check('ADMIN')) {
if(!in_array(strtolower(pathinfo($this->Name, PATHINFO_EXTENSION)), AssetAdmin::$allowed_extensions)) {
$message = sprintf(
_t(
'File.INVALIDEXTENSION',
'Extension is not allowed (valid: %s)',
PR_MEDIUM,
'Argument 1: Comma-separated list of valid extensions'
),
implode(',',AssetAdmin::$allowed_extensions)
);
return new ValidationResult(false, $message);
}
}
return new ValidationResult(true);
}
}
?>