Skip to content

Commit bf6650e

Browse files
committed
Fix shopping list acl
1 parent 6b72f1c commit bf6650e

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v5.9.3
2+
## Fixes
3+
- Fixed shopping list access check
4+
15
# v5.9.2
26
## Fixes
37
- Fixed CSV import errors

app/Http/Controllers/ShoppingListController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ShoppingListController extends Controller
3030
public function index(Request $request, int $id): JsonResource
3131
{
3232
$user = User::findOrFail($id);
33-
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
33+
if ($request->user()->id !== $user->id) {
3434
abort(403);
3535
}
3636

@@ -54,7 +54,7 @@ public function index(Request $request, int $id): JsonResource
5454
public function batchStore(IngredientsBatchRequest $request, int $id): Response
5555
{
5656
$user = User::findOrFail($id);
57-
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
57+
if ($request->user()->id !== $user->id) {
5858
abort(403);
5959
}
6060

@@ -111,7 +111,7 @@ public function batchStore(IngredientsBatchRequest $request, int $id): Response
111111
public function batchDelete(IngredientsBatchRequest $request, int $id): Response
112112
{
113113
$user = User::findOrFail($id);
114-
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
114+
if ($request->user()->id !== $user->id) {
115115
abort(403);
116116
}
117117

@@ -150,7 +150,7 @@ public function batchDelete(IngredientsBatchRequest $request, int $id): Response
150150
public function share(Request $request, int $id): JsonResponse
151151
{
152152
$user = User::findOrFail($id);
153-
if ($request->user()->id !== $user->id || $request->user()->cannot('show', $user)) {
153+
if ($request->user()->id !== $user->id) {
154154
abort(403);
155155
}
156156

tests/Feature/Http/ShoppingListControllerTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Kami\Cocktail\Models\UserShoppingList;
1010
use Illuminate\Testing\Fluent\AssertableJson;
1111
use Illuminate\Foundation\Testing\RefreshDatabase;
12+
use Kami\Cocktail\Models\Enums\UserRoleEnum;
1213

1314
class ShoppingListControllerTest extends TestCase
1415
{
@@ -84,4 +85,26 @@ public function test_delete_multiple_ingredients_from_shopping_list_response():
8485

8586
$this->assertDatabaseCount('user_shopping_lists', 0);
8687
}
88+
89+
public function test_list_ingredients_on_shopping_list_response_guest_role(): void
90+
{
91+
$membership = $this->setupBarMembership(UserRoleEnum::Guest);
92+
$this->actingAs($membership->user);
93+
94+
UserShoppingList::factory()->count(5)->create();
95+
UserShoppingList::factory()
96+
->recycle($membership, $membership->bar, $membership->user)
97+
->count(5)
98+
->create();
99+
100+
$response = $this->getJson('/api/users/'. $membership->user_id .'/shopping-list', ['Bar-Assistant-Bar-Id' => $membership->bar_id]);
101+
102+
$response->assertOk();
103+
$response->assertJson(
104+
fn (AssertableJson $json) =>
105+
$json
106+
->has('data', 5)
107+
->etc()
108+
);
109+
}
87110
}

0 commit comments

Comments
 (0)