Skip to content

Commit 0640288

Browse files
qunabuMateusz Wojczal
andauthored
libraries essential fix (#66)
* libraries essential fix * libraries essential fix Co-authored-by: Mateusz Wojczal <mateuszwojczal@Mateuszs-MacBook-Pro.local>
1 parent 93d5533 commit 0640288

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

src/Http/Controllers/LibraryApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function libraries(LibraryListRequest $request): JsonResponse
4747
$request->get('minorVersion')
4848
);
4949

50-
return $this->sendResponseForResource(LibraryResource::collection($libraries));
50+
return response()->json($libraries, 200);
5151
}
5252

5353
public function destroy(LibraryDeleteRequest $request, int $id): JsonResponse

src/Http/Requests/LibraryListRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class LibraryListRequest extends FormRequest
1010
{
1111
public function authorize(): bool
1212
{
13-
return Gate::allows('list', H5PLibrary::class);
13+
return true;
1414
}
1515

1616
public function rules(): array

src/routes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@
3434
})->name('hh5p.index'); // DO not remove this is needed as prefix for editor ajax calls
3535
});
3636
});
37+
38+
Route::group(['prefix' => 'api/hh5p'], function () {
39+
Route::get('libraries', [LibraryApiController::class, 'libraries'])->name('hh5p.library.libraries');
40+
Route::post('libraries', [LibraryApiController::class, 'libraries'])->name('hh5p.library.libraries');
41+
});

tests/Api/LibraryApiTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function test_library_uploading(): void
1212
{
1313
$this->authenticateAsAdmin();
1414
$filename = 'arithmetic-quiz.h5p';
15-
$filepath = realpath(__DIR__.'/../mocks/'.$filename);
15+
$filepath = realpath(__DIR__ . '/../mocks/' . $filename);
1616
$storage_path = storage_path($filename);
1717

1818
copy($filepath, $storage_path);
@@ -68,17 +68,17 @@ public function testGuestCannotDeleteLibrary(): void
6868
$response->assertForbidden();
6969
}
7070

71-
public function testGuestCannotIndexLibrary(): void
71+
public function testGuestCanIndexLibrary(): void
7272
{
7373
$response = $this->get('/api/admin/hh5p/library');
7474

75-
$response->assertForbidden();
75+
$response->assertOk();
7676
}
7777

7878
public function testGuestCannotUploadLibrary(): void
7979
{
8080
$filename = 'arithmetic-quiz.h5p';
81-
$filepath = realpath(__DIR__.'/../mocks/'.$filename);
81+
$filepath = realpath(__DIR__ . '/../mocks/' . $filename);
8282
$storage_path = storage_path($filename);
8383

8484
copy($filepath, $storage_path);

0 commit comments

Comments
 (0)