From b23a4ca96b018b31d7586883075f306f0492c7e4 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 17 Nov 2016 12:14:13 +0100 Subject: push public user data to the lookup server Signed-off-by: Bjoern Schiessle --- apps/lookup_server_connector/appinfo/app.php | 28 +++++++ apps/lookup_server_connector/appinfo/info.xml | 18 +++++ .../lib/BackgroundJobs/RetryJob.php | 33 ++++++++ .../lib/UpdateLookupServer.php | 93 ++++++++++++++++++++++ 4 files changed, 172 insertions(+) create mode 100644 apps/lookup_server_connector/appinfo/app.php create mode 100644 apps/lookup_server_connector/appinfo/info.xml create mode 100644 apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php create mode 100644 apps/lookup_server_connector/lib/UpdateLookupServer.php (limited to 'apps/lookup_server_connector') diff --git a/apps/lookup_server_connector/appinfo/app.php b/apps/lookup_server_connector/appinfo/app.php new file mode 100644 index 00000000000..e74f101853f --- /dev/null +++ b/apps/lookup_server_connector/appinfo/app.php @@ -0,0 +1,28 @@ + + * + * @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 . + * + */ + +$dispatcher = \OC::$server->getEventDispatcher(); + +$dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { + $user = $event->getSubject(); + $updateLookupServer = new \OCA\LookupServerConnector\UpdateLookupServer(); + $updateLookupServer->userUpdated($user); +}); diff --git a/apps/lookup_server_connector/appinfo/info.xml b/apps/lookup_server_connector/appinfo/info.xml new file mode 100644 index 00000000000..88898c0b71b --- /dev/null +++ b/apps/lookup_server_connector/appinfo/info.xml @@ -0,0 +1,18 @@ + + + lookup_server_connector + Lookup Server Connector + Sync public user information with the lookup server + AGPL + Bjoern Schiessle + LookupServerConnector + 1.0.0 + other + + + + + + + + diff --git a/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php b/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php new file mode 100644 index 00000000000..5c4f1e73259 --- /dev/null +++ b/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php @@ -0,0 +1,33 @@ + + * + * @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 OCA\LookupServerConnector\BackgroundJobs; + + +use OC\BackgroundJob\Job; + +class RetryJob extends Job { + + protected function run($argument) { + // TODO: Implement run() method. + } +} diff --git a/apps/lookup_server_connector/lib/UpdateLookupServer.php b/apps/lookup_server_connector/lib/UpdateLookupServer.php new file mode 100644 index 00000000000..2ccdf5b5a8c --- /dev/null +++ b/apps/lookup_server_connector/lib/UpdateLookupServer.php @@ -0,0 +1,93 @@ + + * + * @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 OCA\LookupServerConnector; + + +use OC\Accounts\AccountManager; +use OCP\IConfig; +use OCP\IUser; + +/** + * Class UpdateLookupServer + * + * @package OCA\LookupServerConnector + */ +class UpdateLookupServer { + + /** @var AccountManager */ + private $accountManager; + + /** @var IConfig */ + private $config; + + /** + * UpdateLookupServer constructor. + * + * @param AccountManager $accountManager + * @param IConfig $config + */ + public function __construct(AccountManager $accountManager, IConfig $config) { + $this->accountManager; + $this->config = $config; + } + + + public function userUpdated(IUser $user) { + $userData = $this->accountManager->getUser($user); + $authKey = $this->config->getUserValue($user->getUID(), 'lookup_server_connector', 'authKey'); + + $publicData = []; + + foreach ($userData as $data) { + if ($data['scope'] === AccountManager::VISIBILITY_PUBLIC) { + $publicData[] = $data; + } + } + + if (empty($publicData)) { + $this->removeFromLookupServer($user); + } else { + $this->sendToLookupServer($publicData, $authKey); + } + } + + /** + * remove user from lookup server + * + * @param IUser $user + */ + protected function removeFromLookupServer(IUser $user) { + $this->config->deleteUserValue($user->getUID(), 'lookup_server_connector', 'authKey'); + } + + /** + * send public user data to the lookup server + * + * @param array $publicData + * @param string $authKey + */ + protected function sendToLookupServer($publicData, $authKey) { + // If we don't update a existing entry, the server will return a authKey and we + // will add it to the database + } +} -- cgit v1.2.3