Implemented correct object tree for users without rights to root objects
authorVictor Kirhenshtein <victor@netxms.org>
Wed, 16 Feb 2005 09:08:16 +0000 (09:08 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Wed, 16 Feb 2005 09:08:16 +0000 (09:08 +0000)
include/nxclapi.h
src/console/win32/DeploymentView.cpp
src/console/win32/DeploymentView.h
src/console/win32/ObjectBrowser.cpp
src/libnxcl/libnxcl.h
src/libnxcl/objects.cpp
src/server/core/actions.cpp

index efe8a13..1dd4c66 100644 (file)
@@ -958,6 +958,7 @@ void LIBNXCL_EXPORTABLE NXCSetCommandTimeout(NXC_SESSION hSession, DWORD dwTimeo
 
 DWORD LIBNXCL_EXPORTABLE NXCSyncObjects(NXC_SESSION hSession);
 NXC_OBJECT LIBNXCL_EXPORTABLE *NXCFindObjectById(NXC_SESSION hSession, DWORD dwId);
+NXC_OBJECT LIBNXCL_EXPORTABLE *NXCFindObjectByIdNoLock(NXC_SESSION hSession, DWORD dwId);
 NXC_OBJECT LIBNXCL_EXPORTABLE *NXCFindObjectByName(NXC_SESSION hSession, TCHAR *pszName);
 void LIBNXCL_EXPORTABLE NXCEnumerateObjects(NXC_SESSION hSession, BOOL (* pHandler)(NXC_OBJECT *));
 NXC_OBJECT LIBNXCL_EXPORTABLE *NXCGetTopologyRootObject(NXC_SESSION hSession);
index 4ede229..d8371e9 100644 (file)
@@ -92,6 +92,9 @@ int CDeploymentView::OnCreate(LPCREATESTRUCT lpCreateStruct)
    m_wndListCtrl.InsertColumn(1, _T("Status"), LVCFMT_LEFT, 100);
    m_wndListCtrl.InsertColumn(2, _T("Message"), LVCFMT_LEFT, 250);
    m_wndListCtrl.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
+
+   m_imageList.Create(g_pObjectSmallImageList);
+   m_wndListCtrl.SetImageList(&m_imageList, LVSIL_SMALL);
        
        return 0;
 }
@@ -159,7 +162,15 @@ void CDeploymentView::OnDeploymentInfo(DWORD dwRqId, NXC_DEPLOYMENT_STATUS *pInf
 
          // Create new record
          pObject = NXCFindObjectById(g_hSession, pInfo->dwNodeId);
-         iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, (pObject != NULL) ? pObject->szName : _T("<invalid>"));
+         if (pObject != NULL)
+         {
+            iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, pObject->szName,
+                                             GetObjectImageIndex(pObject));
+         }
+         else
+         {
+            iItem = m_wndListCtrl.InsertItem(0x7FFFFFFF, _T("<invalid>"), -1);
+         }
          m_wndListCtrl.SetItemData(iItem, pInfo->dwNodeId);
          m_wndProgressCtrl.SetRange32(0, m_wndListCtrl.GetItemCount());
       }
index fc35158..644d624 100644 (file)
@@ -31,6 +31,7 @@ public:
 
 // Implementation
 protected:
+       CImageList m_imageList;
        CProgressCtrl m_wndProgressCtrl;
        CFont m_font;
    BOOL m_bFinished;
index a811404..9e22a13 100644 (file)
@@ -347,37 +347,42 @@ void CObjectBrowser::OnSetFocus(CWnd* pOldWnd)
 
 void CObjectBrowser::OnViewRefresh() 
 {
-   NXC_OBJECT *pObject;
+   NXC_OBJECT **ppRootObjects;
    NXC_OBJECT_INDEX *pIndex;
-   DWORD i, dwNumObjects;
+   DWORD i, j, dwNumObjects, dwNumRootObj;
    
-   // Populate objects' tree
-   m_wndTreeCtrl.DeleteAllItems();
-   m_dwTreeHashSize = 0;
-
-   pObject = NXCGetTopologyRootObject(g_hSession);
-   if (pObject != NULL)
-      AddObjectToTree(pObject, TVI_ROOT);
-
-   pObject = NXCGetServiceRootObject(g_hSession);
-   if (pObject != NULL)
-      AddObjectToTree(pObject, TVI_ROOT);
-   
-   pObject = NXCGetTemplateRootObject(g_hSession);
-   if (pObject != NULL)
-      AddObjectToTree(pObject, TVI_ROOT);
-   
-   qsort(m_pTreeHash, m_dwTreeHashSize, sizeof(OBJ_TREE_HASH), CompareTreeHashItems);
-
-   // Populate object's list
+   // Populate object's list and select root objects
    m_wndListCtrl.DeleteAllItems();
    NXCLockObjectIndex(g_hSession);
    pIndex = (NXC_OBJECT_INDEX *)NXCGetObjectIndex(g_hSession, &dwNumObjects);
-   for(i = 0; i < dwNumObjects; i++)
+   ppRootObjects = (NXC_OBJECT **)malloc(sizeof(NXC_OBJECT *) * dwNumObjects);
+   for(i = 0, dwNumRootObj = 0; i < dwNumObjects; i++)
       if (!pIndex[i].pObject->bIsDeleted)
+      {
          AddObjectToList(pIndex[i].pObject);
+
+         // Check if some of the parents are accessible
+         for(j = 0; j < pIndex[i].pObject->dwNumParents; j++)
+            if (NXCFindObjectByIdNoLock(g_hSession, pIndex[i].pObject->pdwParentList[j]) != NULL)
+               break;
+         if (j == pIndex[i].pObject->dwNumParents)
+         {
+            // No accessible parents or no parents at all
+            ppRootObjects[dwNumRootObj++] = pIndex[i].pObject;
+         }
+      }
    NXCUnlockObjectIndex(g_hSession);
    m_wndListCtrl.SortItems(CompareListItems, m_dwSortMode);
+
+   // Populate objects' tree
+   m_wndTreeCtrl.DeleteAllItems();
+   m_dwTreeHashSize = 0;
+
+   for(i = 0; i < dwNumRootObj; i++)
+      AddObjectToTree(ppRootObjects[i], TVI_ROOT);
+   safe_free(ppRootObjects);
+   
+   qsort(m_pTreeHash, m_dwTreeHashSize, sizeof(OBJ_TREE_HASH), CompareTreeHashItems);
 }
 
 
index 5b70914..c5ea420 100644 (file)
@@ -159,7 +159,7 @@ public:
    DWORD SyncObjects(void);
    void LockObjectIndex(void) { MutexLock(m_mutexIndexAccess, INFINITE); }
    void UnlockObjectIndex(void) { MutexUnlock(m_mutexIndexAccess); }
-   NXC_OBJECT *FindObjectById(DWORD dwId);
+   NXC_OBJECT *FindObjectById(DWORD dwId, BOOL bLock);
    NXC_OBJECT *FindObjectByName(TCHAR *pszName);
    void EnumerateObjects(BOOL (* pHandler)(NXC_OBJECT *));
    NXC_OBJECT *GetRootObject(DWORD dwId, DWORD dwIndex);
index 70e933f..4b74501 100644 (file)
@@ -273,7 +273,7 @@ void NXCL_Session::ProcessObjectUpdate(CSCPMessage *pMsg)
          break;
       case CMD_OBJECT_UPDATE:
          pNewObject = NewObjectFromMsg(pMsg);
-         pObject = FindObjectById(pNewObject->dwId);
+         pObject = FindObjectById(pNewObject->dwId, TRUE);
          if (pObject == NULL)
          {
             AddObject(pNewObject, TRUE);
@@ -334,21 +334,31 @@ DWORD LIBNXCL_EXPORTABLE NXCSyncObjects(NXC_SESSION hSession)
 // Find object by ID
 //
 
-NXC_OBJECT *NXCL_Session::FindObjectById(DWORD dwId)
+NXC_OBJECT *NXCL_Session::FindObjectById(DWORD dwId, BOOL bLock)
 {
    DWORD dwPos;
    NXC_OBJECT *pObject;
 
-   LockObjectIndex();
+   if (bLock)
+      LockObjectIndex();
+
    dwPos = SearchIndex(m_pIndexById, m_dwNumObjects, dwId);
    pObject = (dwPos == INVALID_INDEX) ? NULL : m_pIndexById[dwPos].pObject;
-   UnlockObjectIndex();
+
+   if (bLock)
+      UnlockObjectIndex();
+
    return pObject;
 }
 
 NXC_OBJECT LIBNXCL_EXPORTABLE *NXCFindObjectById(NXC_SESSION hSession, DWORD dwId)
 {
-   return ((NXCL_Session *)hSession)->FindObjectById(dwId);
+   return ((NXCL_Session *)hSession)->FindObjectById(dwId, TRUE);
+}
+
+NXC_OBJECT LIBNXCL_EXPORTABLE *NXCFindObjectByIdNoLock(NXC_SESSION hSession, DWORD dwId)
+{
+   return ((NXCL_Session *)hSession)->FindObjectById(dwId, FALSE);
 }
 
 
index 1bf69d7..fda6dae 100644 (file)
@@ -246,7 +246,7 @@ BOOL ExecuteAction(DWORD dwActionId, Event *pEvent)
                          pAction->szRcptAddr, pszExpandedData);
                break;
             case ACTION_REMOTE:
-               DbgPrintf(AF_DEBUG_ACTIONS, "*actions* Executing on \"%s\": \"%s\"", 
+               DbgPrintf(AF_DEBUG_ACTIONS, "*actions* Executing on \"%s\": \"%s\"",
                          pAction->szRcptAddr, pszExpandedData);
                break;
             default: