Skip to content

Commit 059d438

Browse files
committed
Fix demo
1 parent a385147 commit 059d438

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

demo/app/Sharp/Posts/Blocks/PostBlockPolicy.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,29 @@
99

1010
class 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
}

0 commit comments

Comments
 (0)