aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Contacts/ContactsMenu
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2021-10-14 08:19:40 +0000
committerChristopher Ng <chrng8@gmail.com>2021-10-19 04:59:35 +0000
commit309354852f12ae88d5eef05d311d6ebcba8ee762 (patch)
tree640c4e2394ba2a868d8d1cb6b5271fd1271bbdab /lib/private/Contacts/ContactsMenu
parent7215148a242815a5064ce5d00a387c634dc936f3 (diff)
downloadnextcloud-server-309354852f12ae88d5eef05d311d6ebcba8ee762.tar.gz
nextcloud-server-309354852f12ae88d5eef05d311d6ebcba8ee762.zip
Profile backend
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'lib/private/Contacts/ContactsMenu')
-rw-r--r--lib/private/Contacts/ContactsMenu/ActionProviderStore.php6
-rw-r--r--lib/private/Contacts/ContactsMenu/ContactsStore.php54
-rw-r--r--lib/private/Contacts/ContactsMenu/Entry.php37
-rw-r--r--lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php93
4 files changed, 181 insertions, 9 deletions
diff --git a/lib/private/Contacts/ContactsMenu/ActionProviderStore.php b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php
index a984f9d6dfb..1db99497a21 100644
--- a/lib/private/Contacts/ContactsMenu/ActionProviderStore.php
+++ b/lib/private/Contacts/ContactsMenu/ActionProviderStore.php
@@ -24,11 +24,13 @@ declare(strict_types=1);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
namespace OC\Contacts\ContactsMenu;
use Exception;
use OC\App\AppManager;
use OC\Contacts\ContactsMenu\Providers\EMailProvider;
+use OC\Contacts\ContactsMenu\Providers\ProfileProvider;
use OCP\AppFramework\QueryException;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IServerContainer;
@@ -67,7 +69,8 @@ class ActionProviderStore {
try {
$providers[] = $this->serverContainer->query($class);
} catch (QueryException $ex) {
- $this->logger->error('Could not load contacts menu action provider ' . $class,
+ $this->logger->error(
+ 'Could not load contacts menu action provider ' . $class,
[
'app' => 'core',
'exception' => $ex,
@@ -85,6 +88,7 @@ class ActionProviderStore {
*/
private function getServerProviderClasses(): array {
return [
+ ProfileProvider::class,
EMailProvider::class,
];
}
diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php
index 31e13bbe8f2..a4a53bf8774 100644
--- a/lib/private/Contacts/ContactsMenu/ContactsStore.php
+++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php
@@ -1,4 +1,5 @@
<?php
+
/**
* @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
* @copyright 2017 Lukas Reschke <lukas@statuscode.ch>
@@ -27,18 +28,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
namespace OC\Contacts\ContactsMenu;
use OC\KnownUser\KnownUserService;
+use OCP\Accounts\IAccountManager;
use OCP\Contacts\ContactsMenu\IContactsStore;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\IManager;
use OCP\IConfig;
use OCP\IGroupManager;
+use OCP\IURLGenerator;
use OCP\IUser;
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;
@@ -49,22 +58,36 @@ class ContactsStore implements IContactsStore {
/** @var IUserManager */
private $userManager;
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
/** @var IGroupManager */
private $groupManager;
/** @var KnownUserService */
private $knownUserService;
- public function __construct(IManager $contactsManager,
- IConfig $config,
- IUserManager $userManager,
- IGroupManager $groupManager,
- KnownUserService $knownUserService) {
+ /** @var IL10NFactory */
+ private $l10nFactory;
+
+ public function __construct(
+ IAccountManager $accountManager,
+ IManager $contactsManager,
+ IConfig $config,
+ IUserManager $userManager,
+ IURLGenerator $urlGenerator,
+ IGroupManager $groupManager,
+ KnownUserService $knownUserService,
+ IL10NFactory $l10nFactory
+ ) {
+ $this->accountManager = $accountManager;
$this->contactsManager = $contactsManager;
$this->config = $config;
$this->userManager = $userManager;
+ $this->urlGenerator = $urlGenerator;
$this->groupManager = $groupManager;
$this->knownUserService = $knownUserService;
+ $this->l10nFactory = $l10nFactory;
}
/**
@@ -116,9 +139,11 @@ class ContactsStore implements IContactsStore {
* @param string $filter
* @return Entry[] the filtered contacts
*/
- private function filterContacts(IUser $self,
- array $entries,
- $filter) {
+ private function filterContacts(
+ IUser $self,
+ array $entries,
+ $filter
+ ) {
$disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes';
$restrictEnumerationGroup = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
$restrictEnumerationPhone = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
@@ -302,6 +327,19 @@ 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)) {
+ $entry->setProfileTitle($this->l10nFactory->get('core')->t('View profile'));
+ $entry->setProfileUrl($this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $targetUserId]));
+ }
+ }
+ }
+
// Attach all other properties to the entry too because some
// providers might make use of it.
$entry->setProperties($contact);
diff --git a/lib/private/Contacts/ContactsMenu/Entry.php b/lib/private/Contacts/ContactsMenu/Entry.php
index aea71df2968..915a0434cc8 100644
--- a/lib/private/Contacts/ContactsMenu/Entry.php
+++ b/lib/private/Contacts/ContactsMenu/Entry.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
namespace OC\Contacts\ContactsMenu;
use OCP\Contacts\ContactsMenu\IAction;
@@ -43,6 +44,12 @@ class Entry implements IEntry {
/** @var string|null */
private $avatar;
+ /** @var string|null */
+ private $profileTitle;
+
+ /** @var string|null */
+ private $profileUrl;
+
/** @var IAction[] */
private $actions = [];
@@ -99,6 +106,34 @@ class Entry implements IEntry {
}
/**
+ * @param string $profileTitle
+ */
+ public function setProfileTitle(string $profileTitle): void {
+ $this->profileTitle = $profileTitle;
+ }
+
+ /**
+ * @return string
+ */
+ public function getProfileTitle(): ?string {
+ return $this->profileTitle;
+ }
+
+ /**
+ * @param string $profileUrl
+ */
+ public function setProfileUrl(string $profileUrl): void {
+ $this->profileUrl = $profileUrl;
+ }
+
+ /**
+ * @return string
+ */
+ public function getProfileUrl(): ?string {
+ return $this->profileUrl;
+ }
+
+ /**
* @param IAction $action
*/
public function addAction(IAction $action): void {
@@ -166,6 +201,8 @@ class Entry implements IEntry {
'actions' => $otherActions,
'lastMessage' => '',
'emailAddresses' => $this->getEMailAddresses(),
+ 'profileTitle' => $this->profileTitle,
+ 'profileUrl' => $this->profileUrl,
];
}
}
diff --git a/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php b/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php
new file mode 100644
index 00000000000..4882c0ac883
--- /dev/null
+++ b/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php
@@ -0,0 +1,93 @@
+<?php
+
+/**
+ * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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/>.
+ *
+ */
+
+namespace OC\Contacts\ContactsMenu\Providers;
+
+use OCP\Accounts\IAccountManager;
+use OCP\Contacts\ContactsMenu\IActionFactory;
+use OCP\Contacts\ContactsMenu\IEntry;
+use OCP\Contacts\ContactsMenu\IProvider;
+use OCP\IURLGenerator;
+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 IL10NFactory */
+ private $l10nFactory;
+
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
+ /** @var IUserManager */
+ private $userManager;
+
+ /**
+ * @param IAccountManager $accountManager
+ * @param IActionFactory $actionFactory
+ * @param IL10NFactory $l10nFactory
+ * @param IURLGenerator $urlGenerator
+ * @param IUserManager $userManager
+ */
+ public function __construct(
+ IAccountManager $accountManager,
+ IActionFactory $actionFactory,
+ IL10NFactory $l10nFactory,
+ IURLGenerator $urlGenerator,
+ IUserManager $userManager
+ ) {
+ $this->accountManager = $accountManager;
+ $this->actionFactory = $actionFactory;
+ $this->l10nFactory = $l10nFactory;
+ $this->urlGenerator = $urlGenerator;
+ $this->userManager = $userManager;
+ }
+
+ /**
+ * @param IEntry $entry
+ */
+ public function process(IEntry $entry) {
+ $targetUserId = $entry->getProperty('UID');
+ $targetUser = $this->userManager->get($targetUserId);
+ if (!empty($targetUser)) {
+ $account = $this->accountManager->getAccount($targetUser);
+ if ($this->isProfileEnabled($account)) {
+ $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/profile.svg'));
+ $profileActionText = $this->l10nFactory->get('core')->t('View profile');
+ $profileUrl = $this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $targetUserId]);
+ $action = $this->actionFactory->newLinkAction($iconUrl, $profileActionText, $profileUrl);
+ // Set highest priority (by descending order), other actions have the default priority 10 as defined in lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
+ $action->setPriority(20);
+ $entry->addAction($action);
+ }
+ }
+ }
+}