namespace BookStack\Entities\Models;
use BookStack\Entities\Tools\PageContent;
-use BookStack\Facades\Permissions;
+use BookStack\Permissions\PermissionApplicator;
use BookStack\Uploads\Attachment;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
public $textField = 'text';
- protected $hidden = ['html', 'markdown', 'text', 'restricted', 'pivot', 'deleted_at'];
+ protected $hidden = ['html', 'markdown', 'text', 'pivot', 'deleted_at'];
protected $casts = [
'draft' => 'boolean',
*/
public function scopeVisible(Builder $query): Builder
{
- $query = Permissions::enforceDraftVisibilityOnQuery($query);
+ $query = app()->make(PermissionApplicator::class)->restrictDraftsOnPageQuery($query);
return parent::scopeVisible($query);
}
/**
* Get the current revision for the page if existing.
- *
- * @return PageRevision|null
*/
public function currentRevision(): HasOne
{
{
$refreshed = $this->refresh()->unsetRelations()->load(['tags', 'createdBy', 'updatedBy', 'ownedBy']);
$refreshed->setHidden(array_diff($refreshed->getHidden(), ['html', 'markdown']));
+ $refreshed->setAttribute('raw_html', $refreshed->html);
$refreshed->html = (new PageContent($refreshed))->render();
return $refreshed;
}
+
+ /**
+ * Get a visible page by its book and page slugs.
+ * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
+ */
+ public static function getBySlugs(string $bookSlug, string $pageSlug): self
+ {
+ return static::visible()->whereSlugs($bookSlug, $pageSlug)->firstOrFail();
+ }
}