Skip to content

Commit

Permalink
Merge branch '5.15' into 5
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Aug 16, 2023
2 parents 98cfb16 + 60717e5 commit 1fb7c8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 6 additions & 1 deletion code/Model/Submission/SubmittedFileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\UserForms\Model\Submission;

use SilverStripe\Assets\File;
use SilverStripe\Control\Director;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\Versioned\Versioned;

Expand Down Expand Up @@ -83,7 +84,11 @@ public function getLink($grant = true)
{
if ($file = $this->getUploadedFileFromDraft()) {
if ($file->exists()) {
return $file->getURL($grant);
$url = $file->getURL($grant);
if ($url) {
return Director::absoluteURL($url);
}
return null;
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions tests/php/Model/SubmittedFileFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Control\Director;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\Submission\SubmittedFileField;
Expand Down Expand Up @@ -69,21 +70,23 @@ public function testDeletingSubmissionRemovesFile()

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();
$message = "You don't have the right permissions to download this file";

$this->file->CanViewType = 'OnlyTheseUsers';
$this->file->write();

$this->loginWithPermission('ADMIN');
$this->assertEquals(
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
),
$this->submittedFile->getFormattedValue()->value
);

$this->loginWithPermission('CMS_ACCESS_CMSMain');
$this->assertEquals(
sprintf(
Expand Down

0 comments on commit 1fb7c8a

Please sign in to comment.