From 34bf0c3cb0c868f882fe8deac349acc24a82e151 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 15 Oct 2015 15:28:03 +0200 Subject: [PATCH] Add method getUserBackendName() to UserGroupBackendInterface refs #10367 refs #10373 --- application/views/scripts/group/show.phtml | 7 ++----- .../UserGroup/DbUserGroupBackend.php | 12 ++++++++++++ .../UserGroup/LdapUserGroupBackend.php | 15 +++++++++++++++ .../UserGroup/UserGroupBackendInterface.php | 9 +++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/application/views/scripts/group/show.phtml b/application/views/scripts/group/show.phtml index f76ecdf3f..8d81683ee 100644 --- a/application/views/scripts/group/show.phtml +++ b/application/views/scripts/group/show.phtml @@ -2,7 +2,6 @@ use Icinga\Data\Extensible; use Icinga\Data\Updatable; -use Icinga\Data\Selectable; $extensible = $this->hasPermission('config/authentication/groups/add') && $backend instanceof Extensible; @@ -85,12 +84,10 @@ foreach ($members as $member): ?> hasPermission('config/authentication/users/show') - && method_exists($backend, 'getUserBackend') - && ($userBackend = $backend->getUserBackend()) !== null - && $userBackend instanceof Selectable + && ($userBackend = $backend->getUserBackendName($member->user_name)) !== null ): ?> qlink($member->user_name, 'user/show', array( - 'backend' => $userBackend->getName(), + 'backend' => $userBackend, 'user' => $member->user_name ), array( 'title' => sprintf($this->translate('Show detailed information about %s'), $member->user_name) diff --git a/library/Icinga/Authentication/UserGroup/DbUserGroupBackend.php b/library/Icinga/Authentication/UserGroup/DbUserGroupBackend.php index a114cc8d1..5596f18b6 100644 --- a/library/Icinga/Authentication/UserGroup/DbUserGroupBackend.php +++ b/library/Icinga/Authentication/UserGroup/DbUserGroupBackend.php @@ -217,6 +217,18 @@ class DbUserGroupBackend extends DbRepository implements UserGroupBackendInterfa return $memberships; } + /** + * Return the name of the backend that is providing the given user + * + * @param string $username Currently unused + * + * @return null|string The name of the backend or null in case this information is not available + */ + public function getUserBackendName($username) + { + return null; // TODO(10373): Store this to the database when inserting and fetch it here + } + /** * Join group into group_membership * diff --git a/library/Icinga/Authentication/UserGroup/LdapUserGroupBackend.php b/library/Icinga/Authentication/UserGroup/LdapUserGroupBackend.php index 54ec1763b..1b1bb31d0 100644 --- a/library/Icinga/Authentication/UserGroup/LdapUserGroupBackend.php +++ b/library/Icinga/Authentication/UserGroup/LdapUserGroupBackend.php @@ -560,6 +560,21 @@ class LdapUserGroupBackend extends LdapRepository implements UserGroupBackendInt return $groups; } + /** + * Return the name of the backend that is providing the given user + * + * @param string $username Unused + * + * @return null|string The name of the backend or null in case this information is not available + */ + public function getUserBackendName($username) + { + $userBackend = $this->getUserBackend(); + if ($userBackend !== null) { + return $userBackend->getName(); + } + } + /** * Apply the given configuration on this backend * diff --git a/library/Icinga/Authentication/UserGroup/UserGroupBackendInterface.php b/library/Icinga/Authentication/UserGroup/UserGroupBackendInterface.php index a567d1f0a..31dd2c50d 100644 --- a/library/Icinga/Authentication/UserGroup/UserGroupBackendInterface.php +++ b/library/Icinga/Authentication/UserGroup/UserGroupBackendInterface.php @@ -34,4 +34,13 @@ interface UserGroupBackendInterface * @return array */ public function getMemberships(User $user); + + /** + * Return the name of the backend that is providing the given user + * + * @param string $username + * + * @return null|string The name of the backend or null in case this information is not available + */ + public function getUserBackendName($username); }