diff --git a/core/Controller/ProfileController.php b/core/Controller/ProfileController.php index 7df62182a6e79..9cc5f5cda6a45 100644 --- a/core/Controller/ProfileController.php +++ b/core/Controller/ProfileController.php @@ -27,7 +27,7 @@ namespace OC\Core\Controller; - +use EmailAction; use OCP\Accounts\IAccountManager; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; @@ -35,41 +35,68 @@ use OCP\IRequest; use OCP\IUserSession; use OCP\UserStatus\IManager; -use OCP\UserStatus\IUserStatus; use OCP\Accounts\IAccount; use OCP\Accounts\IAccountProperty; use OCP\App\IAppManager; +use OCP\IUserManager; +use OCP\Profile\IActionManager; class ProfileController extends \OCP\AppFramework\Controller { /** @var IL10N */ private $l10n; + /** @var IUserSession */ private $userSession; + + /** @var IUserManager */ + private $userManager; + /** @var IAccountManager */ private $accountManager; + /** @var IInitialState */ private $initialStateService; + /** @var IAppManager */ private $appManager; + /** @var IManager */ + private $userStatusManager; + + /** @var IActionManager */ + // private $actionManager; + public function __construct( $appName, IRequest $request, IL10N $l10n, IUserSession $userSession, + IUserManager $userManager, IAccountManager $accountManager, IInitialState $initialStateService, - IAppManager $appManager + IAppManager $appManager, + IManager $userStatusManager, + // IActionManager $actionManager ) { parent::__construct($appName, $request); $this->l10n = $l10n; $this->userSession = $userSession; + $this->userManager = $userManager; $this->accountManager = $accountManager; $this->initialStateService = $initialStateService; $this->appManager = $appManager; + $this->userStatusManager = $userStatusManager; + // $this->actionManager = $actionManager; } + public const PROPERTY_ACTIONS = [ + IAccountManager::PROPERTY_EMAIL, + IAccountManager::PROPERTY_PHONE, + IAccountManager::PROPERTY_WEBSITE, + IAccountManager::PROPERTY_TWITTER, + ]; + /** * @NoCSRFRequired * @UseSession @@ -77,7 +104,7 @@ public function __construct( */ public function index(string $userId = null): TemplateResponse { $isLoggedIn = $this->userSession->isLoggedIn(); - $account = $this->accountManager->getAccount(\OC::$server->getUserManager()->get($userId)); + $account = $this->accountManager->getAccount($this->userManager->get($userId)); $profileEnabled = filter_var( $account->getProperty(IAccountManager::PROPERTY_PROFILE_ENABLED)->getValue(), @@ -95,8 +122,7 @@ public function index(string $userId = null): TemplateResponse { ); } - $status = \OC::$server->get(IManager::class); - $status = $status->getUserStatuses([$userId]); + $status = $this->userStatusManager->getUserStatuses([$userId]); $status = array_pop($status); if ($status) { @@ -158,4 +184,35 @@ function (IAccountProperty $property) { return $profileParameters; } + + protected function initActions(IAccount $account) { + foreach(self::PROPERTY_ACTIONS as $property) { + $scope = $account->getProperty($property)->getScope(); + $value = $account->getProperty($property)->getValue(); + + // TODO: handle talk verification + if ($scope === IAccountManager::SCOPE_PRIVATE) { + return; + } + + // User is not logged in, we don't display the action + if ($scope === IAccountManager::SCOPE_LOCAL && !$this->userSession->isLoggedIn()) { + return; + } + + // TODO: handle federation verification + if ($scope === IAccountManager::SCOPE_FEDERATED && false) { + return; + } + + switch ($property) { + case IAccountManager::PROPERTY_EMAIL: + // $this->actionManager->registerAction(new EmailAction($value)); + break; + + default: + break; + } + } + } } diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index ea1473f27dc34..2c62680d5be52 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -456,6 +456,8 @@ 'OCP\\Preview\\IProvider' => $baseDir . '/lib/public/Preview/IProvider.php', 'OCP\\Preview\\IProviderV2' => $baseDir . '/lib/public/Preview/IProviderV2.php', 'OCP\\Preview\\IVersionedPreviewFile' => $baseDir . '/lib/public/Preview/IVersionedPreviewFile.php', + 'OCP\\Profile\\IActionManager' => $baseDir . '/lib/public/Profile/IActionManager.php', + 'OCP\\Profile\\IProfileAction' => $baseDir . '/lib/public/Profile/IProfileAction.php', 'OCP\\Remote\\Api\\IApiCollection' => $baseDir . '/lib/public/Remote/Api/IApiCollection.php', 'OCP\\Remote\\Api\\IApiFactory' => $baseDir . '/lib/public/Remote/Api/IApiFactory.php', 'OCP\\Remote\\Api\\ICapabilitiesApi' => $baseDir . '/lib/public/Remote/Api/ICapabilitiesApi.php', @@ -915,6 +917,7 @@ 'OC\\Core\\Controller\\OCJSController' => $baseDir . '/core/Controller/OCJSController.php', 'OC\\Core\\Controller\\OCSController' => $baseDir . '/core/Controller/OCSController.php', 'OC\\Core\\Controller\\PreviewController' => $baseDir . '/core/Controller/PreviewController.php', + 'OC\\Core\\Controller\\ProfileController' => $baseDir . '/core/Controller/ProfileController.php', 'OC\\Core\\Controller\\RecommendedAppsController' => $baseDir . '/core/Controller/RecommendedAppsController.php', 'OC\\Core\\Controller\\SearchController' => $baseDir . '/core/Controller/SearchController.php', 'OC\\Core\\Controller\\SetupController' => $baseDir . '/core/Controller/SetupController.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 93208f6ff1502..0b9ff1ae0b7a0 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -485,6 +485,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Preview\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Preview/IProvider.php', 'OCP\\Preview\\IProviderV2' => __DIR__ . '/../../..' . '/lib/public/Preview/IProviderV2.php', 'OCP\\Preview\\IVersionedPreviewFile' => __DIR__ . '/../../..' . '/lib/public/Preview/IVersionedPreviewFile.php', + 'OCP\\Profile\\IActionManager' => __DIR__ . '/../../..' . '/lib/public/Profile/IActionManager.php', + 'OCP\\Profile\\IProfileAction' => __DIR__ . '/../../..' . '/lib/public/Profile/IProfileAction.php', 'OCP\\Remote\\Api\\IApiCollection' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/IApiCollection.php', 'OCP\\Remote\\Api\\IApiFactory' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/IApiFactory.php', 'OCP\\Remote\\Api\\ICapabilitiesApi' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/ICapabilitiesApi.php', @@ -944,6 +946,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Controller\\OCJSController' => __DIR__ . '/../../..' . '/core/Controller/OCJSController.php', 'OC\\Core\\Controller\\OCSController' => __DIR__ . '/../../..' . '/core/Controller/OCSController.php', 'OC\\Core\\Controller\\PreviewController' => __DIR__ . '/../../..' . '/core/Controller/PreviewController.php', + 'OC\\Core\\Controller\\ProfileController' => __DIR__ . '/../../..' . '/core/Controller/ProfileController.php', 'OC\\Core\\Controller\\RecommendedAppsController' => __DIR__ . '/../../..' . '/core/Controller/RecommendedAppsController.php', 'OC\\Core\\Controller\\SearchController' => __DIR__ . '/../../..' . '/core/Controller/SearchController.php', 'OC\\Core\\Controller\\SetupController' => __DIR__ . '/../../..' . '/core/Controller/SetupController.php', diff --git a/lib/private/Profile/ActionManager.php b/lib/private/Profile/ActionManager.php new file mode 100644 index 0000000000000..0c2e6b92b8245 --- /dev/null +++ b/lib/private/Profile/ActionManager.php @@ -0,0 +1,50 @@ + + * + * @author John Molakvoæ + * + * @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 . + * + */ + +use OCP\Profile\IActionManager; +use OCP\Profile\IProfileAction; + +/** + * @since 23 + */ +class ActionManager implements IActionManager { + + public function __construct() {} + + /** @var array */ + protected $actions = []; + + /** + * @inheritDoc + */ + public function registerAction(IProfileAction $action) { + $this->actions[] = $action; + } + + /** + * @inheritDoc + */ + public function getActions(): array { + return $this->actions; + } +} \ No newline at end of file diff --git a/lib/private/Profile/EmailAction.php b/lib/private/Profile/EmailAction.php new file mode 100644 index 0000000000000..02313f78ede7f --- /dev/null +++ b/lib/private/Profile/EmailAction.php @@ -0,0 +1,70 @@ + + * + * @author John Molakvoæ + * + * @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 . + * + */ + +class EmailAction implements IProfileAction { + + /** @var string */ + private $value; + + /** @var IL10N */ + private $l10n; + + /** @var IUrlGenerator */ + private $urlGenerator; + + /** + * Personal Section constructor. + * + * @param string $appName + * @param IURLGenerator $urlGenerator + * @param IL10N $l10n + */ + public function __construct(string $value, + IL10N $l10n, + IURLGenerator $urlGenerator) { + $this->value = $value; + $this->l10n = $l10n; + $this->urlGenerator = $urlGenerator; + } + + public function getTitle(): string { + return $this->l10n->t('Mail %s', [$this->value]); + } + + public function getPriority(): int { + return 20; + } + + public function getIcon(): string { + return 'icon-mail'; + } + + public function getTarget(): string { + return 'mailto:' . $this->value; + } +} diff --git a/lib/public/Profile/IActionManager.php b/lib/public/Profile/IActionManager.php new file mode 100644 index 0000000000000..b292de5998b86 --- /dev/null +++ b/lib/public/Profile/IActionManager.php @@ -0,0 +1,43 @@ + + * + * @author John Molakvoæ + * + * @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 . + * + */ +namespace OCP\Profile; + +/** + * @since 23 + */ +interface IActionManager { + + /** + * Register a new action for the user profile page + * + * @since 23 + */ + public function registerAction(IProfileAction $action); + + /** + * Returns the list of all registered profile actions + * + * @since 23 + */ + public function getActions(): array; +} \ No newline at end of file diff --git a/lib/public/Profile/IProfileAction.php b/lib/public/Profile/IProfileAction.php new file mode 100644 index 0000000000000..364f3de0c5a37 --- /dev/null +++ b/lib/public/Profile/IProfileAction.php @@ -0,0 +1,63 @@ + + * + * @author John Molakvoæ + * + * @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 . + * + */ +namespace OCP\Profile; + +/** + * @since 23 + */ +interface IProfileAction { + /** + * returns the translated title as it should be displayed, + * e.g. 'Email john@domain.com'. Use the L10N service to translate it. + * + * @return string + * @since 23 + */ + public function getTitle(): string; + + /** + * @return int whether the action should be rather on the top or bottom of + * the list. The actions are arranged in ascending order of + * the priority values. It is required to return a value between 0 and 99. + * + * E.g.: 70 + * @since 23 + */ + public function getPriority(): int; + + /** + * returns the 16*16 icon class describing the action. + * + * @returns string + * @since 23 + */ + public function getIcon(): string; + + /** + * returns the target of the action, e.g. 'mailto:john@domain.com' + * + * @returns string + * @since 23 + */ + public function getTarget(): string; +}