aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/src/service/PersonalInfo/PersonalInfoService.js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/src/service/PersonalInfo/PersonalInfoService.js')
-rw-r--r--apps/settings/src/service/PersonalInfo/PersonalInfoService.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/apps/settings/src/service/PersonalInfo/PersonalInfoService.js b/apps/settings/src/service/PersonalInfo/PersonalInfoService.js
new file mode 100644
index 00000000000..f2eaac91301
--- /dev/null
+++ b/apps/settings/src/service/PersonalInfo/PersonalInfoService.js
@@ -0,0 +1,61 @@
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import { getCurrentUser } from '@nextcloud/auth'
+import { generateOcsUrl } from '@nextcloud/router'
+import { confirmPassword } from '@nextcloud/password-confirmation'
+import axios from '@nextcloud/axios'
+
+import { SCOPE_SUFFIX } from '../../constants/AccountPropertyConstants.ts'
+
+import '@nextcloud/password-confirmation/dist/style.css'
+
+/**
+ * Save the primary account property value for the user
+ *
+ * @param {string} accountProperty the account property
+ * @param {string|boolean} value the primary value
+ * @return {object}
+ */
+export const savePrimaryAccountProperty = async (accountProperty, value) => {
+ // TODO allow boolean values on backend route handler
+ // Convert boolean to string for compatibility
+ if (typeof value === 'boolean') {
+ value = value ? '1' : '0'
+ }
+
+ const userId = getCurrentUser().uid
+ const url = generateOcsUrl('cloud/users/{userId}', { userId })
+
+ await confirmPassword()
+
+ const res = await axios.put(url, {
+ key: accountProperty,
+ value,
+ })
+
+ return res.data
+}
+
+/**
+ * Save the federation scope of the primary account property for the user
+ *
+ * @param {string} accountProperty the account property
+ * @param {string} scope the federation scope
+ * @return {object}
+ */
+export const savePrimaryAccountPropertyScope = async (accountProperty, scope) => {
+ const userId = getCurrentUser().uid
+ const url = generateOcsUrl('cloud/users/{userId}', { userId })
+
+ await confirmPassword()
+
+ const res = await axios.put(url, {
+ key: `${accountProperty}${SCOPE_SUFFIX}`,
+ value: scope,
+ })
+
+ return res.data
+}