|
6 | 6 | use SilverStripe\Control\Director; |
7 | 7 | use SilverStripe\ORM\FieldType\DBField; |
8 | 8 | use SilverStripe\Versioned\Versioned; |
| 9 | +use SilverStripe\Security\Member; |
| 10 | +use SilverStripe\Security\Security; |
9 | 11 |
|
10 | 12 | /** |
11 | 13 | * A file uploaded on a {@link UserDefinedForm} and attached to a single |
@@ -41,27 +43,40 @@ public function getFormattedValue() |
41 | 43 | { |
42 | 44 | $name = $this->getFileName(); |
43 | 45 | $link = $this->getLink(false); |
44 | | - $title = _t(__CLASS__ . '.DOWNLOADFILE', 'Download File'); |
45 | | - $message = _t(__CLASS__ . '.INSUFFICIENTRIGHTS', 'You don\'t have the right permissions to download this file'); |
46 | | - $file = $this->getUploadedFileFromDraft(); |
47 | | - |
48 | 46 | if ($link) { |
49 | | - if ($file->canView()) { |
| 47 | + $title = _t(__CLASS__ . '.DOWNLOADFILE', 'Download File'); |
| 48 | + $file = $this->getUploadedFileFromDraft(); |
| 49 | + if (!$file->canView()) { |
| 50 | + if (Security::getCurrentUser()) { |
| 51 | + // Logged in CMS user without permissions to view file in the CMS |
| 52 | + $default = 'You don\'t have the right permissions to download this file'; |
| 53 | + $message = _t(__CLASS__ . '..INSUFFICIENTRIGHTS', $default); |
| 54 | + return DBField::create_field('HTMLText', sprintf( |
| 55 | + '<i class="icon font-icon-lock"></i> %s - <em>%s</em>', |
| 56 | + htmlspecialchars($name, ENT_QUOTES), |
| 57 | + htmlspecialchars($message, ENT_QUOTES) |
| 58 | + )); |
| 59 | + } else { |
| 60 | + // Userforms submission filled in by non-logged in user being emailed to recipient |
| 61 | + $message = _t(__CLASS__ . '.YOUMUSTBELOGGEDIN', 'You must be logged in to view this file'); |
| 62 | + return DBField::create_field('HTMLText', sprintf( |
| 63 | + '%s - <a href="%s" target="_blank">%s</a> - <em>%s</em>', |
| 64 | + htmlspecialchars($name, ENT_QUOTES), |
| 65 | + htmlspecialchars($link, ENT_QUOTES), |
| 66 | + htmlspecialchars($title, ENT_QUOTES), |
| 67 | + htmlspecialchars($message, ENT_QUOTES) |
| 68 | + )); |
| 69 | + } |
| 70 | + } else { |
| 71 | + // Logged in CMS user with permissions to view file in the CMS |
50 | 72 | return DBField::create_field('HTMLText', sprintf( |
51 | 73 | '%s - <a href="%s" target="_blank">%s</a>', |
52 | 74 | htmlspecialchars($name, ENT_QUOTES), |
53 | 75 | htmlspecialchars($link, ENT_QUOTES), |
54 | 76 | htmlspecialchars($title, ENT_QUOTES) |
55 | 77 | )); |
56 | | - } else { |
57 | | - return DBField::create_field('HTMLText', sprintf( |
58 | | - '<i class="icon font-icon-lock"></i> %s - <em>%s</em>', |
59 | | - htmlspecialchars($name, ENT_QUOTES), |
60 | | - htmlspecialchars($message, ENT_QUOTES) |
61 | | - )); |
62 | 78 | } |
63 | 79 | } |
64 | | - |
65 | 80 | return false; |
66 | 81 | } |
67 | 82 |
|
|
0 commit comments