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 diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index 1a4ca9dab..dc079abe4 100644 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -60,8 +60,6 @@ public function list() { * @NoCSRFRequired */ public function config() { - $this->dbCacheService->triggerCheck(); - $data = $this->restParser->getParameters(); if (isset($data['folder'])) { @@ -77,6 +75,8 @@ public function config() { $this->service->setPrintImage((bool)$data['print_image']); } + $this->dbCacheService->triggerCheck(); + return new DataResponse('OK', Http::STATUS_OK); } 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/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; } diff --git a/src/components/AppInvalidGuest.vue b/src/components/AppInvalidGuest.vue new file mode 100644 index 000000000..805ccd11f --- /dev/null +++ b/src/components/AppInvalidGuest.vue @@ -0,0 +1,89 @@ + + + + + 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'),