Skip to content

Commit 8c98864

Browse files
committed
wip: add user visible scope for post
1 parent 204930d commit 8c98864

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/Models/Post.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,29 @@ public function reject(): void
375375
: $this->getDraftKey();
376376
}
377377
}
378+
379+
/**
380+
* Determine posts that a user can see
381+
*
382+
* @param $query
383+
* @param PostType $type
384+
* @return mixed
385+
*/
386+
public function scopeUserVisibleForPostType($query, PostType $type)
387+
{
388+
$admin = auth()->user();
389+
390+
if ($admin) {
391+
if ($admin->can('create', $type) && $admin->can('editOthers', $type)) {
392+
// Admin can edit all posts
393+
return $query;
394+
}
395+
}
396+
397+
// everyone can view published
398+
return $query->published();
399+
}
400+
378401
/**
379402
* Get the content blocks
380403
* Default to one single raw block

0 commit comments

Comments
 (0)