Signed-off-by: Christopher Ng <chrng8@gmail.com>tags/v24.0.0beta1
@@ -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); |
@@ -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') | |||
} |
@@ -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; ?> |
@@ -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', |
@@ -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'); |
@@ -2097,4 +2097,11 @@ $CONFIG = [ | |||
* Limit diagnostics event logging to events longer than the configured threshold in ms | |||
*/ | |||
'diagnostics.logging.threshold' => 0, | |||
/** | |||
* Enable profile globally | |||
* | |||
* Defaults to ``true`` | |||
*/ | |||
'profile.enabled' => true, | |||
]; |
@@ -26,13 +26,10 @@ declare(strict_types=1); | |||
namespace OC\Core\Controller; | |||
use OC\KnownUser\KnownUserService; | |||
use OC\Profile\ProfileManager; | |||
use OCP\Accounts\IAccountManager; | |||
use OCP\AppFramework\Controller; | |||
use OCP\AppFramework\Http\TemplateResponse; | |||
use OCP\AppFramework\Services\IInitialState; | |||
use OCP\IGroupManager; | |||
use OCP\IRequest; | |||
use OCP\IUser; | |||
use OCP\IUserManager; | |||
@@ -41,26 +38,16 @@ use OCP\Share\IManager as IShareManager; | |||
use OCP\UserStatus\IManager as IUserStatusManager; | |||
class ProfilePageController extends Controller { | |||
use \OC\Profile\TProfileHelper; | |||
/** @var IInitialState */ | |||
private $initialStateService; | |||
/** @var IAccountManager */ | |||
private $accountManager; | |||
/** @var ProfileManager */ | |||
private $profileManager; | |||
/** @var IShareManager */ | |||
private $shareManager; | |||
/** @var IGroupManager */ | |||
private $groupManager; | |||
/** @var KnownUserService */ | |||
private $knownUserService; | |||
/** @var IUserManager */ | |||
private $userManager; | |||
@@ -74,22 +61,16 @@ class ProfilePageController extends Controller { | |||
$appName, | |||
IRequest $request, | |||
IInitialState $initialStateService, | |||
IAccountManager $accountManager, | |||
ProfileManager $profileManager, | |||
IShareManager $shareManager, | |||
IGroupManager $groupManager, | |||
KnownUserService $knownUserService, | |||
IUserManager $userManager, | |||
IUserSession $userSession, | |||
IUserStatusManager $userStatusManager | |||
) { | |||
parent::__construct($appName, $request); | |||
$this->initialStateService = $initialStateService; | |||
$this->accountManager = $accountManager; | |||
$this->profileManager = $profileManager; | |||
$this->shareManager = $shareManager; | |||
$this->groupManager = $groupManager; | |||
$this->knownUserService = $knownUserService; | |||
$this->userManager = $userManager; | |||
$this->userSession = $userSession; | |||
$this->userStatusManager = $userStatusManager; | |||
@@ -114,9 +95,8 @@ class ProfilePageController extends Controller { | |||
return $profileNotFoundTemplate; | |||
} | |||
$visitingUser = $this->userSession->getUser(); | |||
$targetAccount = $this->accountManager->getAccount($targetUser); | |||
if (!$this->isProfileEnabled($targetAccount)) { | |||
if (!$this->profileManager->isProfileEnabled($targetUser)) { | |||
return $profileNotFoundTemplate; | |||
} | |||
@@ -32,7 +32,7 @@ | |||
namespace OC\Contacts\ContactsMenu; | |||
use OC\KnownUser\KnownUserService; | |||
use OCP\Accounts\IAccountManager; | |||
use OC\Profile\ProfileManager; | |||
use OCP\Contacts\ContactsMenu\IContactsStore; | |||
use OCP\Contacts\ContactsMenu\IEntry; | |||
use OCP\Contacts\IManager; | |||
@@ -44,10 +44,6 @@ use OCP\IUserManager; | |||
use OCP\L10N\IFactory as IL10NFactory; | |||
class ContactsStore implements IContactsStore { | |||
use \OC\Profile\TProfileHelper; | |||
/** @var IAccountManager */ | |||
private $accountManager; | |||
/** @var IManager */ | |||
private $contactsManager; | |||
@@ -55,6 +51,9 @@ class ContactsStore implements IContactsStore { | |||
/** @var IConfig */ | |||
private $config; | |||
/** @var ProfileManager */ | |||
private $profileManager; | |||
/** @var IUserManager */ | |||
private $userManager; | |||
@@ -71,18 +70,18 @@ class ContactsStore implements IContactsStore { | |||
private $l10nFactory; | |||
public function __construct( | |||
IAccountManager $accountManager, | |||
IManager $contactsManager, | |||
IConfig $config, | |||
ProfileManager $profileManager, | |||
IUserManager $userManager, | |||
IURLGenerator $urlGenerator, | |||
IGroupManager $groupManager, | |||
KnownUserService $knownUserService, | |||
IL10NFactory $l10nFactory | |||
) { | |||
$this->accountManager = $accountManager; | |||
$this->contactsManager = $contactsManager; | |||
$this->config = $config; | |||
$this->profileManager = $profileManager; | |||
$this->userManager = $userManager; | |||
$this->urlGenerator = $urlGenerator; | |||
$this->groupManager = $groupManager; | |||
@@ -335,10 +334,9 @@ class ContactsStore implements IContactsStore { | |||
// Provide profile parameters for core/src/OC/contactsmenu/contact.handlebars template | |||
if (isset($contact['UID']) && isset($contact['FN'])) { | |||
$targetUserId = $contact['UID']; | |||
$user = $this->userManager->get($targetUserId); | |||
if (!empty($user)) { | |||
$account = $this->accountManager->getAccount($user); | |||
if ($this->isProfileEnabled($account)) { | |||
$targetUser = $this->userManager->get($targetUserId); | |||
if (!empty($targetUser)) { | |||
if ($this->profileManager->isProfileEnabled($targetUser)) { | |||
$entry->setProfileTitle($this->l10nFactory->get('lib')->t('View profile')); | |||
$entry->setProfileUrl($this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $targetUserId])); | |||
} |
@@ -24,7 +24,7 @@ | |||
namespace OC\Contacts\ContactsMenu\Providers; | |||
use OCP\Accounts\IAccountManager; | |||
use OC\Profile\ProfileManager; | |||
use OCP\Contacts\ContactsMenu\IActionFactory; | |||
use OCP\Contacts\ContactsMenu\IEntry; | |||
use OCP\Contacts\ContactsMenu\IProvider; | |||
@@ -33,14 +33,13 @@ use OCP\IUserManager; | |||
use OCP\L10N\IFactory as IL10NFactory; | |||
class ProfileProvider implements IProvider { | |||
use \OC\Profile\TProfileHelper; | |||
/** @var IAccountManager */ | |||
private $accountManager; | |||
/** @var IActionFactory */ | |||
private $actionFactory; | |||
/** @var ProfileManager */ | |||
private $profileManager; | |||
/** @var IL10NFactory */ | |||
private $l10nFactory; | |||
@@ -51,21 +50,21 @@ class ProfileProvider implements IProvider { | |||
private $userManager; | |||
/** | |||
* @param IAccountManager $accountManager | |||
* @param IActionFactory $actionFactory | |||
* @param ProfileManager $profileManager | |||
* @param IL10NFactory $l10nFactory | |||
* @param IURLGenerator $urlGenerator | |||
* @param IUserManager $userManager | |||
*/ | |||
public function __construct( | |||
IAccountManager $accountManager, | |||
IActionFactory $actionFactory, | |||
ProfileManager $profileManager, | |||
IL10NFactory $l10nFactory, | |||
IURLGenerator $urlGenerator, | |||
IUserManager $userManager | |||
) { | |||
$this->accountManager = $accountManager; | |||
$this->actionFactory = $actionFactory; | |||
$this->profileManager = $profileManager; | |||
$this->l10nFactory = $l10nFactory; | |||
$this->urlGenerator = $urlGenerator; | |||
$this->userManager = $userManager; | |||
@@ -78,8 +77,7 @@ class ProfileProvider implements IProvider { | |||
$targetUserId = $entry->getProperty('UID'); | |||
$targetUser = $this->userManager->get($targetUserId); | |||
if (!empty($targetUser)) { | |||
$account = $this->accountManager->getAccount($targetUser); | |||
if ($this->isProfileEnabled($account)) { | |||
if ($this->profileManager->isProfileEnabled($targetUser)) { | |||
$iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/profile.svg')); | |||
$profileActionText = $this->l10nFactory->get('lib')->t('View profile'); | |||
$profileUrl = $this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $targetUserId]); |
@@ -40,6 +40,7 @@ use OCP\Accounts\IAccountManager; | |||
use OCP\Accounts\PropertyDoesNotExistException; | |||
use OCP\App\IAppManager; | |||
use OCP\AppFramework\Db\DoesNotExistException; | |||
use OCP\IConfig; | |||
use OCP\IUser; | |||
use OCP\L10N\IFactory; | |||
use OCP\Profile\ILinkAction; | |||
@@ -54,6 +55,9 @@ class ProfileManager { | |||
/** @var IAppManager */ | |||
private $appManager; | |||
/** @var IConfig */ | |||
private $config; | |||
/** @var ProfileConfigMapper */ | |||
private $configMapper; | |||
@@ -106,6 +110,7 @@ class ProfileManager { | |||
public function __construct( | |||
IAccountManager $accountManager, | |||
IAppManager $appManager, | |||
IConfig $config, | |||
ProfileConfigMapper $configMapper, | |||
ContainerInterface $container, | |||
KnownUserService $knownUserService, | |||
@@ -115,6 +120,7 @@ class ProfileManager { | |||
) { | |||
$this->accountManager = $accountManager; | |||
$this->appManager = $appManager; | |||
$this->config = $config; | |||
$this->configMapper = $configMapper; | |||
$this->container = $container; | |||
$this->knownUserService = $knownUserService; | |||
@@ -123,6 +129,24 @@ class ProfileManager { | |||
$this->coordinator = $coordinator; | |||
} | |||
/** | |||
* If no user is passed as an argument return whether profile is enabled globally in `config.php` | |||
*/ | |||
public function isProfileEnabled(?IUser $user = null): ?bool { | |||
$profileEnabledGlobally = $this->config->getSystemValueBool('profile.enabled', true); | |||
if (empty($user) || !$profileEnabledGlobally) { | |||
return $profileEnabledGlobally; | |||
} | |||
$account = $this->accountManager->getAccount($user); | |||
return filter_var( | |||
$account->getProperty(IAccountManager::PROPERTY_PROFILE_ENABLED)->getValue(), | |||
FILTER_VALIDATE_BOOLEAN, | |||
FILTER_NULL_ON_FAILURE, | |||
); | |||
} | |||
/** | |||
* Register an action for the user | |||
*/ |
@@ -27,7 +27,7 @@ namespace Tests\Contacts\ContactsMenu; | |||
use OC\Contacts\ContactsMenu\ContactsStore; | |||
use OC\KnownUser\KnownUserService; | |||
use OCP\Accounts\IAccountManager; | |||
use OC\Profile\ProfileManager; | |||
use OCP\Contacts\IManager; | |||
use OCP\IConfig; | |||
use OCP\IGroupManager; | |||
@@ -39,12 +39,12 @@ use PHPUnit\Framework\MockObject\MockObject; | |||
use Test\TestCase; | |||
class ContactsStoreTest extends TestCase { | |||
/** @var IAccountManager */ | |||
private $accountManager; | |||
/** @var ContactsStore */ | |||
private $contactsStore; | |||
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ | |||
private $contactsManager; | |||
/** @var ProfileManager */ | |||
private $profileManager; | |||
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ | |||
private $userManager; | |||
/** @var IURLGenerator */ | |||
@@ -61,18 +61,18 @@ class ContactsStoreTest extends TestCase { | |||
protected function setUp(): void { | |||
parent::setUp(); | |||
$this->accountManager = $this->createMock(IAccountManager::class); | |||
$this->contactsManager = $this->createMock(IManager::class); | |||
$this->userManager = $this->createMock(IUserManager::class); | |||
$this->profileManager = $this->createMock(ProfileManager::class); | |||
$this->urlGenerator = $this->createMock(IURLGenerator::class); | |||
$this->groupManager = $this->createMock(IGroupManager::class); | |||
$this->config = $this->createMock(IConfig::class); | |||
$this->knownUserService = $this->createMock(KnownUserService::class); | |||
$this->l10nFactory = $this->createMock(IL10NFactory::class); | |||
$this->contactsStore = new ContactsStore( | |||
$this->accountManager, | |||
$this->contactsManager, | |||
$this->config, | |||
$this->profileManager, | |||
$this->userManager, | |||
$this->urlGenerator, | |||
$this->groupManager, |