From f6ef779f97c2abf0543184e58dd27b39aa0ea3bc Mon Sep 17 00:00:00 2001 From: Tobia De Koninck Date: Sat, 16 Sep 2017 13:42:46 +0200 Subject: [PATCH] Make ContactsStore a public API Signed-off-by: Tobia De Koninck --- apps/dav/appinfo/app.php | 2 ++ apps/dav/lib/AppInfo/Application.php | 10 +++++++ apps/dav/lib/CardDAV/ContactsManager.php | 8 ++++++ .../Contacts/ContactsMenu/ContactsStore.php | 3 ++- lib/private/Server.php | 10 +++++++ .../Contacts/ContactsMenu/IContactsStore.php | 26 +++++++++++++++++++ 6 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 lib/public/Contacts/ContactsMenu/IContactsStore.php diff --git a/apps/dav/appinfo/app.php b/apps/dav/appinfo/app.php index 8a534a75970..4f4fbe6e126 100644 --- a/apps/dav/appinfo/app.php +++ b/apps/dav/appinfo/app.php @@ -53,6 +53,8 @@ $cm->register(function() use ($cm, $app) { $user = \OC::$server->getUserSession()->getUser(); if (!is_null($user)) { $app->setupContactsProvider($cm, $user->getUID()); + } else { + $app->setupSystemContactsProvider($cm); } }); diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php index b38f38044f3..a5571286354 100644 --- a/apps/dav/lib/AppInfo/Application.php +++ b/apps/dav/lib/AppInfo/Application.php @@ -75,6 +75,16 @@ class Application extends App { $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); } + /** + * @param IManager $contactsManager + */ + public function setupSystemContactsProvider(IContactsManager $contactsManager) { + /** @var ContactsManager $cm */ + $cm = $this->getContainer()->query(ContactsManager::class); + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); + $cm->setupSystemContactsProvider($contactsManager, $urlGenerator); + } + /** * @param ICalendarManager $calendarManager * @param string $userId diff --git a/apps/dav/lib/CardDAV/ContactsManager.php b/apps/dav/lib/CardDAV/ContactsManager.php index ad02d4ba427..67e3ef2c72c 100644 --- a/apps/dav/lib/CardDAV/ContactsManager.php +++ b/apps/dav/lib/CardDAV/ContactsManager.php @@ -55,6 +55,14 @@ class ContactsManager { public function setupContactsProvider(IManager $cm, $userId, IURLGenerator $urlGenerator) { $addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId"); $this->register($cm, $addressBooks, $urlGenerator); + $this->setupSystemContactsProvider($cm, $urlGenerator); + } + + /** + * @param IManager $cm + * @param IURLGenerator $urlGenerator + */ + public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGenerator) { $addressBooks = $this->backend->getAddressBooksForUser("principals/system/system"); $this->register($cm, $addressBooks, $urlGenerator); } diff --git a/lib/private/Contacts/ContactsMenu/ContactsStore.php b/lib/private/Contacts/ContactsMenu/ContactsStore.php index 108ff0d4989..43600470e1f 100644 --- a/lib/private/Contacts/ContactsMenu/ContactsStore.php +++ b/lib/private/Contacts/ContactsMenu/ContactsStore.php @@ -35,8 +35,9 @@ use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; +use OCP\Contacts\ContactsMenu\IContactsStore; -class ContactsStore { +class ContactsStore implements IContactsStore { /** @var IManager */ private $contactsManager; diff --git a/lib/private/Server.php b/lib/private/Server.php index 0dfbcbb75ec..09128f33bfb 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -63,6 +63,7 @@ use OC\Collaboration\Collaborators\RemotePlugin; use OC\Collaboration\Collaborators\UserPlugin; use OC\Command\CronBus; use OC\Contacts\ContactsMenu\ActionFactory; +use OC\Contacts\ContactsMenu\ContactsStore; use OC\Diagnostics\EventLogger; use OC\Diagnostics\QueryLogger; use OC\Federation\CloudIdManager; @@ -1129,6 +1130,15 @@ class Server extends ServerContainer implements IServerContainer { return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); }); + $this->registerService(\OCP\Contacts\ContactsMenu\IContactsStore::class, function(Server $c) { + return new ContactsStore( + $c->getContactsManager(), + $c->getConfig(), + $c->getUserManager(), + $c->getGroupManager() + ); + }); + $this->connectDispatcher(); } diff --git a/lib/public/Contacts/ContactsMenu/IContactsStore.php b/lib/public/Contacts/ContactsMenu/IContactsStore.php new file mode 100644 index 00000000000..415c450072d --- /dev/null +++ b/lib/public/Contacts/ContactsMenu/IContactsStore.php @@ -0,0 +1,26 @@ +