MINOR moved File validation to the model (from r92044)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@96742 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-01-12 23:23:15 +00:00
parent 0ce4714fdf
commit b4dc73e002

View File

@ -614,6 +614,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);
}
}
?>