BookStack\Services\PermissionService::enforcePageRestrictions PHP Method

enforcePageRestrictions() public method

Add restrictions for a page query
public enforcePageRestrictions ( $query, string $action = 'view' ) : mixed
$query
$action string
return mixed
    public function enforcePageRestrictions($query, $action = 'view')
    {
        // Prevent drafts being visible to others.
        $query = $query->where(function ($query) {
            $query->where('draft', '=', false);
            if ($this->currentUser()) {
                $query->orWhere(function ($query) {
                    $query->where('draft', '=', true)->where('created_by', '=', $this->currentUser()->id);
                });
            }
        });
        return $this->enforceEntityRestrictions($query, $action);
    }

Usage Example

Example #1
0
 /**
  * Get the most recently updated pages.
  * @param $count
  * @param int $page
  * @return mixed
  */
 public function getRecentlyUpdatedPages($count = 20, $page = 0)
 {
     return $this->permissionService->enforcePageRestrictions($this->page)->where('draft', '=', false)->orderBy('updated_at', 'desc')->with('book')->skip($page * $count)->take($count)->get();
 }