X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/58fa7679bccafd00f9a50bcd4a87e96876331b03..refs/pull/3391/head:/app/Uploads/Attachment.php
diff --git a/app/Uploads/Attachment.php b/app/Uploads/Attachment.php
index 383af9537..5e637246a 100644
--- a/app/Uploads/Attachment.php
+++ b/app/Uploads/Attachment.php
@@ -1,26 +1,42 @@
- 'bool',
+ ];
/**
* Get the downloadable file name for this upload.
+ *
* @return mixed|string
*/
public function getFileName()
@@ -28,6 +44,7 @@ class Attachment extends Model
if (strpos($this->name, '.') !== false) {
return $this->name;
}
+
return $this->name . '.' . $this->extension;
}
@@ -47,6 +64,7 @@ class Attachment extends Model
if ($this->external && strpos($this->path, 'http') !== 0) {
return $this->path;
}
+
return url('/http/source.bookstackapp.com/attachments/' . $this->id . ($openInline ? '?open=true' : ''));
}
@@ -55,7 +73,7 @@ class Attachment extends Model
*/
public function htmlLink(): string
{
- return ''.e($this->name).'';
+ return '' . e($this->name) . '';
}
/**
@@ -63,6 +81,21 @@ class Attachment extends Model
*/
public function markdownLink(): string
{
- return '['. $this->name .']('. $this->getUrl() .')';
+ return '[' . $this->name . '](' . $this->getUrl() . ')';
+ }
+
+ /**
+ * Scope the query to those attachments that are visible based upon related page permissions.
+ */
+ public function scopeVisible(): Builder
+ {
+ $permissionService = app()->make(PermissionService::class);
+
+ return $permissionService->filterRelatedEntity(
+ Page::class,
+ self::query(),
+ 'attachments',
+ 'uploaded_to'
+ );
}
}