[icinga-checkins] icinga.org: icinga-web/mhein/default: * Fixed group principals showing at user panel

git at icinga.org git at icinga.org
Tue Nov 22 10:42:20 CET 2011


Module: icinga-web
Branch: mhein/default
Commit: f2534ee57cb39bec7f927e07f301b6a4ada86659
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=f2534ee57cb39bec7f927e07f301b6a4ada86659

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Tue Nov 22 10:11:16 2011 +0100

* Fixed group principals showing at user panel

---

 .../DataProvider/UserProviderAction.class.php      |    6 +++---
 app/modules/AppKit/lib/database/models/NsmUser.php |   20 +++++++++++++++-----
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php b/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php
index 746e0df..ff70398 100644
--- a/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php
+++ b/app/modules/AppKit/actions/DataProvider/UserProviderAction.class.php
@@ -59,11 +59,11 @@ class AppKit_DataProvider_UserProviderAction extends AppKitBaseAction {
 
 
         $userObject["principals"] = array();
-        $targets = $user->getTargets();
+        $targets = $user->getTargets(null,true);
 
         foreach($targets as $t) {
-            if($t->target_type != "icinga")
-                continue;
+            //if($t->target_type != "icinga")
+            //    continue;
             $userObject["principals"][] = array(
                 "target" => $t->toArray(),
                 "values" => $user->getTargetValues($t->target_name)->toArray()
diff --git a/app/modules/AppKit/lib/database/models/NsmUser.php b/app/modules/AppKit/lib/database/models/NsmUser.php
index 0374cd7..978c38b 100644
--- a/app/modules/AppKit/lib/database/models/NsmUser.php
+++ b/app/modules/AppKit/lib/database/models/NsmUser.php
@@ -325,6 +325,14 @@ class NsmUser extends BaseNsmUser {
         return $this->principals_list;
     }
 
+    public function getUserPrincipalsList() {
+        return array_keys(Doctrine_Query::create()
+            ->select('p.*')
+            ->from('NsmPrincipal p INDEXBY p.principal_id')
+            ->orWhere('p.principal_user_id = ?',$this->user_id)
+            ->execute()->toArray());
+    }
+
     private function getRoleIds() {
         $ids = array();
         foreach($this->NsmRole as $role) {
@@ -343,7 +351,7 @@ class NsmUser extends BaseNsmUser {
      * user
      * @return Doctrine_Collection
      */
-    public function getPrincipals() {
+    public function getPrincipals($userOnly= false) {
 
         if ($this->principals === null) {
             $roles = $this->getRoleIds();
@@ -376,23 +384,25 @@ class NsmUser extends BaseNsmUser {
      * @param string $type
      * @return Doctrine_Collection
      */
-    public function getTargets($type=null) {
+    public function getTargets($type=null,$userOnly = false) {
 
-        return $this->getTargetsQuery($type)->execute();
+        return $this->getTargetsQuery($type,$userOnly)->execute();
     }
 
     /**
+     *
      * Returns a DQL providing the user targets
      * @param string $type
      * @return Doctrine_Query
      */
-    protected function getTargetsQuery($type=null) {
+    protected function getTargetsQuery($type=null,$userOnly = false) {
+        $principals = $userOnly ? $this->getUserPrincipalsList() : $this->getPrincipalsList();
         $q = Doctrine_Query::create()
              ->select('t.*')
              ->distinct(true)
              ->from('NsmTarget t INDEXBY t.target_id')
              ->innerJoin('t.NsmPrincipalTarget pt')
-             ->andWhereIn('pt.pt_principal_id', $this->getPrincipalsList());
+             ->andWhereIn('pt.pt_principal_id', $principals);
 
         if ($type !== null) {
             $q->andWhere('t.target_type=?', array($type));





More information about the icinga-checkins mailing list