mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FIX Use absolute URL for submitted file links in emails (#1226)
This commit is contained in:
parent
495ca85ea4
commit
60717e5c04
@ -3,6 +3,7 @@
|
|||||||
namespace SilverStripe\UserForms\Model\Submission;
|
namespace SilverStripe\UserForms\Model\Submission;
|
||||||
|
|
||||||
use SilverStripe\Assets\File;
|
use SilverStripe\Assets\File;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\ORM\FieldType\DBField;
|
use SilverStripe\ORM\FieldType\DBField;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
|
|
||||||
@ -83,7 +84,11 @@ class SubmittedFileField extends SubmittedFormField
|
|||||||
{
|
{
|
||||||
if ($file = $this->getUploadedFileFromDraft()) {
|
if ($file = $this->getUploadedFileFromDraft()) {
|
||||||
if ($file->exists()) {
|
if ($file->exists()) {
|
||||||
return $file->getURL($grant);
|
$url = $file->getURL($grant);
|
||||||
|
if ($url) {
|
||||||
|
return Director::absoluteURL($url);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace SilverStripe\UserForms\Tests\Model;
|
|||||||
use SilverStripe\Assets\Dev\TestAssetStore;
|
use SilverStripe\Assets\Dev\TestAssetStore;
|
||||||
use SilverStripe\Assets\File;
|
use SilverStripe\Assets\File;
|
||||||
use SilverStripe\Assets\Storage\AssetStore;
|
use SilverStripe\Assets\Storage\AssetStore;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\UserForms\Model\Submission\SubmittedFileField;
|
use SilverStripe\UserForms\Model\Submission\SubmittedFileField;
|
||||||
@ -69,6 +70,8 @@ class SubmittedFileFieldTest extends SapphireTest
|
|||||||
|
|
||||||
public function testGetFormattedValue()
|
public function testGetFormattedValue()
|
||||||
{
|
{
|
||||||
|
// Set an explicit base URL so we get a reliable value for the test
|
||||||
|
Director::config()->set('alternate_base_url', 'http://mysite.com');
|
||||||
$fileName = $this->submittedFile->getFileName();
|
$fileName = $this->submittedFile->getFileName();
|
||||||
$message = "You don't have the right permissions to download this file";
|
$message = "You don't have the right permissions to download this file";
|
||||||
|
|
||||||
@ -78,7 +81,7 @@ class SubmittedFileFieldTest extends SapphireTest
|
|||||||
$this->loginWithPermission('ADMIN');
|
$this->loginWithPermission('ADMIN');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
sprintf(
|
sprintf(
|
||||||
'%s - <a href="/assets/3c01bdbb26/test-SubmittedFileFieldTest.txt" target="_blank">Download File</a>',
|
'%s - <a href="http://mysite.com/assets/3c01bdbb26/test-SubmittedFileFieldTest.txt" target="_blank">Download File</a>',
|
||||||
$fileName
|
$fileName
|
||||||
),
|
),
|
||||||
$this->submittedFile->getFormattedValue()->value
|
$this->submittedFile->getFormattedValue()->value
|
||||||
|
Loading…
Reference in New Issue
Block a user