Skip to content

Commit

Permalink
Merge pull request #31624 from nextcloud/backport/29372/stable23
Browse files Browse the repository at this point in the history
  • Loading branch information
Pytal committed Mar 25, 2022
2 parents 70163ec + d8c0446 commit fea072c
Show file tree
Hide file tree
Showing 46 changed files with 718 additions and 328 deletions.
156 changes: 156 additions & 0 deletions apps/settings/js/vue-settings-admin-basic-settings.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/settings/js/vue-settings-admin-basic-settings.js.map

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions apps/settings/js/vue-settings-admin-delegation.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-admin-delegation.js.map

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions apps/settings/js/vue-settings-admin-security.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-admin-security.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions apps/settings/js/vue-settings-apps-users-management.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-apps-users-management.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/settings/js/vue-settings-apps.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-apps.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions apps/settings/js/vue-settings-nextcloud-pdf.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-nextcloud-pdf.js.map

Large diffs are not rendered by default.

178 changes: 88 additions & 90 deletions apps/settings/js/vue-settings-personal-info.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-personal-info.js.map

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions apps/settings/js/vue-settings-personal-security.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-personal-security.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions apps/settings/js/vue-settings-personal-webauthn.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-personal-webauthn.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions apps/settings/js/vue-settings-users.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-users.js.map

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions apps/settings/js/vue-vendors-settings-apps-settings-users.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions apps/settings/js/vue-vendors-settings-apps.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-vendors-settings-apps.js.map

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions apps/settings/js/vue-vendors-settings-users.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-vendors-settings-users.js.map

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions apps/settings/lib/Settings/Admin/Server.php
Expand Up @@ -25,17 +25,25 @@
*/
namespace OCA\Settings\Settings\Admin;

use OC\Profile\ProfileManager;
use OC\Profile\TProfileHelper;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\Settings\IDelegatedSettings;

class Server implements IDelegatedSettings {
use TProfileHelper;

/** @var IDBConnection */
private $connection;
/** @var IInitialState */
private $initialStateService;
/** @var ProfileManager */
private $profileManager;
/** @var ITimeFactory */
private $timeFactory;
/** @var IConfig */
Expand All @@ -44,10 +52,14 @@ class Server implements IDelegatedSettings {
private $l;

public function __construct(IDBConnection $connection,
IInitialState $initialStateService,
ProfileManager $profileManager,
ITimeFactory $timeFactory,
IConfig $config,
IL10N $l) {
$this->connection = $connection;
$this->initialStateService = $initialStateService;
$this->profileManager = $profileManager;
$this->timeFactory = $timeFactory;
$this->config = $config;
$this->l = $l;
Expand All @@ -65,8 +77,12 @@ public function getForm() {
'cronErrors' => $this->config->getAppValue('core', 'cronErrors'),
'cli_based_cron_possible' => function_exists('posix_getpwuid'),
'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '',
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
];

$this->initialStateService->provideInitialState('profileEnabledGlobally', $this->profileManager->isProfileEnabled());
$this->initialStateService->provideInitialState('profileEnabledByDefault', $this->isProfileEnabledByDefault($this->config));

return new TemplateResponse('settings', 'settings/admin/server', $parameters, '');
}

Expand Down
8 changes: 5 additions & 3 deletions apps/settings/lib/Settings/Personal/PersonalInfo.php
Expand Up @@ -56,7 +56,6 @@
use OCP\Settings\ISettings;

class PersonalInfo implements ISettings {
use \OC\Profile\TProfileHelper;

/** @var IConfig */
private $config;
Expand Down Expand Up @@ -166,15 +165,17 @@ public function getForm(): TemplateResponse {
'twitterScope' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getScope(),
'twitterVerification' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getVerified(),
'groups' => $this->getGroups($user),
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService()
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
] + $messageParameters + $languageParameters + $localeParameters;

$personalInfoParameters = [
'userId' => $uid,
'displayNameMap' => $this->getDisplayNameMap($account),
'emailMap' => $this->getEmailMap($account),
'languageMap' => $this->getLanguageMap($user),
'profileEnabled' => $this->isProfileEnabled($account),
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
'profileEnabled' => $this->profileManager->isProfileEnabled($user),
'organisationMap' => $this->getOrganisationMap($account),
'roleMap' => $this->getRoleMap($account),
'headlineMap' => $this->getHeadlineMap($account),
Expand All @@ -190,6 +191,7 @@ public function getForm(): TemplateResponse {
'profileConfig' => $this->profileManager->getProfileConfigWithMetadata($user, $user),
];

$this->initialStateService->provideInitialState('profileEnabledGlobally', $this->profileManager->isProfileEnabled());
$this->initialStateService->provideInitialState('personalInfoParameters', $personalInfoParameters);
$this->initialStateService->provideInitialState('accountParameters', $accountParameters);
$this->initialStateService->provideInitialState('profileParameters', $profileParameters);
Expand Down
101 changes: 101 additions & 0 deletions apps/settings/src/components/BasicSettings/ProfileSettings.vue
@@ -0,0 +1,101 @@
<!--
- @copyright 2022 Christopher Ng <chrng8@gmail.com>
-
- @author Christopher Ng <chrng8@gmail.com>
-
- @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 <http://www.gnu.org/licenses/>.
-
-->

<template>
<div id="profile-settings"
class="section">
<h2 class="inlineblock">
{{ t('settings', 'Profile') }}
</h2>

<p class="settings-hint">
{{ t('settings', 'Enable or disable profile by default for new users.') }}
</p>

<CheckboxRadioSwitch type="switch"
:checked.sync="initialProfileEnabledByDefault"
@update:checked="onProfileDefaultChange">
{{ t('settings', 'Enable') }}
</CheckboxRadioSwitch>
</div>
</template>

<script>
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import { saveProfileDefault } from '../../service/ProfileService'
import { validateBoolean } from '../../utils/validate'
import CheckboxRadioSwitch from '@nextcloud/vue/dist/Components/CheckboxRadioSwitch'
const profileEnabledByDefault = loadState('settings', 'profileEnabledByDefault', true)
export default {
name: 'ProfileSettings',
components: {
CheckboxRadioSwitch,
},
data() {
return {
initialProfileEnabledByDefault: profileEnabledByDefault,
}
},
methods: {
async onProfileDefaultChange(isEnabled) {
if (validateBoolean(isEnabled)) {
await this.updateProfileDefault(isEnabled)
}
},
async updateProfileDefault(isEnabled) {
try {
const responseData = await saveProfileDefault(isEnabled)
this.handleResponse({
isEnabled,
status: responseData.ocs?.meta?.status,
})
} catch (e) {
this.handleResponse({
errorMessage: t('settings', 'Unable to update profile default setting'),
error: e,
})
}
},
handleResponse({ isEnabled, status, errorMessage, error }) {
if (status === 'ok') {
this.initialProfileEnabledByDefault = isEnabled
} else {
showError(errorMessage)
this.logger.error(errorMessage, error)
}
},
},
}
</script>
<style lang="scss" scoped>
</style>
49 changes: 49 additions & 0 deletions apps/settings/src/main-admin-basic-settings.js
@@ -0,0 +1,49 @@
/**
* @copyright 2022 Christopher Ng <chrng8@gmail.com>
*
* @author Christopher Ng <chrng8@gmail.com>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

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')
}
31 changes: 19 additions & 12 deletions apps/settings/src/main-personal-info.js
Expand Up @@ -22,6 +22,7 @@

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'

Expand All @@ -39,6 +40,8 @@ import ProfileVisibilitySection from './components/PersonalInfo/ProfileVisibilit

__webpack_nonce__ = btoa(getRequestToken())

const profileEnabledGlobally = loadState('settings', 'profileEnabledGlobally', true)

Vue.mixin({
props: {
logger,
Expand All @@ -51,19 +54,23 @@ Vue.mixin({
const DisplayNameView = Vue.extend(DisplayNameSection)
const EmailView = Vue.extend(EmailSection)
const LanguageView = Vue.extend(LanguageSection)
const ProfileView = Vue.extend(ProfileSection)
const OrganisationView = Vue.extend(OrganisationSection)
const RoleView = Vue.extend(RoleSection)
const HeadlineView = Vue.extend(HeadlineSection)
const BiographyView = Vue.extend(BiographySection)
const ProfileVisibilityView = Vue.extend(ProfileVisibilitySection)

new DisplayNameView().$mount('#vue-displayname-section')
new EmailView().$mount('#vue-email-section')
new LanguageView().$mount('#vue-language-section')
new ProfileView().$mount('#vue-profile-section')
new OrganisationView().$mount('#vue-organisation-section')
new RoleView().$mount('#vue-role-section')
new HeadlineView().$mount('#vue-headline-section')
new BiographyView().$mount('#vue-biography-section')
new ProfileVisibilityView().$mount('#vue-profile-visibility-section')

if (profileEnabledGlobally) {
const ProfileView = Vue.extend(ProfileSection)
const OrganisationView = Vue.extend(OrganisationSection)
const RoleView = Vue.extend(RoleSection)
const HeadlineView = Vue.extend(HeadlineSection)
const BiographyView = Vue.extend(BiographySection)
const ProfileVisibilityView = Vue.extend(ProfileVisibilitySection)

new ProfileView().$mount('#vue-profile-section')
new OrganisationView().$mount('#vue-organisation-section')
new RoleView().$mount('#vue-role-section')
new HeadlineView().$mount('#vue-headline-section')
new BiographyView().$mount('#vue-biography-section')
new ProfileVisibilityView().$mount('#vue-profile-visibility-section')
}
24 changes: 24 additions & 0 deletions apps/settings/src/service/ProfileService.js
Expand Up @@ -45,3 +45,27 @@ export const saveProfileParameterVisibility = async(paramId, visibility) => {

return res.data
}

/**
* Save profile default
*
* @param {boolean} isEnabled the default
* @returns {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
}
7 changes: 7 additions & 0 deletions apps/settings/templates/settings/admin/server.php
Expand Up @@ -24,6 +24,9 @@
/** @var \OCP\IL10N $l */
/** @var array $_ */

script('settings', [
'vue-settings-admin-basic-settings',
]);
?>

<div class="section" id="backgroundjobs">
Expand Down Expand Up @@ -112,3 +115,7 @@
</fieldset>
</form>
</div>

<?php if ($_['profileEnabledGlobally']) : ?>
<div class="vue-admin-profile-settings"></div>
<?php endif; ?>
42 changes: 24 additions & 18 deletions apps/settings/templates/settings/personal/personal.info.php
Expand Up @@ -239,24 +239,28 @@
<input type="hidden" id="twitterscope" value="<?php p($_['twitterScope']) ?>">
</form>
</div>
<div class="personal-settings-setting-box">
<div id="vue-organisation-section"></div>
</div>
<div class="personal-settings-setting-box">
<div id="vue-role-section"></div>
</div>
<div class="personal-settings-setting-box">
<div id="vue-headline-section"></div>
</div>
<div class="personal-settings-setting-box">
<div id="vue-biography-section"></div>
</div>
<?php if ($_['profileEnabledGlobally']) : ?>
<div class="personal-settings-setting-box">
<div id="vue-organisation-section"></div>
</div>
<div class="personal-settings-setting-box">
<div id="vue-role-section"></div>
</div>
<div class="personal-settings-setting-box">
<div id="vue-headline-section"></div>
</div>
<div class="personal-settings-setting-box">
<div id="vue-biography-section"></div>
</div>
<?php endif; ?>
</div>

<div class="profile-settings-container">
<div class="personal-settings-setting-box">
<div id="vue-profile-section"></div>
</div>
<?php if ($_['profileEnabledGlobally']) : ?>
<div class="personal-settings-setting-box">
<div id="vue-profile-section"></div>
</div>
<?php endif; ?>
<div class="personal-settings-setting-box personal-settings-language-box">
<div id="vue-language-section"></div>
</div>
Expand Down Expand Up @@ -304,6 +308,8 @@

</div>

<div class="personal-settings-section">
<div id="vue-profile-visibility-section"></div>
</div>
<?php if ($_['profileEnabledGlobally']) : ?>
<div class="personal-settings-section">
<div id="vue-profile-visibility-section"></div>
</div>
<?php endif; ?>

0 comments on commit fea072c

Please sign in to comment.