summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2019-05-23 16:58:58 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2019-05-27 12:03:05 +0200
commitc6c8a41d2f34a05dbb8b24b280c767b022a3c338 (patch)
tree45852452a236211e8126fce4557baa4aa435f0d2 /apps
parent96e892770d0b37fab66f8b92c10866fadccf98c5 (diff)
downloadnextcloud-server-c6c8a41d2f34a05dbb8b24b280c767b022a3c338.tar.gz
nextcloud-server-c6c8a41d2f34a05dbb8b24b280c767b022a3c338.zip
group display name support (service level + ldap)
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_external/ajax/applicable.php2
-rw-r--r--apps/user_ldap/lib/Access.php7
-rw-r--r--apps/user_ldap/lib/Connection.php1
-rw-r--r--apps/user_ldap/lib/Group_LDAP.php28
-rw-r--r--apps/user_ldap/lib/Group_Proxy.php7
-rw-r--r--apps/user_ldap/tests/Group_LDAPTest.php39
6 files changed, 81 insertions, 3 deletions
diff --git a/apps/files_external/ajax/applicable.php b/apps/files_external/ajax/applicable.php
index a946962a293..016a4dc7f9f 100644
--- a/apps/files_external/ajax/applicable.php
+++ b/apps/files_external/ajax/applicable.php
@@ -41,7 +41,7 @@ if (isset($_GET['offset'])) {
$groups = [];
foreach (\OC::$server->getGroupManager()->search($pattern, $limit, $offset) as $group) {
- $groups[$group->getGID()] = $group->getGID();
+ $groups[$group->getGID()] = $group->getDisplayName();
}
$users = [];
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php
index 1044938446e..6a074bbed2e 100644
--- a/apps/user_ldap/lib/Access.php
+++ b/apps/user_ldap/lib/Access.php
@@ -712,6 +712,8 @@ class Access extends LDAPUtility {
$sndName = isset($ldapObject[$sndAttribute][0])
? $ldapObject[$sndAttribute][0] : '';
$this->cacheUserDisplayName($ncName, $nameByLDAP, $sndName);
+ } else if($nameByLDAP !== null) {
+ $this->cacheGroupDisplayName($ncName, $nameByLDAP);
}
}
}
@@ -765,6 +767,11 @@ class Access extends LDAPUtility {
$this->connection->writeToCache($cacheKeyTrunk.$ocName, $displayName);
}
+ public function cacheGroupDisplayName(string $ncName, string $displayName): void {
+ $cacheKey = 'group_getDisplayName' . $ncName;
+ $this->connection->writeToCache($cacheKey, $displayName);
+ }
+
/**
* creates a unique name for internal Nextcloud use for users. Don't call it directly.
* @param string $name the display name of the object
diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php
index 4335f8e4397..35770f082fa 100644
--- a/apps/user_ldap/lib/Connection.php
+++ b/apps/user_ldap/lib/Connection.php
@@ -65,6 +65,7 @@ use OCP\ILogger;
* @property bool|string ldapNestedGroups
* @property string[] ldapBaseGroups
* @property string ldapGroupFilter
+ * @property string ldapGroupDisplayName
*/
class Connection extends LDAPUtility {
private $ldapConnectionRes = null;
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php
index cd4bd18cb44..ae2434056b1 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -42,10 +42,11 @@
namespace OCA\User_LDAP;
use OC\Cache\CappedMemoryCache;
+use OCP\Group\Backend\IGetDisplayNameBackend;
use OCP\GroupInterface;
use OCP\ILogger;
-class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLDAP {
+class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend {
protected $enabled = false;
/**
@@ -1221,4 +1222,29 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
return $connection->getConnectionResource();
}
+ /**
+ * @throws \OC\ServerNotAvailableException
+ */
+ public function getDisplayName(string $gid): string {
+ if ($this->groupPluginManager instanceof IGetDisplayNameBackend) {
+ return $this->groupPluginManager->getDisplayName($gid);
+ }
+
+ $cacheKey = 'group_getDisplayName' . $gid;
+ if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
+ return $displayName;
+ }
+
+ $displayName = $this->access->readAttribute(
+ $this->access->groupname2dn($gid),
+ $this->access->connection->ldapGroupDisplayName);
+
+ if ($displayName && (count($displayName) > 0)) {
+ $displayName = $displayName[0];
+ $this->access->connection->writeToCache($cacheKey, $displayName);
+ return $displayName;
+ }
+
+ return '';
+ }
}
diff --git a/apps/user_ldap/lib/Group_Proxy.php b/apps/user_ldap/lib/Group_Proxy.php
index 9fccb64cd46..c0599ad4870 100644
--- a/apps/user_ldap/lib/Group_Proxy.php
+++ b/apps/user_ldap/lib/Group_Proxy.php
@@ -27,7 +27,9 @@
namespace OCA\User_LDAP;
-class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP {
+use OCP\Group\Backend\IGetDisplayNameBackend;
+
+class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend {
private $backends = array();
private $refBackend = null;
@@ -272,4 +274,7 @@ class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP {
return $this->handleRequest($gid, 'getNewLDAPConnection', array($gid));
}
+ public function getDisplayName(string $gid): string {
+ return $this->handleRequest($gid, 'getDisplayName', [$gid]);
+ }
}
diff --git a/apps/user_ldap/tests/Group_LDAPTest.php b/apps/user_ldap/tests/Group_LDAPTest.php
index cb5760e3171..a505c403acb 100644
--- a/apps/user_ldap/tests/Group_LDAPTest.php
+++ b/apps/user_ldap/tests/Group_LDAPTest.php
@@ -1057,4 +1057,43 @@ class Group_LDAPTest extends TestCase {
$this->assertEquals($expectedMembers, $resultingMembers, '', 0.0, 10, true);
}
+ public function displayNameProvider() {
+ return [
+ ['Graphic Novelists', ['Graphic Novelists']],
+ ['', false],
+ ];
+ }
+
+ /**
+ * @dataProvider displayNameProvider
+ */
+ public function testGetDisplayName(string $expected, $ldapResult) {
+ $gid = 'graphic_novelists';
+
+ $access = $this->getAccessMock();
+ $access->expects($this->atLeastOnce())
+ ->method('readAttribute')
+ ->willReturn($ldapResult);
+
+ $access->connection = $this->createMock(Connection::class);
+ $access->connection->expects($this->any())
+ ->method('__get')
+ ->willReturnCallback(function($name) {
+ if($name === 'ldapGroupMemberAssocAttr') {
+ return 'member';
+ } else if($name === 'ldapGroupFilter') {
+ return 'objectclass=nextcloudGroup';
+ } else if($name === 'ldapGroupDisplayName') {
+ return 'cn';
+ }
+ return null;
+ });
+
+ /** @var GroupPluginManager $pluginManager */
+ $pluginManager = $this->createMock(GroupPluginManager::class);
+
+ $ldap = new GroupLDAP($access, $pluginManager);
+ $this->assertSame($expected, $ldap->getDisplayName($gid));
+ }
+
}