consolidate user count filter in wizard and user back end
This commit is contained in:
parent
cb3af1dce2
commit
f725cc66a3
4 changed files with 16 additions and 36 deletions
|
@ -1167,6 +1167,18 @@ class Access extends LDAPUtility implements user\IUserTools {
|
|||
return $this->combineFilterWithOr($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the filter used for counting users
|
||||
*/
|
||||
public function getFilterForUserCount() {
|
||||
$filter = $this->combineFilterWithAnd(array(
|
||||
$this->connection->ldapUserFilter,
|
||||
$this->connection->ldapUserDisplayName . '=*'
|
||||
));
|
||||
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $password
|
||||
|
|
|
@ -121,10 +121,7 @@ class Wizard extends LDAPUtility {
|
|||
*/
|
||||
public function countUsers() {
|
||||
$this->detectUserDisplayNameAttribute();
|
||||
$filter = $this->access->combineFilterWithAnd(array(
|
||||
$this->configuration->ldapUserFilter,
|
||||
$this->configuration->ldapUserDisplayName . '=*'
|
||||
));
|
||||
$filter = $this->access->getFilterForUserCount();
|
||||
|
||||
$usersTotal = $this->countEntries($filter, 'users');
|
||||
$usersTotal = ($usersTotal !== false) ? $usersTotal : 0;
|
||||
|
|
|
@ -550,23 +550,9 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
|
|||
public function testCountUsers() {
|
||||
$access = $this->getAccessMock();
|
||||
|
||||
$access->connection->expects($this->once())
|
||||
->method('__get')
|
||||
->will($this->returnCallback(function($name) {
|
||||
if($name === 'ldapLoginFilter') {
|
||||
return 'uid=%uid';
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
|
||||
$access->expects($this->once())
|
||||
->method('countUsers')
|
||||
->will($this->returnCallback(function($filter, $a, $b, $c) {
|
||||
if($filter !== 'uid=*') {
|
||||
return false;
|
||||
}
|
||||
return 5;
|
||||
}));
|
||||
->will($this->returnValue(5));
|
||||
|
||||
$backend = new UserLDAP($access);
|
||||
|
||||
|
@ -577,23 +563,9 @@ class Test_User_Ldap_Direct extends \PHPUnit_Framework_TestCase {
|
|||
public function testCountUsersFailing() {
|
||||
$access = $this->getAccessMock();
|
||||
|
||||
$access->connection->expects($this->once())
|
||||
->method('__get')
|
||||
->will($this->returnCallback(function($name) {
|
||||
if($name === 'ldapLoginFilter') {
|
||||
return 'invalidFilter';
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
|
||||
$access->expects($this->once())
|
||||
->method('countUsers')
|
||||
->will($this->returnCallback(function($filter, $a, $b, $c) {
|
||||
if($filter !== 'uid=*') {
|
||||
return false;
|
||||
}
|
||||
return 5;
|
||||
}));
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$backend = new UserLDAP($access);
|
||||
|
||||
|
|
|
@ -290,8 +290,7 @@ class USER_LDAP extends BackendUtility implements \OCP\UserInterface {
|
|||
* @return int|bool
|
||||
*/
|
||||
public function countUsers() {
|
||||
$filter = \OCP\Util::mb_str_replace(
|
||||
'%uid', '*', $this->access->connection->ldapLoginFilter, 'UTF-8');
|
||||
$filter = $this->access->getFilterForUserCount();
|
||||
$entries = $this->access->countUsers($filter);
|
||||
return $entries;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue