diff --git a/.env.testing b/.env.testing index cdfbecfa..b0045eaf 100644 --- a/.env.testing +++ b/.env.testing @@ -1,6 +1,6 @@ APP_NAME=Laravel APP_ENV=local -APP_KEY=base64:qO2rFS9MzY3SKl6AqwV1jMAshl9jiaC02VNjXMhrMpo= +APP_KEY=base64:z6k1PzCZHXgOlUdNwFJzjKtyxIy8Qczl3POYpk3O94A= APP_DEBUG=true APP_URL=http://localhost APP_DEMO=false diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 3595196d..40e70220 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,6 +1,6 @@ { "/js/main.js": "/js/main.js", - "/chunks/request.js": "/chunks/request.js?id=4f2f083839a7f102", + "/chunks/request.js": "/chunks/request.js?id=2bbfd08f4a543123", "/chunks/request-upload.js": "/chunks/request-upload.js?id=1201e261c848a844", "/chunks/setup-wizard.js": "/chunks/setup-wizard.js?id=19a0784e59d768ec", "/chunks/status-check.js": "/chunks/status-check.js?id=a5ba5fb895af7040", @@ -9,13 +9,13 @@ "/chunks/environment.js": "/chunks/environment.js?id=e4fdb87ff173d48a", "/chunks/app-setup.js": "/chunks/app-setup.js?id=cbe7bfed06400736", "/chunks/admin-account.js": "/chunks/admin-account.js?id=78d257775f5fc485", - "/chunks/shared.js": "/chunks/shared.js?id=54c3bc26f2aab8d6", + "/chunks/shared.js": "/chunks/shared.js?id=2fd6e7e80c7a6090", "/chunks/shared/browser.js": "/chunks/shared/browser.js?id=ebf193e6828917dc", - "/chunks/shared/single-file.js": "/chunks/shared/single-file.js?id=e1ca697ccf4363dc", - "/chunks/shared/authenticate.js": "/chunks/shared/authenticate.js?id=b5519d193bce2339", + "/chunks/shared/single-file.js": "/chunks/shared/single-file.js?id=f03ab6659c6c1e9b", + "/chunks/shared/authenticate.js": "/chunks/shared/authenticate.js?id=cd743a710a7dd6b4", "/chunks/not-found.js": "/chunks/not-found.js?id=d31bd699138cf828", "/chunks/temporary-unavailable.js": "/chunks/temporary-unavailable.js?id=26798085f527d955", - "/chunks/admin.js": "/chunks/admin.js?id=60aa9e8508a842a1", + "/chunks/admin.js": "/chunks/admin.js?id=c9419b333cc023a5", "/chunks/dashboard.js": "/chunks/dashboard.js?id=5ab55a12214433c8", "/chunks/invoices.js": "/chunks/invoices.js?id=799928609f57ca10", "/chunks/subscriptions.js": "/chunks/subscriptions.js?id=a0c4f59d0ec4aee0", @@ -51,18 +51,19 @@ "/chunks/homepage.js": "/chunks/homepage.js?id=55c3e017e2a12876", "/chunks/dynamic-page.js": "/chunks/dynamic-page.js?id=9553d7a2912cb901", "/chunks/contact-us.js": "/chunks/contact-us.js?id=ea99d85aa3500595", + "/chunks/demo.js": "/chunks/demo.js?id=355303e4230cb5ae", "/chunks/successfully-email-verified.js": "/chunks/successfully-email-verified.js?id=c26cb144101e7c79", "/chunks/successfully-email-send.js": "/chunks/successfully-email-send.js?id=170d814982e1c475", "/chunks/sign-in.js": "/chunks/sign-in.js?id=1631a0f4a4ad25c2", "/chunks/sign-up.js": "/chunks/sign-up.js?id=2af6073efe54c560", "/chunks/forgotten-password.js": "/chunks/forgotten-password.js?id=ff8954243e86c1e1", "/chunks/create-new-password.js": "/chunks/create-new-password.js?id=2f0401ee2fc148c4", - "/chunks/settings.js": "/chunks/settings.js?id=2f6576332da7cad2", + "/chunks/settings.js": "/chunks/settings.js?id=22509bd0c45c0159", "/chunks/profile.js": "/chunks/profile.js?id=3e24bb5e1f52d4bb", "/chunks/settings-password.js": "/chunks/settings-password.js?id=d00bf503d8126dc4", "/chunks/settings-storage.js": "/chunks/settings-storage.js?id=ecfee7f7e98204f8", "/chunks/billing.js": "/chunks/billing.js?id=dd217d680baafb84", - "/chunks/platform.js": "/chunks/platform.js?id=220943bcb1e9f3ca", + "/chunks/platform.js": "/chunks/platform.js?id=a31d808015c4e7ea", "/chunks/files.js": "/chunks/files.js?id=5f29f35c280e680b", "/chunks/recent-uploads.js": "/chunks/recent-uploads.js?id=6f43aea38e0927bc", "/chunks/my-shared-items.js": "/chunks/my-shared-items.js?id=6e819ffe88a0fd1d", @@ -71,6 +72,5 @@ "/chunks/shared-with-me.js": "/chunks/shared-with-me.js?id=e86d3c1f72e6fde2", "/chunks/invitation.js": "/chunks/invitation.js?id=424b2783d9785a09", "/css/tailwind.css": "/css/tailwind.css", - "/css/app.css": "/css/app.css", - "/chunks/demo.js": "/chunks/demo.js?id=355303e4230cb5ae" + "/css/app.css": "/css/app.css" } diff --git a/resources/js/components/RemoteUpload/RemoteUploadPopup.vue b/resources/js/components/RemoteUpload/RemoteUploadPopup.vue index 28b0ac74..7ff3aecf 100644 --- a/resources/js/components/RemoteUpload/RemoteUploadPopup.vue +++ b/resources/js/components/RemoteUpload/RemoteUploadPopup.vue @@ -106,7 +106,7 @@ export default { // Get route let route = { RequestUpload: `/api/file-request/${this.$router.currentRoute.params.token}/upload/remote`, - Public: `/api/editor/upload/remote/${this.$router.currentRoute.params.token}`, + Public: `/api/sharing/upload/remote/${this.$router.currentRoute.params.token}`, }[this.$router.currentRoute.name] || '/api/upload/remote' let parentId = this.$store.getters.currentFolder diff --git a/resources/js/components/Spotlight/Spotlight.vue b/resources/js/components/Spotlight/Spotlight.vue index 9df80a82..80855f64 100644 --- a/resources/js/components/Spotlight/Spotlight.vue +++ b/resources/js/components/Spotlight/Spotlight.vue @@ -890,7 +890,7 @@ export default { // Get route let route = this.$store.getters.sharedDetail - ? `/api/search/${this.$router.currentRoute.params.token}` + ? `/api/sharing/search/${this.$router.currentRoute.params.token}` : '/api/search' axios diff --git a/resources/js/store/modules/fileBrowser.js b/resources/js/store/modules/fileBrowser.js index 0220cd64..26718974 100644 --- a/resources/js/store/modules/fileBrowser.js +++ b/resources/js/store/modules/fileBrowser.js @@ -105,7 +105,7 @@ const actions = { // Get route let route = { RequestUpload: `/api/file-request/${router.currentRoute.params.token}/navigation`, - Public: `/api/browse/navigation/${router.currentRoute.params.token}`, + Public: `/api/sharing/navigation/${router.currentRoute.params.token}`, }[router.currentRoute.name] || '/api/browse/navigation' axios diff --git a/resources/js/store/modules/fileFunctions.js b/resources/js/store/modules/fileFunctions.js index 536ee25a..b21a7aff 100644 --- a/resources/js/store/modules/fileFunctions.js +++ b/resources/js/store/modules/fileFunctions.js @@ -34,7 +34,7 @@ const actions = { // Get route let route = getters.sharedDetail - ? `/api/zip/${router.currentRoute.params.token}?items=${files.join(',')}` + ? `/api/sharing/zip/${router.currentRoute.params.token}?items=${files.join(',')}` : `/api/zip?items=${files.join(',')}` // Download zip @@ -60,14 +60,14 @@ const actions = { // Get route let route = { RequestUpload: `/api/file-request/${router.currentRoute.params.token}/move`, - Public: `/api/editor/move/${router.currentRoute.params.token}`, + Public: `/api/sharing/move/${router.currentRoute.params.token}`, }[router.currentRoute.name] || '/api/move' let moveToId = to_item.data ? to_item.data.id : to_item.id axios .post(route, { - to_id: moveToId || null, + to_id: moveToId || undefined, items: itemsToMove, }) .then(() => { @@ -88,7 +88,7 @@ const actions = { // Get route let route = { RequestUpload: `/api/file-request/${router.currentRoute.params.token}/create-folder`, - Public: `/api/editor/create-folder/${router.currentRoute.params.token}`, + Public: `/api/sharing/create-folder/${router.currentRoute.params.token}`, }[router.currentRoute.name] || '/api/create-folder' axios @@ -127,7 +127,7 @@ const actions = { // Get route let route = { RequestUpload: `/api/file-request/${router.currentRoute.params.token}/rename/${data.id}`, - Public: `/api/editor/rename/${data.id}/${router.currentRoute.params.token}`, + Public: `/api/sharing/rename/${data.id}/${router.currentRoute.params.token}`, }[router.currentRoute.name] || `/api/rename/${data.id}` axios @@ -150,7 +150,7 @@ const actions = { // Get route let route = { RequestUpload: `/api/file-request/${router.currentRoute.params.token}/upload/chunks`, - Public: `/api/editor/upload/chunks/${router.currentRoute.params.token}`, + Public: `/api/sharing/upload/chunks/${router.currentRoute.params.token}`, }[router.currentRoute.name] || '/api/upload/chunks' // Create cancel token for axios cancellation @@ -320,7 +320,7 @@ const actions = { // Get route let route = { RequestUpload: `/api/file-request/${router.currentRoute.params.token}/remove`, - Public: `/api/editor/remove/${router.currentRoute.params.token}`, + Public: `/api/sharing/remove/${router.currentRoute.params.token}`, }[router.currentRoute.name] || '/api/remove' axios diff --git a/resources/js/store/modules/sharing.js b/resources/js/store/modules/sharing.js index 9a9e4a8e..9344a3a1 100644 --- a/resources/js/store/modules/sharing.js +++ b/resources/js/store/modules/sharing.js @@ -25,7 +25,7 @@ const actions = { return new Promise((resolve, reject) => { axios - .get(`/api/browse/folders/${id}/${router.currentRoute.params.token}${getters.sorting.URI}`) + .get(`/api/sharing/folders/${id}/${router.currentRoute.params.token}${getters.sorting.URI}`) .then((response) => { let folders = response.data.folders.data let files = response.data.files.data @@ -50,7 +50,7 @@ const actions = { getShareDetail: ({ commit, state }, token) => { return new Promise((resolve, reject) => { axios - .get(`/api/browse/share/${token}`) + .get(`/api/sharing/share/${token}`) .then((response) => { resolve(response) diff --git a/resources/js/views/SharedAuthentication.vue b/resources/js/views/SharedAuthentication.vue index dae742a8..bd79e0b0 100644 --- a/resources/js/views/SharedAuthentication.vue +++ b/resources/js/views/SharedAuthentication.vue @@ -78,7 +78,7 @@ export default { // Send request to get verify account axios - .post('/api/browse/authenticate/' + this.$route.params.token, { + .post('/api/sharing/authenticate/' + this.$route.params.token, { password: this.password, }) .then((response) => { diff --git a/resources/js/views/SharedSingleFile.vue b/resources/js/views/SharedSingleFile.vue index f7d40d8f..5665bbb4 100644 --- a/resources/js/views/SharedSingleFile.vue +++ b/resources/js/views/SharedSingleFile.vue @@ -108,7 +108,7 @@ export default { }, mounted() { axios - .get(`/api/browse/file/${this.$router.currentRoute.params.token}`) + .get(`/api/sharing/file/${this.$router.currentRoute.params.token}`) .then((response) => { this.file = response.data }) diff --git a/routes/api.php b/routes/api.php index 527e07aa..c291d084 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,8 +1,8 @@ 'editor'], function () { - Route::post('/upload/remote/{shared}', VisitorRemoteUploadFileController::class); - Route::post('/upload/chunks/{shared}', VisitorUploadFileChunksController::class); +// Creating +Route::post('/upload/remote/{shared}', VisitorRemoteUploadFileController::class); +Route::post('/upload/chunks/{shared}', VisitorUploadFileChunksController::class); +Route::post('/upload/{shared}', VisitorUploadFileController::class); - Route::post('/create-folder/{shared}', VisitorCreateFolderController::class); +Route::post('/create-folder/{shared}', VisitorCreateFolderController::class); - Route::patch('/rename/{id}/{shared}', VisitorRenameFileOrFolderController::class); - Route::post('/remove/{shared}', VisitorDeleteFileOrFolderController::class); - Route::post('/move/{shared}', VisitorMoveFileOrFolderController::class); -}); - -// Zip shared items -Route::get('/zip/{shared}', VisitorZipController::class); +// Editing +Route::patch('/rename/{id}/{shared}', VisitorRenameFileOrFolderController::class); +Route::post('/remove/{shared}', VisitorDeleteFileOrFolderController::class); +Route::post('/move/{shared}', VisitorMoveFileOrFolderController::class); // Browse share content -Route::group(['prefix' => 'browse'], function () { - Route::post('/authenticate/{shared}', VisitorUnlockLockedShareController::class); - Route::get('/navigation/{shared}', VisitorNavigationFolderTreeController::class); - Route::get('/folders/{id}/{shared}', VisitorBrowseFolderController::class); - Route::get('/file/{shared}', VisitorShowFileController::class); - Route::get('/share/{share}', [ShareController::class, 'show']); -}); +Route::post('/authenticate/{shared}', VisitorUnlockLockedShareController::class); +Route::get('/navigation/{shared}', VisitorNavigationFolderTreeController::class); +Route::get('/folders/{id}/{shared}', VisitorBrowseFolderController::class); +Route::get('/file/{shared}', VisitorShowFileController::class); +Route::get('/share/{share}', [ShareController::class, 'show']); +// Others Route::get('/search/{shared}', VisitorSearchFilesAndFoldersController::class); Route::get('/og-site/{share}', WebCrawlerOpenGraphController::class); +Route::get('/zip/{shared}', VisitorZipController::class); diff --git a/src/App/Exceptions/Handler.php b/src/App/Exceptions/Handler.php index 3326bede..360e984c 100644 --- a/src/App/Exceptions/Handler.php +++ b/src/App/Exceptions/Handler.php @@ -51,9 +51,12 @@ class Handler extends ExceptionHandler { if ($exception instanceof ModelNotFoundException) { if (in_array('application/json', $request->getAcceptableContentTypes())) { + // Get ids + $ids = implode(', ', $exception->getIds()); + return response()->json([ 'type' => 'error', - 'message' => "We couldn't find your requested item.", + 'message' => "We couldn't find the resource you requested with id $ids", ], 404); } diff --git a/src/App/Providers/RouteServiceProvider.php b/src/App/Providers/RouteServiceProvider.php index b68870d9..1dfab120 100644 --- a/src/App/Providers/RouteServiceProvider.php +++ b/src/App/Providers/RouteServiceProvider.php @@ -39,7 +39,7 @@ class RouteServiceProvider extends ServiceProvider ->middleware('api') ->group(base_path('routes/api.php')); - Route::prefix('api') + Route::prefix('api/sharing') ->middleware('api') ->group(base_path('routes/share.php')); diff --git a/src/Domain/Browsing/Controllers/VisitorBrowseFolderController.php b/src/Domain/Browsing/Controllers/VisitorBrowseFolderController.php index fc0ddaad..5081370d 100644 --- a/src/Domain/Browsing/Controllers/VisitorBrowseFolderController.php +++ b/src/Domain/Browsing/Controllers/VisitorBrowseFolderController.php @@ -4,6 +4,7 @@ namespace Domain\Browsing\Controllers; use Domain\Files\Models\File; use Domain\Sharing\Models\Share; use Domain\Folders\Models\Folder; +use Illuminate\Http\JsonResponse; use Domain\Files\Resources\FilesCollection; use Domain\Folders\Resources\FolderResource; use Domain\Folders\Resources\FolderCollection; @@ -24,7 +25,7 @@ class VisitorBrowseFolderController public function __invoke( string $id, Share $shared, - ): array { + ): JsonResponse { // Check ability to access protected share record ($this->protectShareRecord)($shared); @@ -48,10 +49,10 @@ class VisitorBrowseFolderController // Set thumbnail links for public files $files->map(fn ($file) => $file->setSharedPublicUrl($shared->token)); - return [ + return response()->json([ 'folders' => new FolderCollection($folders), 'files' => new FilesCollection($files), 'root' => new FolderResource($requestedFolder), - ]; + ]); } } diff --git a/src/Domain/Browsing/Controllers/VisitorSearchFilesAndFoldersController.php b/src/Domain/Browsing/Controllers/VisitorSearchFilesAndFoldersController.php index 2fe682cc..a83ef301 100644 --- a/src/Domain/Browsing/Controllers/VisitorSearchFilesAndFoldersController.php +++ b/src/Domain/Browsing/Controllers/VisitorSearchFilesAndFoldersController.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use Domain\Files\Models\File; use Domain\Sharing\Models\Share; use Domain\Folders\Models\Folder; +use Illuminate\Http\JsonResponse; use App\Http\Controllers\Controller; use Domain\Files\Resources\FilesCollection; use Domain\Folders\Resources\FolderCollection; @@ -24,7 +25,7 @@ class VisitorSearchFilesAndFoldersController extends Controller public function __invoke( Request $request, Share $shared, - ): array { + ): JsonResponse { // Check ability to access protected share record ($this->protectShareRecord)($shared); @@ -70,9 +71,9 @@ class VisitorSearchFilesAndFoldersController extends Controller ->take(3); // Collect folders and files to single array - return [ + return response()->json([ 'folders' => new FolderCollection($folders), 'files' => new FilesCollection($files), - ]; + ]); } } diff --git a/src/Domain/Files/Controllers/VisitorShowFileController.php b/src/Domain/Files/Controllers/VisitorShowFileController.php index 7ccea4c4..337d8cbf 100644 --- a/src/Domain/Files/Controllers/VisitorShowFileController.php +++ b/src/Domain/Files/Controllers/VisitorShowFileController.php @@ -3,8 +3,8 @@ namespace Domain\Files\Controllers; use Gate; use Domain\Files\Models\File; -use Illuminate\Http\Response; use Domain\Sharing\Models\Share; +use Illuminate\Http\JsonResponse; use Domain\Files\Resources\FileResource; /** @@ -14,7 +14,7 @@ class VisitorShowFileController { public function __invoke( Share $shared - ): Response { + ): JsonResponse { $file = File::whereUserId($shared->user_id) ->whereId($shared->item_id) ->firstOrFail(); @@ -24,6 +24,6 @@ class VisitorShowFileController // Set access urls $file->setSharedPublicUrl($shared->token); - return response(new FileResource($file), 200); + return response()->json(new FileResource($file)); } } diff --git a/src/Domain/Files/Controllers/VisitorUploadFileChunksController.php b/src/Domain/Files/Controllers/VisitorUploadFileChunksController.php index 4d41fe22..da8b7dae 100644 --- a/src/Domain/Files/Controllers/VisitorUploadFileChunksController.php +++ b/src/Domain/Files/Controllers/VisitorUploadFileChunksController.php @@ -44,7 +44,12 @@ class VisitorUploadFileChunksController extends Controller // Check shared permission if (is_visitor($shared)) { - abort(403); + return response()->json(accessDeniedError(), 403); + } + + // Add default parent id if missing + if ($request->missing('parent_id')) { + $request->merge(['parent_id' => $shared->item_id]); } // Check access to requested directory diff --git a/src/Domain/Files/Controllers/VisitorUploadFileController.php b/src/Domain/Files/Controllers/VisitorUploadFileController.php new file mode 100644 index 00000000..0a877d64 --- /dev/null +++ b/src/Domain/Files/Controllers/VisitorUploadFileController.php @@ -0,0 +1,73 @@ +json(($this->fakeUploadFile)($request), 201); + } + + // Check ability to access protected share record + ($this->protectShareRecord)($shared); + + // Check shared permission + if (is_visitor($shared)) { + return response()->json(accessDeniedError(), 403); + } + + // Add default parent id if missing + if ($request->missing('parent_id')) { + $request->merge(['parent_id' => $shared->item_id]); + } + + // Check access to requested directory + ($this->verifyAccessToItem)($request->input('parent_id'), $shared); + + // Get file name + $name = Str::uuid() . '.' . $request->input('extension'); + + // Put file to user directory + Storage::disk('local')->put("files/$shared->user_id/$name", $request->file('file')->get()); + + // Process file + $file = ($this->processFie)($request, $shared->user, $name); + + // Set public access url + $file->setSharedPublicUrl($shared->token); + + return response()->json(new FileResource($file), 201); + } +} diff --git a/src/Domain/Folders/Controllers/VisitorCreateFolderController.php b/src/Domain/Folders/Controllers/VisitorCreateFolderController.php index d8ce4cdb..e68add33 100644 --- a/src/Domain/Folders/Controllers/VisitorCreateFolderController.php +++ b/src/Domain/Folders/Controllers/VisitorCreateFolderController.php @@ -1,8 +1,8 @@ fakeCreateFolder)($request); - return response(new FolderResource($fakeFolder), 201); + return response()->json(new FolderResource($fakeFolder), 201); } // Check ability to access protected share record @@ -40,21 +40,26 @@ class VisitorCreateFolderController extends Controller // Check shared permission if (is_visitor($shared)) { - abort(403); + return response()->json(accessDeniedError(), 403); + } + + // Add default parent id if missing + if ($request->missing('parent_id')) { + $request->merge(['parent_id' => $shared->item_id]); } // Check access to requested directory - ($this->verifyAccessToItem)($request->parent_id, $shared); + ($this->verifyAccessToItem)($request->input('parent_id'), $shared); try { // Create new folder $folder = ($this->createFolder)($request, $shared); // Return new folder - return response(new FolderResource($folder), 201); + return response()->json(new FolderResource($folder), 201); } catch (InvalidUserActionException $e) { // Return error response - return response([ + return response()->json([ 'type' => 'error', 'message' => $e->getMessage(), ], 401); diff --git a/src/Domain/Folders/Controllers/VisitorNavigationFolderTreeController.php b/src/Domain/Folders/Controllers/VisitorNavigationFolderTreeController.php index eac960c5..27566785 100644 --- a/src/Domain/Folders/Controllers/VisitorNavigationFolderTreeController.php +++ b/src/Domain/Folders/Controllers/VisitorNavigationFolderTreeController.php @@ -3,6 +3,7 @@ namespace Domain\Folders\Controllers; use Domain\Sharing\Models\Share; use Domain\Folders\Models\Folder; +use Illuminate\Http\JsonResponse; use App\Http\Controllers\Controller; use Domain\Sharing\Actions\ProtectShareRecordAction; use Domain\Sharing\Actions\VerifyAccessToItemAction; @@ -20,7 +21,7 @@ class VisitorNavigationFolderTreeController extends Controller public function __invoke( Share $shared, - ): array { + ): JsonResponse { // Check ability to access protected share record ($this->protectShareRecord)($shared); @@ -34,7 +35,7 @@ class VisitorNavigationFolderTreeController extends Controller ->sortable() ->get(['id', 'parent_id', 'id', 'name']); - return [ + return response()->json([ [ 'name' => __t('home'), 'location' => 'public', @@ -42,6 +43,6 @@ class VisitorNavigationFolderTreeController extends Controller 'isMovable' => true, 'isOpen' => true, ], - ]; + ]); } } diff --git a/src/Domain/Homepage/Controllers/SendContactMessageController.php b/src/Domain/Homepage/Controllers/SendContactMessageController.php index 766d3bce..e4b6b599 100644 --- a/src/Domain/Homepage/Controllers/SendContactMessageController.php +++ b/src/Domain/Homepage/Controllers/SendContactMessageController.php @@ -1,7 +1,7 @@ 'success', + 'message' => 'The message was successfully send', + ]; - $contactEmail = get_settings('contact_email'); - - if ($contactEmail) { - Mail::to($contactEmail) - ->send(new SendContactMessage($request->all())); + // Return success in demo mode + if (is_demo()) { + return response()->json($message); } - return response('Done', 201); + // Get contact mail + if ($contactEmail = get_settings('contact_email')) { + Mail::to($contactEmail)->send(new SendContactMessage($request->all())); + } + + return response()->json($message); } } diff --git a/src/Domain/Items/Controllers/VisitorDeleteFileOrFolderController.php b/src/Domain/Items/Controllers/VisitorDeleteFileOrFolderController.php index de20dc51..5dcf046b 100644 --- a/src/Domain/Items/Controllers/VisitorDeleteFileOrFolderController.php +++ b/src/Domain/Items/Controllers/VisitorDeleteFileOrFolderController.php @@ -1,8 +1,8 @@ 'success', + 'message' => 'Items was successfully deleted.', + ]; + if (isDemoAccount()) { - abort(204, 'Done.'); + return response()->json($message, 204); } // Check shared permission if (is_visitor($shared)) { - abort(403); + return response()->json(accessDeniedError(), 403); } foreach ($request->input('items') as $file) { @@ -47,6 +52,6 @@ class VisitorDeleteFileOrFolderController extends Controller ($this->deleteFileOrFolder)($file, $file['id'], $shared); } - return response('Done', 204); + return response()->json($message, 204); } } diff --git a/src/Domain/Items/Controllers/VisitorMoveFileOrFolderController.php b/src/Domain/Items/Controllers/VisitorMoveFileOrFolderController.php index 6b6b4023..6fcc7f28 100644 --- a/src/Domain/Items/Controllers/VisitorMoveFileOrFolderController.php +++ b/src/Domain/Items/Controllers/VisitorMoveFileOrFolderController.php @@ -2,8 +2,8 @@ namespace Domain\Items\Controllers; use Domain\Files\Models\File; -use Illuminate\Http\Response; use Domain\Sharing\Models\Share; +use Illuminate\Http\JsonResponse; use App\Http\Controllers\Controller; use Domain\Items\Requests\MoveItemRequest; use Domain\Items\Actions\MoveFileOrFolderAction; @@ -23,14 +23,24 @@ class VisitorMoveFileOrFolderController extends Controller public function __invoke( MoveItemRequest $request, Share $shared, - ): Response { + ): JsonResponse { + $successMessage = [ + 'type' => 'success', + 'message' => 'Items was successfully moved.', + ]; + if (isDemoAccount()) { - abort(204, 'Done.'); + return response()->json($successMessage); } // Check shared permission if (is_visitor($shared)) { - abort(403); + return response()->json(accessDeniedError(), 403); + } + + // Add default parent id if missing + if ($request->missing('to_id')) { + $request->merge(['to_id' => $shared->item_id]); } foreach ($request->input('items') as $item) { @@ -53,6 +63,6 @@ class VisitorMoveFileOrFolderController extends Controller ($this->moveFileOrFolder)($request, $shared); - return response('Done.', 204); + return response()->json($successMessage); } } diff --git a/src/Domain/Items/Controllers/VisitorRenameFileOrFolderController.php b/src/Domain/Items/Controllers/VisitorRenameFileOrFolderController.php index 767edca8..de2a9134 100644 --- a/src/Domain/Items/Controllers/VisitorRenameFileOrFolderController.php +++ b/src/Domain/Items/Controllers/VisitorRenameFileOrFolderController.php @@ -1,8 +1,8 @@ fakeRenameFileOrFolder)($request, $id); + return response()->json(($this->fakeRenameFileOrFolder)($request, $id)); } // Check shared permission if (is_visitor($shared)) { - abort(403); + return response()->json(accessDeniedError(), 403); } // Get file|folder item @@ -64,10 +64,10 @@ class VisitorRenameFileOrFolderController extends Controller } if ($request->input('type') === 'folder') { - return response(new FolderResource($item), 201); + return response()->json(new FolderResource($item), 201); } // Return updated item - return response(new FileResource($item), 201); + return response()->json(new FileResource($item), 201); } } diff --git a/src/Domain/Pages/Controllers/PagesController.php b/src/Domain/Pages/Controllers/ShowPageController.php similarity index 52% rename from src/Domain/Pages/Controllers/PagesController.php rename to src/Domain/Pages/Controllers/ShowPageController.php index 17a37c3e..5bb92ec6 100644 --- a/src/Domain/Pages/Controllers/PagesController.php +++ b/src/Domain/Pages/Controllers/ShowPageController.php @@ -2,16 +2,17 @@ namespace Domain\Pages\Controllers; use Domain\Pages\Models\Page; +use Illuminate\Http\JsonResponse; use App\Http\Controllers\Controller; use Domain\Pages\Resources\PageResource; -class PagesController extends Controller +class ShowPageController extends Controller { /** * Get single page content */ - public function show(Page $page): PageResource + public function __invoke(Page $page): JsonResponse { - return new PageResource($page); + return response()->json(new PageResource($page)); } } diff --git a/src/Domain/RemoteUpload/Controllers/VisitorRemoteUploadFileController.php b/src/Domain/RemoteUpload/Controllers/VisitorRemoteUploadFileController.php index 1ab2c349..74c80f9a 100644 --- a/src/Domain/RemoteUpload/Controllers/VisitorRemoteUploadFileController.php +++ b/src/Domain/RemoteUpload/Controllers/VisitorRemoteUploadFileController.php @@ -18,8 +18,10 @@ class VisitorRemoteUploadFileController extends Controller ) { } - public function __invoke(RemoteUploadRequest $request, ?Share $shared = null): JsonResponse - { + public function __invoke( + RemoteUploadRequest $request, + ?Share $shared = null, + ): JsonResponse { $successMessage = [ 'type' => 'success', 'message' => 'Files was successfully uploaded.', @@ -30,7 +32,12 @@ class VisitorRemoteUploadFileController extends Controller // Check shared permission if (is_visitor($shared)) { - abort(403, "You don't have access to this item"); + return response()->json(accessDeniedError(), 403); + } + + // Add default parent id if missing + if ($request->missing('parent_id')) { + $request->merge(['parent_id' => $shared->item_id]); } // Check access to requested directory diff --git a/src/Domain/Sharing/Actions/ProtectShareRecordAction.php b/src/Domain/Sharing/Actions/ProtectShareRecordAction.php index 716b6ff6..66de4391 100644 --- a/src/Domain/Sharing/Actions/ProtectShareRecordAction.php +++ b/src/Domain/Sharing/Actions/ProtectShareRecordAction.php @@ -5,14 +5,19 @@ use Domain\Sharing\Models\Share; class ProtectShareRecordAction { - private string $message = "Sorry, you don't have permission"; - public function __invoke( Share $shared ): void { if ($shared->is_protected) { + $errorResponse = [ + 'type' => 'error', + 'message' => "Sorry, you don't have permission", + ]; + if (! request()->hasCookie('share_session')) { - abort(403, $this->message); + abort( + response()->json($errorResponse, 403) + ); } // Get shared session @@ -22,12 +27,16 @@ class ProtectShareRecordAction // Check if is requested same share record if ($share_session->token !== $shared->token) { - abort(403, $this->message); + abort( + response()->json($errorResponse, 403) + ); } // Check if share record was authenticated previously via ShareController@authenticate if (! $share_session->authenticated) { - abort(403, $this->message); + abort( + response()->json($errorResponse, 403) + ); } } } diff --git a/src/Domain/Sharing/Controllers/ShareController.php b/src/Domain/Sharing/Controllers/ShareController.php index 57456d77..641b72ee 100644 --- a/src/Domain/Sharing/Controllers/ShareController.php +++ b/src/Domain/Sharing/Controllers/ShareController.php @@ -17,8 +17,8 @@ class ShareController extends Controller */ public function show( Share $share, - ): ShareResource { - return new ShareResource($share); + ): JsonResponse { + return response()->json(new ShareResource($share)); } /** diff --git a/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php b/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php index 47033206..e7ad75a8 100644 --- a/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php +++ b/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php @@ -4,8 +4,6 @@ namespace Domain\Sharing\Controllers; use Domain\Sharing\Models\Share; use Illuminate\Contracts\View\View; use App\Http\Controllers\Controller; -use Illuminate\Contracts\View\Factory; -use Illuminate\Contracts\Foundation\Application; class WebCrawlerOpenGraphController extends Controller { @@ -14,7 +12,7 @@ class WebCrawlerOpenGraphController extends Controller */ public function __invoke( Share $share - ): Application|Factory|View { + ): View { $namespace = match ($share->type) { 'folder' => 'Domain\\Folders\\Models\\Folder', 'file' => 'Domain\\Files\\Models\\File', diff --git a/tests/Domain/Homepage/HomepageTest.php b/tests/Domain/Homepage/HomepageTest.php index 4ccabcdb..d98670c4 100644 --- a/tests/Domain/Homepage/HomepageTest.php +++ b/tests/Domain/Homepage/HomepageTest.php @@ -69,7 +69,7 @@ class HomepageTest extends TestCase ]); $this - ->get("/api/og-site/$share->token") + ->get("/api/sharing/og-site/$share->token") ->assertStatus(200) ->assertSee('Folder Title'); } @@ -100,7 +100,7 @@ class HomepageTest extends TestCase ]); $this - ->get("/api/og-site/$share->token") + ->get("/api/sharing/og-site/$share->token") ->assertStatus(200) ->assertSee('Fake Image') ->assertSee('lg-fake-image.jpg'); @@ -132,7 +132,7 @@ class HomepageTest extends TestCase ]); $this - ->get("/api/og-site/$share->token") + ->get("/api/sharing/og-site/$share->token") ->assertStatus(200) ->assertSee('This link is protected by password'); } @@ -153,7 +153,7 @@ class HomepageTest extends TestCase 'email' => 'john@doe.com', 'message' => 'Whaats is up!', ]) - ->assertStatus(201); + ->assertStatus(200); Mail::assertSent(SendContactMessage::class); } diff --git a/tests/Domain/Sharing/VisitorAccessToItemsTest.php b/tests/Domain/Sharing/VisitorAccessToItemsTest.php index b4138fc8..7a3466ff 100644 --- a/tests/Domain/Sharing/VisitorAccessToItemsTest.php +++ b/tests/Domain/Sharing/VisitorAccessToItemsTest.php @@ -138,7 +138,7 @@ class VisitorAccessToItemsTest extends TestCase ]); // Get share record - $this->get("/api/browse/file/$share->token") + $this->get("/api/sharing/file/$share->token") ->assertStatus(403); } diff --git a/tests/Domain/Sharing/VisitorBrowseTest.php b/tests/Domain/Sharing/VisitorBrowseTest.php index e16de595..5aae0e9f 100644 --- a/tests/Domain/Sharing/VisitorBrowseTest.php +++ b/tests/Domain/Sharing/VisitorBrowseTest.php @@ -93,7 +93,7 @@ class VisitorBrowseTest extends TestCase 'password' => bcrypt('secret'), ]); - $this->postJson("/api/browse/authenticate/$share->token", [ + $this->postJson("/api/sharing/authenticate/$share->token", [ 'password' => 'secret', ]) ->assertStatus(200) @@ -120,7 +120,7 @@ class VisitorBrowseTest extends TestCase 'password' => bcrypt('secret'), ]); - $this->postJson("/api/browse/authenticate/$share->token", [ + $this->postJson("/api/sharing/authenticate/$share->token", [ 'password' => 'bad-password', ]) ->assertStatus(401) @@ -298,14 +298,14 @@ class VisitorBrowseTest extends TestCase $this ->withUnencryptedCookies($cookie) - ->get("/api/browse/navigation/$share->token") + ->get("/api/sharing/navigation/$share->token") ->assertStatus(200) ->assertExactJson($tree); } // Check public shared item if (! $is_protected) { - $this->getJson("/api/browse/navigation/$share->token") + $this->getJson("/api/sharing/navigation/$share->token") ->assertStatus(200) ->assertExactJson($tree); } @@ -348,7 +348,7 @@ class VisitorBrowseTest extends TestCase ])]; $this->withUnencryptedCookies($cookie) - ->get("/api/search/$share->token?query=doc") + ->get("/api/sharing/search/$share->token?query=doc") ->assertStatus(200) ->assertJsonFragment([ 'id' => $file->id, @@ -357,7 +357,7 @@ class VisitorBrowseTest extends TestCase // Check public shared item if (! $is_protected) { - $this->getJson("/api/search/$share->token?query=doc") + $this->getJson("/api/sharing/search/$share->token?query=doc") ->assertStatus(200) ->assertJsonFragment([ 'id' => $file->id, @@ -401,14 +401,14 @@ class VisitorBrowseTest extends TestCase ])]; $this->withUnencryptedCookies($cookie) - ->get("/api/search/$share->token?query=doc") + ->get("/api/sharing/search/$share->token?query=doc") ->assertStatus(200) ->assertJsonFragment([]); } // Check public shared item if (! $is_protected) { - $this->getJson("/api/search/$share->token?query=doc") + $this->getJson("/api/sharing/search/$share->token?query=doc") ->assertStatus(200) ->assertJsonFragment([]); } @@ -446,7 +446,7 @@ class VisitorBrowseTest extends TestCase ])]; $this->withUnencryptedCookies($cookie) - ->get("/api/browse/file/$share->token") + ->get("/api/sharing/file/$share->token") ->assertStatus(200) ->assertJsonFragment([ 'name' => 'Document', @@ -455,7 +455,7 @@ class VisitorBrowseTest extends TestCase // Check public shared item if (! $is_protected) { - $this->getJson("/api/browse/file/$share->token") + $this->getJson("/api/sharing/file/$share->token") ->assertStatus(200) ->assertJsonFragment([ 'name' => 'Document', diff --git a/tests/Domain/Sharing/VisitorManipulatingTest.php b/tests/Domain/Sharing/VisitorManipulatingTest.php index 28ff15c2..c398c5f8 100644 --- a/tests/Domain/Sharing/VisitorManipulatingTest.php +++ b/tests/Domain/Sharing/VisitorManipulatingTest.php @@ -52,7 +52,7 @@ class VisitorManipulatingTest extends TestCase $this ->withUnencryptedCookies($cookie) - ->patch("/api/editor/rename/{$file->id}/$share->token", [ + ->patch("/api/sharing/rename/{$file->id}/$share->token", [ 'name' => 'Renamed Item', 'type' => 'file', ]) @@ -64,7 +64,7 @@ class VisitorManipulatingTest extends TestCase // Check public shared item if (! $is_protected) { - $this->patchJson("/api/editor/rename/{$file->id}/$share->token", [ + $this->patchJson("/api/sharing/rename/{$file->id}/$share->token", [ 'name' => 'Renamed Item', 'type' => 'file', ]) @@ -122,7 +122,7 @@ class VisitorManipulatingTest extends TestCase $this ->withUnencryptedCookies($cookie) - ->patch("/api/editor/rename/{$children->id}/$share->token", [ + ->patch("/api/sharing/rename/{$children->id}/$share->token", [ 'name' => 'Renamed Folder', 'type' => 'folder', ]) @@ -134,7 +134,7 @@ class VisitorManipulatingTest extends TestCase // Check public shared item if (! $is_protected) { - $this->patchJson("/api/editor/rename/{$children->id}/$share->token", [ + $this->patchJson("/api/sharing/rename/{$children->id}/$share->token", [ 'name' => 'Renamed Folder', 'type' => 'folder', ]) @@ -186,7 +186,7 @@ class VisitorManipulatingTest extends TestCase $this ->withUnencryptedCookies($cookie) - ->post("/api/editor/create-folder/$share->token", [ + ->post("/api/sharing/create-folder/$share->token", [ 'name' => 'Awesome New Folder', 'parent_id' => $folder->id, ]) @@ -198,7 +198,7 @@ class VisitorManipulatingTest extends TestCase // Check public shared item if (! $is_protected) { - $this->postJson("/api/editor/create-folder/$share->token", [ + $this->postJson("/api/sharing/create-folder/$share->token", [ 'name' => 'Awesome New Folder', 'parent_id' => $folder->id, ]) @@ -272,13 +272,13 @@ class VisitorManipulatingTest extends TestCase $this ->withUnencryptedCookies($cookie) - ->post("/api/editor/remove/$share->token", $payload) + ->post("/api/sharing/remove/$share->token", $payload) ->assertStatus(204); } // Check public shared item if (! $is_protected) { - $this->postJson("/api/editor/remove/$share->token", $payload) + $this->postJson("/api/sharing/remove/$share->token", $payload) ->assertStatus(204); } @@ -329,7 +329,7 @@ class VisitorManipulatingTest extends TestCase $this ->withUnencryptedCookies($cookie) - ->post("/api/editor/upload/chunks/$share->token", [ + ->post("/api/sharing/upload/chunks/$share->token", [ 'name' => $file->name, 'extension' => 'pdf', 'chunk' => $file, @@ -340,7 +340,7 @@ class VisitorManipulatingTest extends TestCase // Check public shared item if (! $is_protected) { - $this->postJson("/api/editor/upload/chunks/$share->token", [ + $this->postJson("/api/sharing/upload/chunks/$share->token", [ 'name' => $file->name, 'extension' => 'pdf', 'chunk' => $file, @@ -414,14 +414,14 @@ class VisitorManipulatingTest extends TestCase $this ->withUnencryptedCookies($cookie) - ->post("/api/editor/move/$share->token", $payload) - ->assertStatus(204); + ->post("/api/sharing/move/$share->token", $payload) + ->assertStatus(200); } // Check public shared item if (! $is_protected) { - $this->postJson("/api/editor/move/$share->token", $payload) - ->assertStatus(204); + $this->postJson("/api/sharing/move/$share->token", $payload) + ->assertStatus(200); } $this->assertDatabaseHas('files', [ @@ -487,14 +487,14 @@ class VisitorManipulatingTest extends TestCase $this ->withUnencryptedCookies($cookie) - ->post("/api/editor/move/$share->token", $payload) - ->assertStatus(204); + ->post("/api/sharing/move/$share->token", $payload) + ->assertStatus(200); } // Check public shared item if (! $is_protected) { - $this->postJson("/api/editor/move/$share->token", $payload) - ->assertStatus(204); + $this->postJson("/api/sharing/move/$share->token", $payload) + ->assertStatus(200); } $this->assertDatabaseHas('folders', [ diff --git a/tests/Domain/Traffic/TrafficTest.php b/tests/Domain/Traffic/TrafficTest.php index 6ec404ac..06dd5589 100644 --- a/tests/Domain/Traffic/TrafficTest.php +++ b/tests/Domain/Traffic/TrafficTest.php @@ -113,7 +113,7 @@ class TrafficTest extends TestCase ]); // Check public shared item - $this->postJson("/api/editor/upload/chunks/$share->token", [ + $this->postJson("/api/sharing/upload/chunks/$share->token", [ 'name' => $this->file->name, 'chunk' => $this->file, 'parent_id' => $folder->id, diff --git a/tests/Support/Gate/GateTest.php b/tests/Support/Gate/GateTest.php index 46ceacc4..42e953d2 100644 --- a/tests/Support/Gate/GateTest.php +++ b/tests/Support/Gate/GateTest.php @@ -81,7 +81,7 @@ class GateTest extends TestCase $this ->withUnencryptedCookies($cookie) - ->patch("/api/editor/rename/{$children->id}/$share->token", [ + ->patch("/api/sharing/rename/{$children->id}/$share->token", [ 'name' => 'Renamed Folder', 'type' => 'folder', ]) @@ -93,7 +93,7 @@ class GateTest extends TestCase // Check public shared item if (! $is_protected) { - $this->patchJson("/api/editor/rename/{$children->id}/$share->token", [ + $this->patchJson("/api/sharing/rename/{$children->id}/$share->token", [ 'name' => 'Renamed Folder', 'type' => 'folder', ])