]> source.dussan.org Git - nextcloud-server.git/commitdiff
push public user data to the lookup server
authorBjoern Schiessle <bjoern@schiessle.org>
Thu, 17 Nov 2016 11:14:13 +0000 (12:14 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Mon, 21 Nov 2016 10:29:59 +0000 (11:29 +0100)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
.gitignore
apps/lookup_server_connector/appinfo/app.php [new file with mode: 0644]
apps/lookup_server_connector/appinfo/info.xml [new file with mode: 0644]
apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php [new file with mode: 0644]
apps/lookup_server_connector/lib/UpdateLookupServer.php [new file with mode: 0644]
core/shipped.json
tests/lib/App/ManagerTest.php

index 964701eea63ae35348a538d5f82c2c3d521dd454..fa49588fad4b2a9fc3c114c11c77599d5ba1ad68 100644 (file)
@@ -22,6 +22,7 @@
 !/apps/files_sharing
 !/apps/files_trashbin
 !/apps/files_versions
+!/apps/lookup_server_connector
 !/apps/user_ldap
 !/apps/provisioning_api
 !/apps/systemtags
diff --git a/apps/lookup_server_connector/appinfo/app.php b/apps/lookup_server_connector/appinfo/app.php
new file mode 100644 (file)
index 0000000..e74f101
--- /dev/null
@@ -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);
+});
diff --git a/apps/lookup_server_connector/appinfo/info.xml b/apps/lookup_server_connector/appinfo/info.xml
new file mode 100644 (file)
index 0000000..88898c0
--- /dev/null
@@ -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>
diff --git a/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php b/apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php
new file mode 100644 (file)
index 0000000..5c4f1e7
--- /dev/null
@@ -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.
+       }
+}
diff --git a/apps/lookup_server_connector/lib/UpdateLookupServer.php b/apps/lookup_server_connector/lib/UpdateLookupServer.php
new file mode 100644 (file)
index 0000000..2ccdf5b
--- /dev/null
@@ -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
+       }
+}
index f831d17f36a5ce8ce321f4b0a240fc7c1f0f5be0..7fb87b7f17db73d0d9469e3ddae78f2835c32830 100644 (file)
@@ -22,6 +22,7 @@
     "firstrunwizard",
     "gallery",
     "logreader",
+    "lookup_server_connector",
     "notifications",
     "password_policy",
     "provisioning_api",
@@ -42,6 +43,7 @@
     "files",
     "dav",
     "federatedfilesharing",
+    "lookup_server_connector",
     "provisioning_api",
     "twofactor_backupcodes",
     "workflowengine"
index 3dbcb8a560988b1b1642d6a9c44874344865790a..e38f72b3d92fe826edda5f84ae5dd47315615893 100644 (file)
@@ -320,6 +320,7 @@ class ManagerTest extends TestCase {
                        'dav',
                        'federatedfilesharing',
                        'files',
+                       'lookup_server_connector',
                        'provisioning_api',
                        'test1',
                        'test3',
@@ -344,6 +345,7 @@ class ManagerTest extends TestCase {
                        'dav',
                        'federatedfilesharing',
                        'files',
+                       'lookup_server_connector',
                        'provisioning_api',
                        'test1',
                        'test3',
@@ -364,6 +366,7 @@ class ManagerTest extends TestCase {
                        'files' => ['id' => 'files'],
                        'federatedfilesharing' => ['id' => 'federatedfilesharing'],
                        'provisioning_api' => ['id' => 'provisioning_api'],
+                       'lookup_server_connector' => ['id' => 'lookup_server_connector'],
                        'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '9.0.0'],
                        'test2' => ['id' => 'test2', 'version' => '1.0.0', 'requiremin' => '8.2.0'],
                        'test3' => ['id' => 'test3', 'version' => '1.2.4', 'requiremin' => '9.0.0'],
@@ -408,6 +411,7 @@ class ManagerTest extends TestCase {
                        'files' => ['id' => 'files'],
                        'federatedfilesharing' => ['id' => 'federatedfilesharing'],
                        'provisioning_api' => ['id' => 'provisioning_api'],
+                       'lookup_server_connector' => ['id' => 'lookup_server_connector'],
                        'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '8.0.0'],
                        'test2' => ['id' => 'test2', 'version' => '1.0.0', 'requiremin' => '8.2.0'],
                        'test3' => ['id' => 'test3', 'version' => '1.2.4', 'requiremin' => '9.0.0'],