Skip to content

Commit

Permalink
Update policies
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpustulka committed Aug 21, 2023
1 parent d3ca112 commit 4a08022
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/test_app/TestApp/Policy/ArticlePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public function canAdd($user)
*/
public function canEdit($user, Article $article)
{
if ($user === null) {
return false;
}

if (in_array($user['role'], ['admin', 'author'])) {
return true;
}
Expand Down
8 changes: 7 additions & 1 deletion tests/test_app/TestApp/Policy/ArticlesTablePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ public function canModify(IdentityInterface $identity)
return $identity['can_edit'];
}

public function scopeEdit(IdentityInterface $user, QueryInterface $query)
public function scopeEdit(?IdentityInterface $user, QueryInterface $query)
{
if ($user === null) {
return $query->where([
'visibility' => 'public',
]);
}

return $query->where([
'user_id' => $user['id'],
]);
Expand Down

0 comments on commit 4a08022

Please sign in to comment.