Retrieve protected files using the defined file model
Adds support to retrieve protected files using the class they are defined to be using if that class differs from the default System\Models\File class. This makes it possible to use a custom class extending the base file model class that does output processing on the file data (for example, an EncryptedFile class that has to decrypt the file contents before they can be output to the browser).
This commit is contained in:
parent
55d49cbf2b
commit
f056e8dcb2
|
|
@ -110,6 +110,23 @@ class Files extends Controller
|
|||
if (!$file = FileModel::find((int) $id)) {
|
||||
throw new ApplicationException('Unable to find file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the file model utilized for this request is
|
||||
* the one specified in the relationship configuration
|
||||
*/
|
||||
if ($file->attachment) {
|
||||
$fileModel = $file->attachment->{$file->field}()->getRelated();
|
||||
|
||||
/**
|
||||
* Only attempt to get file model through its assigned class
|
||||
* when the assigned class differs from the default one that
|
||||
* the file has already been loaded from
|
||||
*/
|
||||
if (get_class($file) !== get_class($fileModel)) {
|
||||
$file = $fileModel->find($file->id);
|
||||
}
|
||||
}
|
||||
|
||||
$verifyCode = self::getUniqueCode($file);
|
||||
if ($code != $verifyCode) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue