diff --git a/appinfo/routes.php b/appinfo/routes.php index f45661fd..755ebd77 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -10,4 +10,6 @@ return ['routes' => [ ['name' => 'display#showPdfViewer', 'url' => '/', 'verb' => 'GET'], + ['name' => 'settings#getSettings', 'url' => '/settings', 'verb' => 'GET'], + ['name' => 'settings#setSettings', 'url' => '/settings', 'verb' => 'POST'], ]]; diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index ea6259b8..b55139e0 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -9,6 +9,7 @@ use OCA\Files_PDFViewer\Listeners\CSPListener; use OCA\Files_PDFViewer\Listeners\LoadViewerListener; +use OCA\Files_PDFViewer\Settings\AdminSettings; use OCA\Viewer\Event\LoadViewer; @@ -17,6 +18,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Security\CSP\AddContentSecurityPolicyEvent; +use OCP\Settings\ISettings; class Application extends App implements IBootstrap { public const APP_ID = 'files_pdfviewer'; @@ -28,6 +30,7 @@ public function __construct() { public function register(IRegistrationContext $context): void { $context->registerEventListener(LoadViewer::class, LoadViewerListener::class); $context->registerEventListener(AddContentSecurityPolicyEvent::class, CSPListener::class); + $context->registerSettings(ISettings::class, AdminSettings::class); } public function boot(IBootContext $context): void { diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php new file mode 100644 index 00000000..8078f448 --- /dev/null +++ b/lib/Controller/SettingsController.php @@ -0,0 +1,63 @@ +config = $config; + } + + /** + * Get current PDF scripting setting + */ + #[AuthorizedAdminSetting(settings: \OCA\Files_PDFViewer\Settings\AdminSettings::class)] + public function getSettings(): JSONResponse { + $enableScripting = $this->config->getAppValue( + Application::APP_ID, + 'enable_scripting', + 'no' + ) === 'yes'; + + return new JSONResponse([ + 'enableScripting' => $enableScripting, + ]); + } + + + /** + * Update PDF scripting setting + */ + #[AuthorizedAdminSetting(settings: \OCA\Files_PDFViewer\Settings\AdminSettings::class)] + public function setSettings(bool $enableScripting): JSONResponse { + $this->config->setAppValue( + Application::APP_ID, + 'enable_scripting', + $enableScripting ? 'yes' : 'no' + ); + + return new JSONResponse([ + 'enableScripting' => $enableScripting, + ]); + } +} diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php new file mode 100644 index 00000000..b504a526 --- /dev/null +++ b/lib/Settings/AdminSettings.php @@ -0,0 +1,36 @@ +config = $config; + } + + public function getForm(): TemplateResponse { + return new TemplateResponse(Application::APP_ID, 'admin', []); + } + + public function getSection(): string { + return 'server'; + } + + public function getPriority(): int { + return 50; + } +} diff --git a/src/admin.js b/src/admin.js new file mode 100644 index 00000000..4a3d9c1f --- /dev/null +++ b/src/admin.js @@ -0,0 +1,12 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import Vue from 'vue' +import AdminSettings from './components/AdminSettings.vue' + +Vue.prototype.t = t +Vue.prototype.n = n + +const View = Vue.extend(AdminSettings) +new View().$mount('#files_pdfviewer-admin-settings') diff --git a/src/components/AdminSettings.vue b/src/components/AdminSettings.vue new file mode 100644 index 00000000..c439fd97 --- /dev/null +++ b/src/components/AdminSettings.vue @@ -0,0 +1,79 @@ + + + + diff --git a/src/views/PDFView.vue b/src/views/PDFView.vue index 26350a5d..c9e4706a 100644 --- a/src/views/PDFView.vue +++ b/src/views/PDFView.vue @@ -145,7 +145,7 @@ export default { PDFViewerApplicationOptions.set('sandboxBundleSrc', this.getViewerTemplateParameter('sandbox')) PDFViewerApplicationOptions.set('enablePermissions', true) PDFViewerApplicationOptions.set('imageResourcesPath', this.getViewerTemplateParameter('imageresourcespath')) - PDFViewerApplicationOptions.set('enableScripting', this.getViewerTemplateParameter('enableScripting') === true) + PDFViewerApplicationOptions.set('enableScripting', this.getViewerTemplateParameter('enableScripting') === '1') const language = getLanguage() const supportedLanguages = SUPPORTED_LANGUAGES diff --git a/templates/admin.php b/templates/admin.php new file mode 100644 index 00000000..f8e8a619 --- /dev/null +++ b/templates/admin.php @@ -0,0 +1,10 @@ + + +
diff --git a/webpack.config.js b/webpack.config.js index b1457de5..d7bf91b3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,6 +13,7 @@ const { readdirSync } = require('fs') const l10nContent = readdirSync(path.resolve(__dirname, 'js', 'pdfjs', 'web', 'locale')) webpackConfig.entry.workersrc = path.resolve(path.join('src', 'workersrc.js')) +webpackConfig.entry.admin = path.resolve(path.join('src', 'admin.js')) // keep pdfjs vendor in the js folder webpackConfig.output.clean = false