From c6c8a41d2f34a05dbb8b24b280c767b022a3c338 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 23 May 2019 16:58:58 +0200 Subject: group display name support (service level + ldap) Signed-off-by: Arthur Schiwon --- apps/user_ldap/lib/Access.php | 7 +++++++ apps/user_ldap/lib/Connection.php | 1 + apps/user_ldap/lib/Group_LDAP.php | 28 +++++++++++++++++++++++++++- apps/user_ldap/lib/Group_Proxy.php | 7 ++++++- 4 files changed, 41 insertions(+), 2 deletions(-) (limited to 'apps/user_ldap/lib') 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]); + } } -- cgit v1.2.3