summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-12-20 17:08:26 +0100
committerArthur Schiwon <blizzz@owncloud.com>2014-12-20 18:28:29 +0100
commit61ed363f820a3b25b68289ed2c03ff5e5edfed91 (patch)
treeace78508902f8d20bc3de4666d90af1b0445ed5b
parent3ca70d647a36144e64cbe4b90ffa97b3d9b64470 (diff)
downloadnextcloud-server-61ed363f820a3b25b68289ed2c03ff5e5edfed91.tar.gz
nextcloud-server-61ed363f820a3b25b68289ed2c03ff5e5edfed91.zip
planned refactorings for OC 8
-rw-r--r--apps/user_ldap/appinfo/register_command.php20
-rw-r--r--apps/user_ldap/command/checkuser.php35
-rw-r--r--apps/user_ldap/lib/jobs/cleanup.php49
-rw-r--r--apps/user_ldap/lib/mapping/abstractmapping.php21
-rw-r--r--apps/user_ldap/lib/user/deletedusersindex.php9
-rw-r--r--apps/user_ldap/tests/jobs/cleanup.php4
6 files changed, 83 insertions, 55 deletions
diff --git a/apps/user_ldap/appinfo/register_command.php b/apps/user_ldap/appinfo/register_command.php
index 314c73e6c4a..e0013c4eb7a 100644
--- a/apps/user_ldap/appinfo/register_command.php
+++ b/apps/user_ldap/appinfo/register_command.php
@@ -10,6 +10,17 @@ use OCA\user_ldap\lib\Helper;
use OCA\user_ldap\lib\LDAP;
use OCA\user_ldap\User_Proxy;
use OCA\User_LDAP\Mapping\UserMapping;
+use OCA\User_LDAP\lib\User\DeletedUsersIndex;
+
+$dbConnection = \OC::$server->getDatabaseConnection();
+$userMapping = new UserMapping($dbConnection);
+$helper = new Helper();
+$uBackend = new User_Proxy(
+ $helper->getServerConfigurationPrefixes(true),
+ new LDAP()
+);
+$deletedUsersIndex = new DeletedUsersIndex(
+ \OC::$server->getConfig(), $dbConnection, $userMapping);
$application->add(new OCA\user_ldap\Command\ShowConfig());
$application->add(new OCA\user_ldap\Command\SetConfig());
@@ -17,13 +28,6 @@ $application->add(new OCA\user_ldap\Command\TestConfig());
$application->add(new OCA\user_ldap\Command\CreateEmptyConfig());
$application->add(new OCA\user_ldap\Command\DeleteConfig());
$application->add(new OCA\user_ldap\Command\Search());
-$userMapping = new UserMapping(\OC::$server->getDatabaseConnection());
$application->add(new OCA\user_ldap\Command\ShowRemnants($userMapping));
-$helper = new Helper();
-$uBackend = new User_Proxy(
- $helper->getServerConfigurationPrefixes(true),
- new LDAP()
-);
$application->add(new OCA\user_ldap\Command\CheckUser(
- $uBackend, $helper, \OC::$server->getConfig()
-));
+ $uBackend, $helper, $deletedUsersIndex, $userMapping));
diff --git a/apps/user_ldap/command/checkuser.php b/apps/user_ldap/command/checkuser.php
index 96c6c832356..5b1dc36c1d0 100644
--- a/apps/user_ldap/command/checkuser.php
+++ b/apps/user_ldap/command/checkuser.php
@@ -16,6 +16,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use OCA\user_ldap\lib\user\User;
use OCA\User_LDAP\lib\user\Manager;
+use OCA\User_LDAP\lib\User\DeletedUsersIndex;
use OCA\user_ldap\lib\Helper;
use OCA\user_ldap\User_Proxy;
@@ -26,18 +27,22 @@ class CheckUser extends Command {
/** @var \OCA\User_LDAP\lib\Helper */
protected $helper;
- /** @var \OCP\IConfig */
- protected $config;
+ /** @var \OCA\User_LDAP\lib\User\DeletedUsersIndex */
+ protected $dui;
+
+ /** @var \OCA\User_LDAP\Mapping\UserMapping */
+ protected $mapping;
/**
* @param OCA\user_ldap\User_Proxy $uBackend
* @param OCA\User_LDAP\lib\Helper $helper
* @param OCP\IConfig $config
*/
- public function __construct(User_Proxy $uBackend, Helper $helper, \OCP\IConfig $config) {
+ public function __construct(User_Proxy $uBackend, Helper $helper, DeletedUsersIndex $dui, UserMapping $mapping) {
$this->backend = $uBackend;
$this->helper = $helper;
- $this->config = $config;
+ $this->dui = $dui;
+ $this->mapping = $mapping;
parent::__construct();
}
@@ -70,10 +75,7 @@ class CheckUser extends Command {
return;
}
- // TODO FIXME consolidate next line in DeletedUsersIndex
- // (impractical now, because of class dependencies)
- $this->config->setUserValue($uid, 'user_ldap', 'isDeleted', '1');
-
+ $this->dui->markUser($uid);
$output->writeln('The user does not exists on LDAP anymore.');
$output->writeln('Clean up the user\'s remnants by: ./occ user:delete "'
. $uid . '"');
@@ -86,22 +88,11 @@ class CheckUser extends Command {
* checks whether a user is actually mapped
* @param string $ocName the username as used in ownCloud
* @throws \Exception
- * @return bool
+ * @return true
*/
protected function confirmUserIsMapped($ocName) {
- //TODO FIXME this should go to Mappings in OC 8
- $db = \OC::$server->getDatabaseConnection();
- $query = $db->prepare('
- SELECT
- `ldap_dn` AS `dn`
- FROM `*PREFIX*ldap_user_mapping`
- WHERE `owncloud_name` = ?'
- );
-
- $query->execute(array($ocName));
- $result = $query->fetchColumn();
-
- if($result === false) {
+ $dn = $this->mapping->getDNByName($ocName);
+ if ($dn === false) {
throw new \Exception('The given user is not a recognized LDAP user.');
}
diff --git a/apps/user_ldap/lib/jobs/cleanup.php b/apps/user_ldap/lib/jobs/cleanup.php
index 56fb296609d..35252d6f6e5 100644
--- a/apps/user_ldap/lib/jobs/cleanup.php
+++ b/apps/user_ldap/lib/jobs/cleanup.php
@@ -11,6 +11,8 @@ namespace OCA\User_LDAP\Jobs;
use \OCA\user_ldap\User_Proxy;
use \OCA\user_ldap\lib\Helper;
use \OCA\user_ldap\lib\LDAP;
+use \OCA\User_LDAP\lib\User\DeletedUsersIndex;
+use \OCA\User_LDAP\Mapping\UserMapping;
/**
* Class CleanUp
@@ -45,6 +47,12 @@ class CleanUp extends \OC\BackgroundJob\TimedJob {
*/
protected $ldapHelper;
+ /** @var \OCA\User_LDAP\Mapping\UserMapping */
+ protected $mapping;
+
+ /** @var \OCA\User_LDAP\lib\User\DeletedUsersIndex */
+ protected $dui;
+
/**
* @var int $defaultIntervalMin default interval in minutes
*/
@@ -92,6 +100,19 @@ class CleanUp extends \OC\BackgroundJob\TimedJob {
} else {
$this->db = \OC::$server->getDatabaseConnection();
}
+
+ if(isset($arguments['mapping'])) {
+ $this->mapping = $arguments['mapping'];
+ } else {
+ $this->mapping = new UserMapping($this->db);
+ }
+
+ if(isset($arguments['deletedUsersIndex'])) {
+ $this->dui = $arguments['deletedUsersIndex'];
+ } else {
+ $this->dui = new DeletedUsersIndex(
+ $this->ocConfig, $this->db, $this->mapping);
+ }
}
/**
@@ -104,7 +125,7 @@ class CleanUp extends \OC\BackgroundJob\TimedJob {
if(!$this->isCleanUpAllowed()) {
return;
}
- $users = $this->getMappedUsers($this->limit, $this->getOffset());
+ $users = $this->mapping->getList($this->limit, $this->getOffset());
if(!is_array($users)) {
//something wrong? Let's start from the beginning next time and
//abort
@@ -169,33 +190,11 @@ class CleanUp extends \OC\BackgroundJob\TimedJob {
private function checkUser($user) {
if($this->userBackend->userExistsOnLDAP($user['name'])) {
//still available, all good
+
return;
}
- // TODO FIXME consolidate next line in DeletedUsersIndex
- // (impractical now, because of class dependencies)
- $this->ocConfig->setUserValue($user['name'], 'user_ldap', 'isDeleted', '1');
- }
-
- /**
- * returns a batch of users from the mappings table
- * @param int $limit
- * @param int $offset
- * @return array
- */
- public function getMappedUsers($limit, $offset) {
- $query = $this->db->prepare('
- SELECT
- `ldap_dn` AS `dn`,
- `owncloud_name` AS `name`,
- `directory_uuid` AS `uuid`
- FROM `*PREFIX*ldap_user_mapping`',
- $limit,
- $offset
- );
-
- $query->execute();
- return $query->fetchAll();
+ $this->dui->markUser($user['name']);
}
/**
diff --git a/apps/user_ldap/lib/mapping/abstractmapping.php b/apps/user_ldap/lib/mapping/abstractmapping.php
index 2c45c6bb1c1..19f173577f5 100644
--- a/apps/user_ldap/lib/mapping/abstractmapping.php
+++ b/apps/user_ldap/lib/mapping/abstractmapping.php
@@ -153,6 +153,27 @@ abstract class AbstractMapping {
}
/**
+ * gets a piece of the mapping list
+ * @param int $offset
+ * @param int $limit
+ * @return array
+ */
+ public function getList($offset = null, $limit = null) {
+ $query = $this->dbc->prepare('
+ SELECT
+ `ldap_dn` AS `dn`,
+ `owncloud_name` AS `name`,
+ `directory_uuid` AS `uuid`
+ FROM `*PREFIX*ldap_user_mapping`',
+ $limit,
+ $offset
+ );
+
+ $query->execute();
+ return $query->fetchAll();
+ }
+
+ /**
* attempts to map the given entry
* @param string $fdn fully distinguished name (from LDAP)
* @param string $name
diff --git a/apps/user_ldap/lib/user/deletedusersindex.php b/apps/user_ldap/lib/user/deletedusersindex.php
index 62abe2e10de..67585530279 100644
--- a/apps/user_ldap/lib/user/deletedusersindex.php
+++ b/apps/user_ldap/lib/user/deletedusersindex.php
@@ -69,6 +69,7 @@ class DeletedUsersIndex {
foreach($deletedUsers as $user) {
$userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping);
}
+ $this->deletedUsers = $userObjects;
return $this->deletedUsers;
}
@@ -97,4 +98,12 @@ class DeletedUsersIndex {
}
return false;
}
+
+ /**
+ * marks a user as deleted
+ * @param string ocName
+ */
+ public function markUser($ocName) {
+ $this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1');
+ }
}
diff --git a/apps/user_ldap/tests/jobs/cleanup.php b/apps/user_ldap/tests/jobs/cleanup.php
index 3aa9a4a43c5..642bad57134 100644
--- a/apps/user_ldap/tests/jobs/cleanup.php
+++ b/apps/user_ldap/tests/jobs/cleanup.php
@@ -15,6 +15,10 @@ class Test_CleanUp extends \PHPUnit_Framework_TestCase {
$this->getMockBuilder('\OCA\user_ldap\User_Proxy')
->disableOriginalConstructor()
->getMock();
+ $mocks['deletedUsersIndex'] =
+ $this->getMockBuilder('\OCA\user_ldap\lib\user\deletedUsersIndex')
+ ->disableOriginalConstructor()
+ ->getMock();
$mocks['ocConfig'] = $this->getMock('\OCP\IConfig');
$mocks['db'] = $this->getMock('\OCP\IDBConnection');
$mocks['helper'] = $this->getMock('\OCA\user_ldap\lib\Helper');