From 108abd77ed0ee29bca4019f6a212ba1b2bdad5e7 Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Thu, 17 Mar 2022 18:06:38 +0000 Subject: Add profile default setting for admin Signed-off-by: Christopher Ng --- .../components/BasicSettings/ProfileSettings.vue | 101 +++++++++++++++++++++ apps/settings/src/main-admin-basic-settings.js | 49 ++++++++++ apps/settings/src/service/ProfileService.js | 24 +++++ 3 files changed, 174 insertions(+) create mode 100644 apps/settings/src/components/BasicSettings/ProfileSettings.vue create mode 100644 apps/settings/src/main-admin-basic-settings.js (limited to 'apps/settings/src') diff --git a/apps/settings/src/components/BasicSettings/ProfileSettings.vue b/apps/settings/src/components/BasicSettings/ProfileSettings.vue new file mode 100644 index 00000000000..9abce3d787c --- /dev/null +++ b/apps/settings/src/components/BasicSettings/ProfileSettings.vue @@ -0,0 +1,101 @@ + + + + + + + diff --git a/apps/settings/src/main-admin-basic-settings.js b/apps/settings/src/main-admin-basic-settings.js new file mode 100644 index 00000000000..522ca392e77 --- /dev/null +++ b/apps/settings/src/main-admin-basic-settings.js @@ -0,0 +1,49 @@ +/** + * @copyright 2022 Christopher Ng + * + * @author Christopher Ng + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +import Vue from 'vue' +import { getRequestToken } from '@nextcloud/auth' +import { loadState } from '@nextcloud/initial-state' +import { translate as t } from '@nextcloud/l10n' +import '@nextcloud/dialogs/styles/toast.scss' + +import logger from './logger' + +import ProfileSettings from './components/BasicSettings/ProfileSettings' + +__webpack_nonce__ = btoa(getRequestToken()) + +const profileEnabledGlobally = loadState('settings', 'profileEnabledGlobally', true) + +Vue.mixin({ + props: { + logger, + }, + methods: { + t, + }, +}) + +if (profileEnabledGlobally) { + const ProfileSettingsView = Vue.extend(ProfileSettings) + new ProfileSettingsView().$mount('.vue-admin-profile-settings') +} diff --git a/apps/settings/src/service/ProfileService.js b/apps/settings/src/service/ProfileService.js index ca84316c655..f84135dd9d2 100644 --- a/apps/settings/src/service/ProfileService.js +++ b/apps/settings/src/service/ProfileService.js @@ -45,3 +45,27 @@ export const saveProfileParameterVisibility = async (paramId, visibility) => { return res.data } + +/** + * Save profile default + * + * @param {boolean} isEnabled the default + * @return {object} + */ +export const saveProfileDefault = async (isEnabled) => { + // Convert to string for compatibility + isEnabled = isEnabled ? '1' : '0' + + const url = generateOcsUrl('/apps/provisioning_api/api/v1/config/apps/{appId}/{key}', { + appId: 'settings', + key: 'profile_enabled_by_default', + }) + + await confirmPassword() + + const res = await axios.post(url, { + value: isEnabled, + }) + + return res.data +} -- cgit v1.2.3