From a0414f6f41bbd0890f773e8f1fe40f3e131f71a8 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 10 Sep 2024 18:16:52 +0200 Subject: [PATCH] fix(settings): Fix config handling Signed-off-by: provokateurin --- lib/Controller/FolderController.php | 11 +++++ package-lock.json | 67 +++++++++++++++++++++++++++++ package.json | 1 + src/settings/Api.ts | 21 +++++++++ 4 files changed, 100 insertions(+) diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php index 61e4b4358..124414bb0 100644 --- a/lib/Controller/FolderController.php +++ b/lib/Controller/FolderController.php @@ -27,6 +27,7 @@ use OCA\GroupFolders\Service\DelegationService; use OCA\GroupFolders\Service\FoldersFilter; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; use OCP\Files\IRootFolder; @@ -114,6 +115,7 @@ private function getRootFolderStorageId(): ?int { * @RequireGroupFolderAdmin * @NoAdminRequired */ + #[PasswordConfirmationRequired] public function addFolder(string $mountpoint): DataResponse { $id = $this->manager->createFolder($mountpoint); return new DataResponse(['id' => $id]); @@ -123,6 +125,7 @@ public function addFolder(string $mountpoint): DataResponse { * @NoAdminRequired * @RequireGroupFolderAdmin */ + #[PasswordConfirmationRequired] public function removeFolder(int $id): DataResponse { $response = $this->checkFolderExists($id); if ($response) { @@ -138,6 +141,7 @@ public function removeFolder(int $id): DataResponse { * @NoAdminRequired * @RequireGroupFolderAdmin */ + #[PasswordConfirmationRequired] public function setMountPoint(int $id, string $mountPoint): DataResponse { $this->manager->setMountPoint($id, $mountPoint); return new DataResponse(['success' => true]); @@ -147,6 +151,7 @@ public function setMountPoint(int $id, string $mountPoint): DataResponse { * @NoAdminRequired * @RequireGroupFolderAdmin */ + #[PasswordConfirmationRequired] public function addGroup(int $id, string $group): DataResponse { $response = $this->checkFolderExists($id); if ($response) { @@ -160,6 +165,7 @@ public function addGroup(int $id, string $group): DataResponse { * @NoAdminRequired * @RequireGroupFolderAdmin */ + #[PasswordConfirmationRequired] public function removeGroup(int $id, string $group): DataResponse { $response = $this->checkFolderExists($id); if ($response) { @@ -173,6 +179,7 @@ public function removeGroup(int $id, string $group): DataResponse { * @NoAdminRequired * @RequireGroupFolderAdmin */ + #[PasswordConfirmationRequired] public function setPermissions(int $id, string $group, int $permissions): DataResponse { $response = $this->checkFolderExists($id); if ($response) { @@ -187,6 +194,7 @@ public function setPermissions(int $id, string $group, int $permissions): DataRe * @RequireGroupFolderAdmin * @throws \OCP\DB\Exception */ + #[PasswordConfirmationRequired] public function setManageACL(int $id, string $mappingType, string $mappingId, bool $manageAcl): DataResponse { $response = $this->checkFolderExists($id); if ($response) { @@ -200,6 +208,7 @@ public function setManageACL(int $id, string $mappingType, string $mappingId, bo * @NoAdminRequired * @RequireGroupFolderAdmin */ + #[PasswordConfirmationRequired] public function setQuota(int $id, int $quota): DataResponse { $response = $this->checkFolderExists($id); if ($response) { @@ -213,6 +222,7 @@ public function setQuota(int $id, int $quota): DataResponse { * @NoAdminRequired * @RequireGroupFolderAdmin */ + #[PasswordConfirmationRequired] public function setACL(int $id, bool $acl): DataResponse { $response = $this->checkFolderExists($id); if ($response) { @@ -226,6 +236,7 @@ public function setACL(int $id, bool $acl): DataResponse { * @NoAdminRequired * @RequireGroupFolderAdmin */ + #[PasswordConfirmationRequired] public function renameFolder(int $id, string $mountpoint): DataResponse { $response = $this->checkFolderExists($id); if ($response) { diff --git a/package-lock.json b/package-lock.json index f3a48c241..f6e1a3072 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "dependencies": { "@nextcloud/axios": "^2.3.0", "@nextcloud/event-bus": "^3.0.2", + "@nextcloud/password-confirmation": "4.0.4", "@nextcloud/router": "^2.0.1", "@nextcloud/vue": "^7.7.1", "nextcloud-server": "^0.15.10", @@ -2366,6 +2367,44 @@ "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, + "node_modules/@nextcloud/password-confirmation": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/@nextcloud/password-confirmation/-/password-confirmation-4.0.4.tgz", + "integrity": "sha512-CdCOWwKU4ejKv0uABn3dfigwPH+tZKUOA38MzZDM4YyL1q9TgKOK90mnrJBvz6EBnlleZEvKlX94jjwPfOdvKw==", + "license": "MIT", + "dependencies": { + "@nextcloud/axios": "^2.0.0", + "@nextcloud/l10n": "^1.6.0", + "@nextcloud/router": "^2.0.0", + "@nextcloud/vue": "^7.0.0-beta.5", + "vue": "^2.7.10" + }, + "engines": { + "node": "^16.0.0", + "npm": "^7.0.0 || ^8.0.0" + } + }, + "node_modules/@nextcloud/password-confirmation/node_modules/@nextcloud/l10n": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@nextcloud/l10n/-/l10n-1.6.0.tgz", + "integrity": "sha512-aKGlgrwN9OiafN791sYus0shfwNeU3PlrH6Oi9ISma6iJSvN6a8aJM8WGKCJ9pqBaTR5PrDuckuM/WnybBWb6A==", + "license": "GPL-3.0-or-later", + "dependencies": { + "core-js": "^3.6.4", + "node-gettext": "^3.0.0" + } + }, + "node_modules/@nextcloud/password-confirmation/node_modules/core-js": { + "version": "3.38.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.38.1.tgz", + "integrity": "sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw==", + "hasInstallScript": true, + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/@nextcloud/router": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/@nextcloud/router/-/router-2.2.1.tgz", @@ -14740,6 +14779,34 @@ } } }, + "@nextcloud/password-confirmation": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/@nextcloud/password-confirmation/-/password-confirmation-4.0.4.tgz", + "integrity": "sha512-CdCOWwKU4ejKv0uABn3dfigwPH+tZKUOA38MzZDM4YyL1q9TgKOK90mnrJBvz6EBnlleZEvKlX94jjwPfOdvKw==", + "requires": { + "@nextcloud/axios": "^2.0.0", + "@nextcloud/l10n": "^1.6.0", + "@nextcloud/router": "^2.0.0", + "@nextcloud/vue": "^7.0.0-beta.5", + "vue": "^2.7.10" + }, + "dependencies": { + "@nextcloud/l10n": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@nextcloud/l10n/-/l10n-1.6.0.tgz", + "integrity": "sha512-aKGlgrwN9OiafN791sYus0shfwNeU3PlrH6Oi9ISma6iJSvN6a8aJM8WGKCJ9pqBaTR5PrDuckuM/WnybBWb6A==", + "requires": { + "core-js": "^3.6.4", + "node-gettext": "^3.0.0" + } + }, + "core-js": { + "version": "3.38.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.38.1.tgz", + "integrity": "sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw==" + } + } + }, "@nextcloud/router": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/@nextcloud/router/-/router-2.2.1.tgz", diff --git a/package.json b/package.json index 7aaa296c8..677dd44f4 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "dependencies": { "@nextcloud/axios": "^2.3.0", "@nextcloud/event-bus": "^3.0.2", + "@nextcloud/password-confirmation": "4.0.4", "@nextcloud/router": "^2.0.1", "@nextcloud/vue": "^7.7.1", "nextcloud-server": "^0.15.10", diff --git a/src/settings/Api.ts b/src/settings/Api.ts index 576de24d6..7897ea928 100644 --- a/src/settings/Api.ts +++ b/src/settings/Api.ts @@ -1,5 +1,6 @@ import axios from '@nextcloud/axios' import { generateUrl } from "@nextcloud/router"; +import { confirmPassword } from '@nextcloud/password-confirmation' // eslint-disable-next-line n/no-unpublished-import import type { OCSResponse } from '@nextcloud/typings/lib/ocs' @@ -59,6 +60,8 @@ export class Api { // Updates the list of groups that have been granted delegated admin or subadmin rights on groupfolders async updateDelegatedGroups(newGroups: Group[], classname: string): Promise { + await confirmPassword() + await axios.post(generateUrl('/apps/settings/') + '/settings/authorizedgroups/saveSettings', { newGroups, class: classname, @@ -66,27 +69,39 @@ export class Api { } async createFolder(mountPoint: string): Promise { + await confirmPassword() + const response = await axios.post>(this.getUrl('folders'), { mountpoint: mountPoint }) return response.data.ocs.data } async deleteFolder(id: number): Promise { + await confirmPassword() + await axios.delete(this.getUrl(`folders/${id}`)) } async addGroup(folderId: number, group: string): Promise { + await confirmPassword() + await axios.post(this.getUrl(`folders/${folderId}/groups`), { group }) } async removeGroup(folderId: number, group: string): Promise { + await confirmPassword() + await axios.delete(this.getUrl(`folders/${folderId}/groups/${group}`)) } async setPermissions(folderId: number, group: string, permissions: number): Promise { + await confirmPassword() + await axios.post(this.getUrl(`folders/${folderId}/groups/${group}`), { permissions }) } async setManageACL(folderId: number, type: string, id: string, manageACL: boolean): Promise { + await confirmPassword() + await axios.post(this.getUrl(`folders/${folderId}/manageACL`), { mappingType: type, mappingId: id, @@ -95,14 +110,20 @@ export class Api { } async setQuota(folderId: number, quota: number): Promise { + await confirmPassword() + await axios.post(this.getUrl(`folders/${folderId}/quota`), { quota }) } async setACL(folderId: number, acl: boolean): Promise { + await confirmPassword() + await axios.post(this.getUrl(`folders/${folderId}/acl`), { acl: acl ? 1 : 0 }) } async renameFolder(folderId: number, mountpoint: string): Promise { + await confirmPassword() + await axios.post(this.getUrl(`folders/${folderId}/mountpoint`), { mountpoint }) }