From 3bd74de1d8d49c03707bd989a928e1b984430470 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Tue, 12 Jan 2021 13:41:19 +0100 Subject: [PATCH 1/6] Update backend to issue a 403 on a guest account Signed-off-by: Christian Wolf --- lib/Exception/UserFolderNotWritableException.php | 9 +++++++++ lib/Service/RecipeService.php | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 lib/Exception/UserFolderNotWritableException.php diff --git a/lib/Exception/UserFolderNotWritableException.php b/lib/Exception/UserFolderNotWritableException.php new file mode 100644 index 000000000..0ab1e4b79 --- /dev/null +++ b/lib/Exception/UserFolderNotWritableException.php @@ -0,0 +1,9 @@ +migrateFolderStructure(); + try { + $this->migrateFolderStructure(); + } catch (UserFolderNotWritableException $ex) { + // Ignore migration if not permitted. + $this->logger->warning("Cannot migrate cookbook file structure as not permitted."); + throw $ex; + } } private function migrateFolderStructure() { @@ -1030,7 +1037,11 @@ private function getOrCreateFolder($path) { if ($this->root->nodeExists($path)) { $folder = $this->root->get($path); } else { - $folder = $this->root->newFolder($path); + try { + $folder = $this->root->newFolder($path); + } catch (NotPermittedException $ex) { + throw new UserFolderNotWritableException($this->il10n->t('User cannot create recipe folder'), null, $ex); + } } return $folder; } From 48fbcdff8af24b56cc0ccab58189fd6c35fb8bec Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Tue, 12 Jan 2021 13:49:53 +0100 Subject: [PATCH 2/6] Update changelog Signed-off-by: Christian Wolf --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f1bc4b68..ef3abe378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ [#565](https://github.com/nextcloud/cookbook/pull/565/) - Enhanced testing interface [#564](https://github.com/nextcloud/cookbook/pull/564) @christianlupus +- Allow guest users to use the cookbook and avoid nextcloud exception handling + [#506](https://github.com/nextcloud/cookbook/pull/506) @christianlupus ### Fixed - Added some documentation how to install GH action generated builds From 4c6b9b6d2d36642db74919cea0a65672f93b5cf9 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Fri, 12 Feb 2021 12:56:47 +0100 Subject: [PATCH 3/6] Catch guest account without correct setting at loading of page Signed-off-by: Christian Wolf --- lib/Controller/MainController.php | 8 +++ src/components/AppInvalidGuest.vue | 87 ++++++++++++++++++++++++++++++ src/guest.js | 37 +++++++++++++ templates/invalid_guest.php | 6 +++ webpack.config.js | 1 + 5 files changed, 139 insertions(+) create mode 100644 src/components/AppInvalidGuest.vue create mode 100644 src/guest.js create mode 100644 templates/invalid_guest.php diff --git a/lib/Controller/MainController.php b/lib/Controller/MainController.php index d39bc898f..1db07f7f0 100755 --- a/lib/Controller/MainController.php +++ b/lib/Controller/MainController.php @@ -11,6 +11,7 @@ use OCA\Cookbook\Service\RecipeService; use OCA\Cookbook\Service\DbCacheService; use OCA\Cookbook\Helper\RestParameterParser; +use OCA\Cookbook\Exception\UserFolderNotWritableException; class MainController extends Controller { protected $appName; @@ -50,6 +51,13 @@ public function __construct(string $AppName, IRequest $request, RecipeService $r * @NoCSRFRequired */ public function index(): TemplateResponse { + try { + // Check if the user folder can be accessed + $this->service->getFolderForUser(); + } catch (UserFolderNotWritableException $ex) { + return new TemplateResponse($this->appName, 'invalid_guest'); + } + $this->dbCacheService->triggerCheck(); return new TemplateResponse($this->appName, 'index'); // templates/index.php diff --git a/src/components/AppInvalidGuest.vue b/src/components/AppInvalidGuest.vue new file mode 100644 index 000000000..33fff16c7 --- /dev/null +++ b/src/components/AppInvalidGuest.vue @@ -0,0 +1,87 @@ + + + + + \ No newline at end of file diff --git a/src/guest.js b/src/guest.js new file mode 100644 index 000000000..c11c2b70a --- /dev/null +++ b/src/guest.js @@ -0,0 +1,37 @@ +/** + * Nextcloud Cookbook app + * Vue frontend entry file + * --------------------------- + * @license AGPL3 or later +*/ + +import Vue from 'vue' +import store from './store' + +import AppInvalidGuest from './components/AppInvalidGuest' + +(function (OC, window) { + 'use strict' + + // Fetch Nextcloud nonce identifier for dynamic script loading + __webpack_nonce__ = btoa(OC.requestToken) + + window.baseUrl = OC.generateUrl('apps/cookbook') + + + // Also make the injections available in Vue components + Vue.prototype.$window = window + Vue.prototype.OC = OC + + // Pass translation engine to Vue + Vue.prototype.t = window.t + + // Start the app once document is done loading + document.addEventListener("DOMContentLoaded", function(event) { + const App = Vue.extend(AppInvalidGuest) + new App({ + store, + // router, + }).$mount("#content") + }) +})(OC, window) diff --git a/templates/invalid_guest.php b/templates/invalid_guest.php new file mode 100644 index 000000000..b1f435aac --- /dev/null +++ b/templates/invalid_guest.php @@ -0,0 +1,6 @@ + + +
+
diff --git a/webpack.config.js b/webpack.config.js index 0d8e5ee3b..5d0142fe9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -12,6 +12,7 @@ module.exports = { entry:{ vue: path.join(__dirname, 'src', 'main.js'), + guest: path.join(__dirname, 'src', 'guest.js'), }, output: { path: path.resolve(__dirname, './js'), From 0acbaccb1f56f77cfe7bcb7d39e2962a6b69d6f8 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 14 Feb 2021 12:59:50 +0100 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: seyfeb Signed-off-by: Christian Wolf --- src/components/AppInvalidGuest.vue | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/AppInvalidGuest.vue b/src/components/AppInvalidGuest.vue index 33fff16c7..60d14cd9b 100644 --- a/src/components/AppInvalidGuest.vue +++ b/src/components/AppInvalidGuest.vue @@ -1,18 +1,17 @@