File tree Expand file tree Collapse file tree
demo/app/Sharp/Posts/Blocks Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99
1010class PostBlockPolicy extends SharpEntityPolicy
1111{
12+ public function entity ($ user ): bool
13+ {
14+ // Only authorized in EEL case
15+ return sharp ()->context ()->breadcrumb ()->previousShowSegment (PostEntity::class) !== null ;
16+ }
17+
1218 public function view ($ user , $ instanceId ): bool
1319 {
14- return $ user ->isAdmin ()
15- || PostBlock::find ($ instanceId )?->post?->author_id === $ user ->id ;
20+ $ block = sharp ()
21+ ->context ()
22+ ->findListInstance ($ instanceId , fn ($ postBlockId ) => PostBlock::find ($ postBlockId ));
23+
24+ return $ block && ($ user ->isAdmin () || $ block ->post ?->author_id === $ user ->id );
1625 }
1726
1827 public function create ($ user ): bool
1928 {
20- return $ user ->isAdmin ()
21- || Post::find (sharp ()->context ()->breadcrumb ()->previousShowSegment (PostEntity::class)->instanceId ())?->author_id === $ user ->id ;
29+ if (! $ postId = sharp ()->context ()->breadcrumb ()->previousShowSegment (PostEntity::class)?->instanceId()) {
30+ return false ;
31+ }
32+
33+ $ post = Post::find ($ postId );
34+
35+ return $ post && ($ user ->isAdmin () || $ post ->author_id === $ user ->id );
2236 }
2337}
You can’t perform that action at this time.
0 commit comments