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 @@
+
+