diff options
author | Christopher Ng <chrng8@gmail.com> | 2022-03-11 02:11:28 +0000 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2022-03-18 02:55:12 +0000 |
commit | 1fc0b4320c8921ad59bf4d41a88bf9936e1f653d (patch) | |
tree | 8d630f864f4a2760f72307e68553cc2ee0c516d4 /apps | |
parent | d364edcf6a18fa237dc53f6b95614851ed5fdc9a (diff) | |
download | nextcloud-server-1fc0b4320c8921ad59bf4d41a88bf9936e1f653d.tar.gz nextcloud-server-1fc0b4320c8921ad59bf4d41a88bf9936e1f653d.zip |
Add global profile toggle config
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps')
5 files changed, 60 insertions, 43 deletions
diff --git a/apps/settings/lib/Settings/Personal/PersonalInfo.php b/apps/settings/lib/Settings/Personal/PersonalInfo.php index def7e19f006..4bac8e67fb7 100644 --- a/apps/settings/lib/Settings/Personal/PersonalInfo.php +++ b/apps/settings/lib/Settings/Personal/PersonalInfo.php @@ -56,7 +56,6 @@ use OCP\Notification\IManager; use OCP\Settings\ISettings; class PersonalInfo implements ISettings { - use \OC\Profile\TProfileHelper; /** @var IConfig */ private $config; @@ -166,7 +165,8 @@ class PersonalInfo implements ISettings { '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 = [ @@ -174,7 +174,8 @@ class PersonalInfo implements ISettings { '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), @@ -190,6 +191,7 @@ class PersonalInfo implements ISettings { '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); diff --git a/apps/settings/src/main-personal-info.js b/apps/settings/src/main-personal-info.js index 398518984a0..7694fa4ff6d 100644 --- a/apps/settings/src/main-personal-info.js +++ b/apps/settings/src/main-personal-info.js @@ -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' @@ -39,6 +40,8 @@ import ProfileVisibilitySection from './components/PersonalInfo/ProfileVisibilit __webpack_nonce__ = btoa(getRequestToken()) +const profileEnabledGlobally = loadState('settings', 'profileEnabledGlobally', true) + Vue.mixin({ props: { logger, @@ -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') +} diff --git a/apps/settings/templates/settings/personal/personal.info.php b/apps/settings/templates/settings/personal/personal.info.php index 19265ebfc85..98009cc52be 100644 --- a/apps/settings/templates/settings/personal/personal.info.php +++ b/apps/settings/templates/settings/personal/personal.info.php @@ -239,24 +239,28 @@ script('settings', [ <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> @@ -304,6 +308,8 @@ script('settings', [ </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; ?> diff --git a/apps/settings/tests/Settings/Admin/ServerTest.php b/apps/settings/tests/Settings/Admin/ServerTest.php index b30ed863f89..045dc60bf98 100644 --- a/apps/settings/tests/Settings/Admin/ServerTest.php +++ b/apps/settings/tests/Settings/Admin/ServerTest.php @@ -92,6 +92,10 @@ class ServerTest extends TestCase { ->method('getAppValue') ->with('core', 'cronErrors') ->willReturn(''); + $this->profileManager + ->expects($this->exactly(2)) + ->method('isProfileEnabled') + ->willReturn(true); $expected = new TemplateResponse( 'settings', 'settings/admin/server', diff --git a/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php b/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php index 6fe2f728de0..daf7265d988 100644 --- a/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php +++ b/apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php @@ -27,9 +27,9 @@ declare(strict_types=1); namespace OCA\UserStatus\Listener; +use OC\Profile\ProfileManager; use OCA\UserStatus\AppInfo\Application; use OCA\UserStatus\Service\JSDataService; -use OCP\Accounts\IAccountManager; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\AppFramework\Http\TemplateResponse; use OCP\EventDispatcher\Event; @@ -38,10 +38,9 @@ use OCP\IInitialStateService; use OCP\IUserSession; class BeforeTemplateRenderedListener implements IEventListener { - use \OC\Profile\TProfileHelper; - /** @var IAccountManager */ - private $accountManager; + /** @var ProfileManager */ + private $profileManager; /** @var IUserSession */ private $userSession; @@ -55,18 +54,18 @@ class BeforeTemplateRenderedListener implements IEventListener { /** * BeforeTemplateRenderedListener constructor. * - * @param IAccountManager $accountManager + * @param ProfileManager $profileManager * @param IUserSession $userSession * @param IInitialStateService $initialState * @param JSDataService $jsDataService */ public function __construct( - IAccountManager $accountManager, + ProfileManager $profileManager, IUserSession $userSession, IInitialStateService $initialState, JSDataService $jsDataService ) { - $this->accountManager = $accountManager; + $this->profileManager = $profileManager; $this->userSession = $userSession; $this->initialState = $initialState; $this->jsDataService = $jsDataService; @@ -80,7 +79,6 @@ class BeforeTemplateRenderedListener implements IEventListener { if ($user === null) { return; } - $account = $this->accountManager->getAccount($user); if (!($event instanceof BeforeTemplateRenderedEvent)) { // Unrelated @@ -95,8 +93,8 @@ class BeforeTemplateRenderedListener implements IEventListener { return $this->jsDataService; }); - $this->initialState->provideLazyInitialState(Application::APP_ID, 'profileEnabled', function () use ($account) { - return ['profileEnabled' => $this->isProfileEnabled($account)]; + $this->initialState->provideLazyInitialState(Application::APP_ID, 'profileEnabled', function () use ($user) { + return ['profileEnabled' => $this->profileManager->isProfileEnabled($user)]; }); \OCP\Util::addScript('user_status', 'menu'); |