From 8d53ed15317c6f0d46b10e15085eb306977f779f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Carodej?= Date: Thu, 6 Jan 2022 11:05:49 +0100 Subject: [PATCH] - Frontend restriction shared page --- public/mix-manifest.json | 30 +++++++++++++-- resources/js/routes/routesIndex.js | 11 +++++- .../Components/NavigationSharePanel.vue | 10 ++++- resources/js/views/NotFound.vue | 18 +-------- resources/js/views/Shared.vue | 2 +- resources/js/views/TemporaryUnavailable.vue | 38 +++++++++++++++++++ .../Engines/DefaultRestrictionsEngine.php | 5 +++ .../FixedBillingRestrictionsEngine.php | 5 +++ .../MeteredBillingRestrictionsEngine.php | 6 +++ src/App/Restrictions/RestrictionsEngine.php | 2 + .../VisitorBrowseFolderController.php | 4 +- .../SharePublicIndexController.php | 11 ++++-- .../WebCrawlerOpenGraphController.php | 7 +++- .../Restrictions/DefaultRestrictionsTest.php | 19 ++++++++++ .../FixedBillingRestrictionsTest.php | 19 ++++++++++ .../MeteredBillingRestrictionsTest.php | 20 ++++++++++ tests/Domain/Sharing/VisitorBrowseTest.php | 17 ++++++--- 17 files changed, 188 insertions(+), 36 deletions(-) create mode 100644 resources/js/views/TemporaryUnavailable.vue diff --git a/public/mix-manifest.json b/public/mix-manifest.json index acb8ff7a..b86e8cf3 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -53,7 +53,7 @@ "/chunks/invitation.js": "/chunks/invitation.js?id=b3a04d44ea7e75c6203a", "/chunks/invoices.js": "/chunks/invoices.js?id=2032e4f8e4f5ed58b8b4", "/chunks/my-shared-items.js": "/chunks/my-shared-items.js?id=ef0a2dbe808eaee42c1f", - "/chunks/not-found.js": "/chunks/not-found.js?id=034287ee0ecb036320d3", + "/chunks/not-found.js": "/chunks/not-found.js?id=9b179edd89e9b0544566", "/chunks/page-edit.js": "/chunks/page-edit.js?id=1b8c9a0eee76fcb52f12", "/chunks/pages.js": "/chunks/pages.js?id=8c6772e3224fadca2bf2", "/chunks/plan.js": "/chunks/plan.js?id=f62a5bd64fb706b2f0e2", @@ -75,7 +75,7 @@ "/chunks/settings-storage.js": "/chunks/settings-storage.js?id=76b45c336e8e12b23e81", "/chunks/settings~chunks/settings-password.js": "/chunks/settings~chunks/settings-password.js?id=aafc9cd6aa47b01bc25a", "/chunks/setup-wizard.js": "/chunks/setup-wizard.js?id=651d5accf401908724c5", - "/chunks/shared.js": "/chunks/shared.js?id=387e9dc2cb6e3e328cf4", + "/chunks/shared.js": "/chunks/shared.js?id=db60726012b6d246bd77", "/chunks/shared-with-me.js": "/chunks/shared-with-me.js?id=cf39d503eef93bcc7f1c", "/chunks/shared-with-me~chunks/team-folders.js": "/chunks/shared-with-me~chunks/team-folders.js?id=abf65131397ea2b12355", "/chunks/shared/authenticate.js": "/chunks/shared/authenticate.js?id=e19e444844d1495d900f", @@ -217,5 +217,29 @@ "/js/main.fcf019dfae2cac8e0432.hot-update.js": "/js/main.fcf019dfae2cac8e0432.hot-update.js", "/js/main.b99796b9cd80dfca9231.hot-update.js": "/js/main.b99796b9cd80dfca9231.hot-update.js", "/js/main.ff162a01c1b21836ee9f.hot-update.js": "/js/main.ff162a01c1b21836ee9f.hot-update.js", - "/js/main.7a46e4ea987d72347892.hot-update.js": "/js/main.7a46e4ea987d72347892.hot-update.js" + "/js/main.7a46e4ea987d72347892.hot-update.js": "/js/main.7a46e4ea987d72347892.hot-update.js", + "/chunks/shared.e292a21450a2e96c5b77.hot-update.js": "/chunks/shared.e292a21450a2e96c5b77.hot-update.js", + "/chunks/shared.ea4e7bbd3ce9f55a2c8e.hot-update.js": "/chunks/shared.ea4e7bbd3ce9f55a2c8e.hot-update.js", + "/chunks/shared.836f769daafe640518ac.hot-update.js": "/chunks/shared.836f769daafe640518ac.hot-update.js", + "/js/main.d457be736ef017a782ea.hot-update.js": "/js/main.d457be736ef017a782ea.hot-update.js", + "/chunks/platform~chunks/shared.d457be736ef017a782ea.hot-update.js": "/chunks/platform~chunks/shared.d457be736ef017a782ea.hot-update.js", + "/chunks/shared.d457be736ef017a782ea.hot-update.js": "/chunks/shared.d457be736ef017a782ea.hot-update.js", + "/js/main.83361deb74c3e1859144.hot-update.js": "/js/main.83361deb74c3e1859144.hot-update.js", + "/chunks/admin~chunks/platform.83361deb74c3e1859144.hot-update.js": "/chunks/admin~chunks/platform.83361deb74c3e1859144.hot-update.js", + "/chunks/platform.83361deb74c3e1859144.hot-update.js": "/chunks/platform.83361deb74c3e1859144.hot-update.js", + "/chunks/shared.83361deb74c3e1859144.hot-update.js": "/chunks/shared.83361deb74c3e1859144.hot-update.js", + "/chunks/shared.3b938ab55dc98ab07bd9.hot-update.js": "/chunks/shared.3b938ab55dc98ab07bd9.hot-update.js", + "/js/main.1f3af2652193f43c092d.hot-update.js": "/js/main.1f3af2652193f43c092d.hot-update.js", + "/js/main.fef96a82e13da818af79.hot-update.js": "/js/main.fef96a82e13da818af79.hot-update.js", + "/chunks/app-setup~chunks/billings-detail~chunks/create-new-password~chunks/database~chunks/email-veri~2c1222b7.js": "/chunks/app-setup~chunks/billings-detail~chunks/create-new-password~chunks/database~chunks/email-veri~2c1222b7.js?id=f8d41224222e2bd2040e", + "/chunks/temporary-unavailable.js": "/chunks/temporary-unavailable.js?id=2269ad0b9a010b240838", + "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~8c6958f5.js": "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~8c6958f5.js?id=b94057ad23d11b238e2b", + "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~c31998a3.js": "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~c31998a3.js?id=78abc0680fedc29e1146", + "/js/main.4e470711fec628ada904.hot-update.js": "/js/main.4e470711fec628ada904.hot-update.js", + "/chunks/temporary-unavailable.4e470711fec628ada904.hot-update.js": "/chunks/temporary-unavailable.4e470711fec628ada904.hot-update.js", + "/chunks/temporary-unavailable.eb45683c53ba28a1beaa.hot-update.js": "/chunks/temporary-unavailable.eb45683c53ba28a1beaa.hot-update.js", + "/js/main.819e5cdfad5c00b05e6a.hot-update.js": "/js/main.819e5cdfad5c00b05e6a.hot-update.js", + "/chunks/not-found.819e5cdfad5c00b05e6a.hot-update.js": "/chunks/not-found.819e5cdfad5c00b05e6a.hot-update.js", + "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~91d4a521.js": "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~91d4a521.js?id=b563ab4d2bf1a17f0fa5", + "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~af91ece5.js": "/vendors~chunks/admin~chunks/admin-account~chunks/app-appearance~chunks/app-billings~chunks/app-email~af91ece5.js?id=9a44c9cf620730dc67d5" } diff --git a/resources/js/routes/routesIndex.js b/resources/js/routes/routesIndex.js index 4f201b0e..1bd50c14 100644 --- a/resources/js/routes/routesIndex.js +++ b/resources/js/routes/routesIndex.js @@ -30,7 +30,16 @@ const routesIndex = [ name: 'NotFound', path: '/not-found', component: () => - import(/* webpackChunkName: "chunks/not-found-shared" */ '../views/NotFound'), + import(/* webpackChunkName: "chunks/not-found" */ '../views/NotFound'), + meta: { + requiresAuth: false + }, + }, + { + name: 'TemporaryUnavailable', + path: '/temporary-unavailable', + component: () => + import(/* webpackChunkName: "chunks/temporary-unavailable" */ '../views/TemporaryUnavailable'), meta: { requiresAuth: false }, diff --git a/resources/js/views/FileView/Components/NavigationSharePanel.vue b/resources/js/views/FileView/Components/NavigationSharePanel.vue index f87cd3d8..00d212be 100644 --- a/resources/js/views/FileView/Components/NavigationSharePanel.vue +++ b/resources/js/views/FileView/Components/NavigationSharePanel.vue @@ -8,7 +8,7 @@
- {{ $t('sidebar.home') }} + {{ $t('Home') }}
@@ -75,7 +75,13 @@ export default { }, methods: { goHome() { - this.$router.replace({name: 'Public', params: {token: this.$route.params.token, id: this.sharedDetail.item_id}}) + this.$router.replace({ + name: 'Public', + params: { + token: this.sharedDetail.data.attributes.token, + id: this.sharedDetail.data.attributes.item_id + } + }) }, dragLeave() { this.area = false diff --git a/resources/js/views/NotFound.vue b/resources/js/views/NotFound.vue index 82b6a990..580b5657 100644 --- a/resources/js/views/NotFound.vue +++ b/resources/js/views/NotFound.vue @@ -1,12 +1,10 @@ + + + + diff --git a/src/App/Restrictions/Engines/DefaultRestrictionsEngine.php b/src/App/Restrictions/Engines/DefaultRestrictionsEngine.php index 63e218b1..52e71c90 100644 --- a/src/App/Restrictions/Engines/DefaultRestrictionsEngine.php +++ b/src/App/Restrictions/Engines/DefaultRestrictionsEngine.php @@ -43,4 +43,9 @@ class DefaultRestrictionsEngine implements RestrictionsEngine { return resolve(CheckMaxTeamMembersLimitAction::class)($user, $newInvites); } + + public function canVisitShared(User $user): bool + { + return true; + } } diff --git a/src/App/Restrictions/Engines/FixedBillingRestrictionsEngine.php b/src/App/Restrictions/Engines/FixedBillingRestrictionsEngine.php index cf8a70e7..d72d1b08 100644 --- a/src/App/Restrictions/Engines/FixedBillingRestrictionsEngine.php +++ b/src/App/Restrictions/Engines/FixedBillingRestrictionsEngine.php @@ -38,4 +38,9 @@ class FixedBillingRestrictionsEngine implements RestrictionsEngine { return resolve(CheckMaxTeamMembersLimitAction::class)($user, $newInvites); } + + public function canVisitShared(User $user): bool + { + return true; + } } diff --git a/src/App/Restrictions/Engines/MeteredBillingRestrictionsEngine.php b/src/App/Restrictions/Engines/MeteredBillingRestrictionsEngine.php index 548ead7e..9464eee2 100644 --- a/src/App/Restrictions/Engines/MeteredBillingRestrictionsEngine.php +++ b/src/App/Restrictions/Engines/MeteredBillingRestrictionsEngine.php @@ -34,4 +34,10 @@ class MeteredBillingRestrictionsEngine implements RestrictionsEngine { return true; } + + public function canVisitShared(User $user): bool + { + // Disable share visit when user has more than 3 failed payments + return ! ($user->failedPayments()->count() >= 3); + } } diff --git a/src/App/Restrictions/RestrictionsEngine.php b/src/App/Restrictions/RestrictionsEngine.php index 1d91280e..77572dcb 100644 --- a/src/App/Restrictions/RestrictionsEngine.php +++ b/src/App/Restrictions/RestrictionsEngine.php @@ -14,4 +14,6 @@ interface RestrictionsEngine public function canCreateTeamFolder(User $user): bool; public function canInviteTeamMembers(User $user, array $newInvites = []): bool; + + public function canVisitShared(User $user): bool; } diff --git a/src/Domain/Browsing/Controllers/VisitorBrowseFolderController.php b/src/Domain/Browsing/Controllers/VisitorBrowseFolderController.php index 38becf8b..625c96c7 100644 --- a/src/Domain/Browsing/Controllers/VisitorBrowseFolderController.php +++ b/src/Domain/Browsing/Controllers/VisitorBrowseFolderController.php @@ -2,6 +2,7 @@ namespace Domain\Browsing\Controllers; use Domain\Files\Models\File; +use Domain\Folders\Resources\FolderResource; use Domain\Sharing\Models\Share; use Domain\Folders\Models\Folder; use Domain\Files\Resources\FilesCollection; @@ -30,6 +31,7 @@ class VisitorBrowseFolderController // Check if user can get directory ($this->verifyAccessToItem)($id, $shared); + // Get requested folder $requestedFolder = Folder::findOrFail($id); // Get files and folders @@ -49,7 +51,7 @@ class VisitorBrowseFolderController return [ 'folders' => new FolderCollection($folders), 'files' => new FilesCollection($files), - 'root' => $requestedFolder, + 'root' => new FolderResource($requestedFolder), ]; } } diff --git a/src/Domain/Sharing/Controllers/SharePublicIndexController.php b/src/Domain/Sharing/Controllers/SharePublicIndexController.php index a1ceeddc..3a46ea7f 100644 --- a/src/Domain/Sharing/Controllers/SharePublicIndexController.php +++ b/src/Domain/Sharing/Controllers/SharePublicIndexController.php @@ -1,6 +1,7 @@ user->canVisitShared()) { + return redirect('/temporary-unavailable'); + } + // Delete share_session if exist if ($share->is_protected) { cookie()->queue('share_session', '', -1); diff --git a/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php b/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php index b1b43db5..7c7f0e6f 100644 --- a/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php +++ b/src/Domain/Sharing/Controllers/WebCrawlerOpenGraphController.php @@ -1,7 +1,9 @@ type) { 'folder' => 'Domain\\Folders\\Models\\Folder', 'file' => 'Domain\\Files\\Models\\File', diff --git a/tests/App/Restrictions/DefaultRestrictionsTest.php b/tests/App/Restrictions/DefaultRestrictionsTest.php index 3378a612..46634eec 100644 --- a/tests/App/Restrictions/DefaultRestrictionsTest.php +++ b/tests/App/Restrictions/DefaultRestrictionsTest.php @@ -235,4 +235,23 @@ class DefaultRestrictionsTest extends TestCase ->get("file/$file->name/$share->token") ->assertStatus(404); } + + /** + * @test + */ + public function it_can_get_share_page() + { + $user = User::factory() + ->create(); + + $share = Share::factory() + ->create([ + 'user_id' => $user->id, + 'type' => 'folder', + 'is_protected' => false, + ]); + + $this->get("/share/$share->token") + ->assertViewIs('index'); + } } diff --git a/tests/App/Restrictions/FixedBillingRestrictionsTest.php b/tests/App/Restrictions/FixedBillingRestrictionsTest.php index 348adefe..71020a23 100644 --- a/tests/App/Restrictions/FixedBillingRestrictionsTest.php +++ b/tests/App/Restrictions/FixedBillingRestrictionsTest.php @@ -196,4 +196,23 @@ class FixedBillingRestrictionsTest extends TestCase ->get("file/$file->name/$share->token") ->assertStatus(404); } + + /** + * @test + */ + public function it_can_get_share_page() + { + $user = User::factory() + ->create(); + + $share = Share::factory() + ->create([ + 'user_id' => $user->id, + 'type' => 'folder', + 'is_protected' => false, + ]); + + $this->get("/share/$share->token") + ->assertViewIs('index'); + } } diff --git a/tests/App/Restrictions/MeteredBillingRestrictionsTest.php b/tests/App/Restrictions/MeteredBillingRestrictionsTest.php index caf65836..6f6998a5 100644 --- a/tests/App/Restrictions/MeteredBillingRestrictionsTest.php +++ b/tests/App/Restrictions/MeteredBillingRestrictionsTest.php @@ -213,4 +213,24 @@ class MeteredBillingRestrictionsTest extends TestCase ->get("file/$file->name/$share->token") ->assertStatus(404); } + + /** + * @test + */ + public function it_cant_get_share_page() + { + $user = User::factory() + ->hasFailedpayments(3) + ->create(); + + $share = Share::factory() + ->create([ + 'user_id' => $user->id, + 'type' => 'folder', + 'is_protected' => false, + ]); + + $this->get("/share/$share->token") + ->assertRedirect('/temporary-unavailable'); + } } diff --git a/tests/Domain/Sharing/VisitorBrowseTest.php b/tests/Domain/Sharing/VisitorBrowseTest.php index ab7e78e8..4f2582f0 100644 --- a/tests/Domain/Sharing/VisitorBrowseTest.php +++ b/tests/Domain/Sharing/VisitorBrowseTest.php @@ -1,4 +1,5 @@ create(); + $share = Share::factory() ->create([ + 'user_id' => $user->id, 'type' => 'folder', 'is_protected' => false, ]); @@ -69,7 +74,7 @@ class VisitorBrowseTest extends TestCase public function it_try_to_get_deleted_share_page() { $this->get('/share/19ZMPNiass4ZqWwQ') - ->assertNotFound(404); + ->assertNotFound(); } /** @@ -188,7 +193,7 @@ class VisitorBrowseTest extends TestCase } // Check public shared item - if (! $is_protected) { + if (!$is_protected) { $this->getJson("/api/browse/folders/$root->id/$share->token") ->assertStatus(200) ->assertJsonFragment([ @@ -303,7 +308,7 @@ class VisitorBrowseTest extends TestCase } // Check public shared item - if (! $is_protected) { + if (!$is_protected) { $this->getJson("/api/browse/navigation/$share->token") ->assertStatus(200) ->assertExactJson($tree); @@ -355,7 +360,7 @@ class VisitorBrowseTest extends TestCase } // Check public shared item - if (! $is_protected) { + if (!$is_protected) { $this->getJson("/api/browse/search/$share->token?query=doc") ->assertStatus(200) ->assertJsonFragment([ @@ -406,7 +411,7 @@ class VisitorBrowseTest extends TestCase } // Check public shared item - if (! $is_protected) { + if (!$is_protected) { $this->getJson("/api/browse/search/$share->token?query=doc") ->assertStatus(200) ->assertJsonFragment([]); @@ -453,7 +458,7 @@ class VisitorBrowseTest extends TestCase } // Check public shared item - if (! $is_protected) { + if (!$is_protected) { $this->getJson("/api/browse/file/$share->token") ->assertStatus(200) ->assertJsonFragment([