Browse Source
push public user data to the lookup server
push public user data to the lookup server
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>pull/1946/head
committed by
Roeland Jago Douma
No known key found for this signature in database
GPG Key ID: F941078878347C0C
7 changed files with 179 additions and 0 deletions
-
1.gitignore
-
28apps/lookup_server_connector/appinfo/app.php
-
18apps/lookup_server_connector/appinfo/info.xml
-
33apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php
-
93apps/lookup_server_connector/lib/UpdateLookupServer.php
-
2core/shipped.json
-
4tests/lib/App/ManagerTest.php
@ -0,0 +1,28 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org> |
||||
|
* |
||||
|
* @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/>. |
||||
|
* |
||||
|
*/ |
||||
|
|
||||
|
$dispatcher = \OC::$server->getEventDispatcher(); |
||||
|
|
||||
|
$dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
||||
|
$user = $event->getSubject(); |
||||
|
$updateLookupServer = new \OCA\LookupServerConnector\UpdateLookupServer(); |
||||
|
$updateLookupServer->userUpdated($user); |
||||
|
}); |
||||
@ -0,0 +1,18 @@ |
|||||
|
<?xml version="1.0"?> |
||||
|
<info> |
||||
|
<id>lookup_server_connector</id> |
||||
|
<name>Lookup Server Connector</name> |
||||
|
<description>Sync public user information with the lookup server</description> |
||||
|
<licence>AGPL</licence> |
||||
|
<author>Bjoern Schiessle</author> |
||||
|
<namespace>LookupServerConnector</namespace> |
||||
|
<version>1.0.0</version> |
||||
|
<category>other</category> |
||||
|
<dependencies> |
||||
|
<owncloud min-version="11.0" max-version="11.0" /> |
||||
|
</dependencies> |
||||
|
<default_enable/> |
||||
|
<types> |
||||
|
<authentication/> |
||||
|
</types> |
||||
|
</info> |
||||
@ -0,0 +1,33 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org> |
||||
|
* |
||||
|
* @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 OCA\LookupServerConnector\BackgroundJobs; |
||||
|
|
||||
|
|
||||
|
use OC\BackgroundJob\Job; |
||||
|
|
||||
|
class RetryJob extends Job { |
||||
|
|
||||
|
protected function run($argument) { |
||||
|
// TODO: Implement run() method.
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,93 @@ |
|||||
|
<?php |
||||
|
/** |
||||
|
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org> |
||||
|
* |
||||
|
* @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 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
|
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue