diff --git a/code/Model/Submission/SubmittedFileField.php b/code/Model/Submission/SubmittedFileField.php
index 1a57cce28..e302d7e00 100755
--- a/code/Model/Submission/SubmittedFileField.php
+++ b/code/Model/Submission/SubmittedFileField.php
@@ -41,25 +41,16 @@ public function getFormattedValue()
{
$name = $this->getFileName();
$link = $this->getLink(false);
- $title = _t(__CLASS__ . '.DOWNLOADFILE', 'Download File');
- $message = _t(__CLASS__ . '.INSUFFICIENTRIGHTS', 'You don\'t have the right permissions to download this file');
- $file = $this->getUploadedFileFromDraft();
-
if ($link) {
- if ($file->canView()) {
- return DBField::create_field('HTMLText', sprintf(
- '%s - %s',
- htmlspecialchars($name, ENT_QUOTES),
- htmlspecialchars($link, ENT_QUOTES),
- htmlspecialchars($title, ENT_QUOTES)
- ));
- } else {
- return DBField::create_field('HTMLText', sprintf(
- ' %s - %s',
- htmlspecialchars($name, ENT_QUOTES),
- htmlspecialchars($message, ENT_QUOTES)
- ));
- }
+ $title = _t(__CLASS__ . '.DOWNLOADFILE', 'Download File');
+ $message = _t(__CLASS__ . '.YOUMUSTBELOGGEDIN', 'You must be logged in to view this file');
+ return DBField::create_field('HTMLText', sprintf(
+ ' %s - %s - %s',
+ htmlspecialchars($name, ENT_QUOTES),
+ htmlspecialchars($link, ENT_QUOTES),
+ htmlspecialchars($title, ENT_QUOTES),
+ htmlspecialchars($message, ENT_QUOTES)
+ ));
}
return false;
diff --git a/lang/en.yml b/lang/en.yml
index 022710434..98515b26d 100644
--- a/lang/en.yml
+++ b/lang/en.yml
@@ -328,6 +328,7 @@ en:
one: 'A Submitted File Field'
other: '{count} Submitted File Fields'
SINGULARNAME: 'Submitted File Field'
+ YOUMUSTBELOGGEDIN: 'You must be logged in to view this file'
has_one_UploadedFile: 'Uploaded file'
SilverStripe\UserForms\Model\Submission\SubmittedForm:
PLURALNAME: 'Submitted Forms'
diff --git a/tests/php/Model/SubmittedFileFieldTest.php b/tests/php/Model/SubmittedFileFieldTest.php
index ac6778982..5f61ef7c0 100644
--- a/tests/php/Model/SubmittedFileFieldTest.php
+++ b/tests/php/Model/SubmittedFileFieldTest.php
@@ -73,34 +73,28 @@ 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";
+ $message = 'You must be logged in to view this file';
+ $link = 'Download File';
$this->file->CanViewType = 'OnlyTheseUsers';
$this->file->write();
- $this->loginWithPermission('ADMIN');
- $this->assertEquals(
- sprintf(
- '%s - Download File',
- $fileName
- ),
- $this->submittedFile->getFormattedValue()->value
- );
-
- $this->loginWithPermission('CMS_ACCESS_CMSMain');
- $this->assertEquals(
- sprintf(
- ' %s - %s',
- $fileName,
- $message
- ),
- $this->submittedFile->getFormattedValue()->value
- );
-
- $store = Injector::inst()->get(AssetStore::class);
- $this->assertFalse(
- $store->canView($fileName, $this->file->getHash()),
- 'Users without canView rights on the file should not have been session granted access to it'
- );
+ foreach (['ADMIN', 'CMS_ACCESS_CMSMain'] as $permission) {
+ $this->loginWithPermission('ADMIN');
+ $this->assertEquals(
+ sprintf(
+ ' %s - %s - %s',
+ $fileName,
+ $link,
+ $message
+ ),
+ $this->submittedFile->getFormattedValue()->value
+ );
+ $store = Injector::inst()->get(AssetStore::class);
+ $this->assertFalse(
+ $store->canView($fileName, $this->file->getHash()),
+ 'Users without canView rights on the file should not have been session granted access to it'
+ );
+ }
}
}