[Pkg-owncloud-commits] [owncloud] 61/69: Backport of #20093 and #20124

David Prévot taffit at moszumanska.debian.org
Wed Nov 11 02:04:14 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 17219162dea81e87d6fd78cddf7745803f8aa47a
Author: Arthur Schiwon <blizzz at owncloud.com>
Date:   Tue Sep 29 16:19:45 2015 +0200

    Backport of #20093 and #20124
    
     #20093 LDAP fix quota and case
     #20124 remove uselessly used parameter, read all user attributes also when looking up users in groups
    
    fix update quota with known value
    
    fix attribute casing to ensure array keys work
    
    remove uselessly used parameter, read all user attributes also when looking up users in groups
---
 apps/user_ldap/group_ldap.php      |  5 +++--
 apps/user_ldap/lib/access.php      |  2 +-
 apps/user_ldap/lib/user/user.php   |  6 +++---
 apps/user_ldap/tests/access.php    | 16 +++++++++++++---
 apps/user_ldap/tests/user/user.php | 39 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 59 insertions(+), 9 deletions(-)

diff --git a/apps/user_ldap/group_ldap.php b/apps/user_ldap/group_ldap.php
index 4fd029c..38f8b98 100644
--- a/apps/user_ldap/group_ldap.php
+++ b/apps/user_ldap/group_ldap.php
@@ -552,6 +552,7 @@ class GROUP_LDAP extends BackendUtility implements \OCP\GroupInterface {
 
 		$groupUsers = array();
 		$isMemberUid = (strtolower($this->access->connection->ldapGroupMemberAssocAttr) === 'memberuid');
+		$attrs = $this->access->userManager->getAttributes(true);
 		foreach($members as $member) {
 			if($isMemberUid) {
 				//we got uids, need to get their DNs to 'translate' them to user names
@@ -559,11 +560,11 @@ class GROUP_LDAP extends BackendUtility implements \OCP\GroupInterface {
 					str_replace('%uid', $member, $this->access->connection->ldapLoginFilter),
 					$this->access->getFilterPartForUserSearch($search)
 				));
-				$ldap_users = $this->access->fetchListOfUsers($filter, 'dn');
+				$ldap_users = $this->access->fetchListOfUsers($filter, $attrs, 1);
 				if(count($ldap_users) < 1) {
 					continue;
 				}
-				$groupUsers[] = $this->access->dn2username($ldap_users[0]);
+				$groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]);
 			} else {
 				//we got DNs, check if we need to filter by search or we can give back all of them
 				if(!empty($search)) {
diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php
index 908a79b..7be9118 100644
--- a/apps/user_ldap/lib/access.php
+++ b/apps/user_ldap/lib/access.php
@@ -707,7 +707,7 @@ class Access extends LDAPUtility implements user\IUserTools {
 	 */
 	public function batchApplyUserAttributes(array $ldapRecords){
 		foreach($ldapRecords as $userRecord) {
-			$ocName  = $this->dn2ocname($userRecord['dn'][0], $userRecord[$this->connection->ldapUserDisplayName]);
+			$ocName  = $this->dn2ocname($userRecord['dn'][0]);
 			$this->cacheUserExists($ocName);
 			$user = $this->userManager->get($ocName);
 			if($user instanceof OfflineUser) {
diff --git a/apps/user_ldap/lib/user/user.php b/apps/user_ldap/lib/user/user.php
index d814803..637b95d 100644
--- a/apps/user_ldap/lib/user/user.php
+++ b/apps/user_ldap/lib/user/user.php
@@ -416,9 +416,9 @@ class User {
 		}
 		//can be null
 		$quotaDefault = $this->connection->ldapQuotaDefault;
-		$quota = !is_null($valueFromLDAP)
-			? $valueFromLDAP
-			: $quotaDefault !== '' ? $quotaDefault : null;
+		$quota = $quotaDefault !== '' ? $quotaDefault : null;
+		$quota = !is_null($valueFromLDAP) ? $valueFromLDAP : $quota;
+
 		if(is_null($valueFromLDAP)) {
 			$quotaAttribute = $this->connection->ldapQuotaAttribute;
 			if(!empty($quotaAttribute)) {
diff --git a/apps/user_ldap/tests/access.php b/apps/user_ldap/tests/access.php
index cb6dbf0..25e871d 100644
--- a/apps/user_ldap/tests/access.php
+++ b/apps/user_ldap/tests/access.php
@@ -230,24 +230,34 @@ class Test_Access extends \Test\TestCase {
 		$mapperMock = $this->getMockBuilder('\OCA\User_LDAP\Mapping\UserMapping')
 			->disableOriginalConstructor()
 			->getMock();
+
+		$mapperMock->expects($this->any())
+			->method('getNameByDN')
+			->will($this->returnValue('a_username'));
+
 		$userMock = $this->getMockBuilder('\OCA\user_ldap\lib\user\User')
 			->disableOriginalConstructor()
 			->getMock();
 
+		$access->connection->expects($this->any())
+			->method('__get')
+			->will($this->returnValue('displayName'));
+
 		$access->setUserMapper($mapperMock);
 
+		$displayNameAttribute = strtolower($access->connection->ldapUserDisplayName);
 		$data = array(
 			array(
 				'dn' => 'foobar',
-				$con->ldapUserDisplayName => 'barfoo'
+				$displayNameAttribute => 'barfoo'
 			),
 			array(
 				'dn' => 'foo',
-				$con->ldapUserDisplayName => 'bar'
+				$displayNameAttribute => 'bar'
 			),
 			array(
 				'dn' => 'raboof',
-				$con->ldapUserDisplayName => 'oofrab'
+				$displayNameAttribute => 'oofrab'
 			)
 		);
 
diff --git a/apps/user_ldap/tests/user/user.php b/apps/user_ldap/tests/user/user.php
index 1c41eb7..19581d8 100644
--- a/apps/user_ldap/tests/user/user.php
+++ b/apps/user_ldap/tests/user/user.php
@@ -370,6 +370,45 @@ class Test_User_User extends \Test\TestCase {
 		$user->updateQuota();
 	}
 
+	public function testUpdateQuotaFromValue() {
+		list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =
+			$this->getTestInstances();
+
+		list($access, $connection) =
+			$this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
+		$readQuota = '19 GB';
+
+		$connection->expects($this->at(0))
+			->method('__get')
+			->with($this->equalTo('ldapQuotaDefault'))
+			->will($this->returnValue(''));
+
+		$connection->expects($this->once(1))
+			->method('__get')
+			->with($this->equalTo('ldapQuotaDefault'))
+			->will($this->returnValue(null));
+
+		$access->expects($this->never())
+			->method('readAttribute');
+
+		$config->expects($this->once())
+			->method('setUserValue')
+			->with($this->equalTo('alice'),
+				$this->equalTo('files'),
+				$this->equalTo('quota'),
+				$this->equalTo($readQuota))
+			->will($this->returnValue(true));
+
+		$uid = 'alice';
+		$dn  = 'uid=alice,dc=foo,dc=bar';
+
+		$user = new User(
+			$uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr);
+
+		$user->updateQuota($readQuota);
+	}
+
 	//the testUpdateAvatar series also implicitely tests getAvatarImage
 	public function testUpdateAvatarJpegPhotoProvided() {
 		list($access, $config, $filesys, $image, $log, $avaMgr, $dbc) =

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list