Commit baa47981abce5512ffdab672a5e3bb3b4d38262b

Authored by jacquiz
1 parent b79b9a80

Type: functionality change

Description:		Now checks folder permissions before displaying folders


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2875 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 47 additions and 7 deletions
lib/browse/FolderBrowser.inc
... ... @@ -61,8 +61,11 @@ class FolderBrowser extends Browser {
61 61 if ($iFolderID == "") {
62 62 // no folder specified, so start at the root folder
63 63  
  64 + //TO DO: Need to look up all the Units
64 65 // look up this users unit
65 66 $unitID = User::getUnitID($_SESSION["userID"]);
  67 +
  68 + $default->log->debug("Users UNIT = " . $unitID );
66 69  
67 70 if ($unitID) {
68 71 // if the user is in a unit, start at the unit's root folder
... ... @@ -76,12 +79,16 @@ class FolderBrowser extends Browser {
76 79  
77 80 // now lookup the folderID
78 81 $aFolders = Folder::getList("name='$unitRootFolderName' and parent_id=1");
  82 +
  83 + $default->log->debug("Users UNIT Name = " . $unitRootFolderName );
79 84  
80 85 if (!$aFolders) {
81 86 // no folder exists with this name, so start at the root
  87 + $default->log->debug("Users UNIT Name NO FOLDER EXISTS WITH THIS NAME" . $unitRootFolderName );
82 88 $iFolderID = lookupID($default->folders_table, "parent_id", 0);
83 89 } else {
84 90 $iFolderID = $aFolders[0]->getID();
  91 + $default->log->debug("FOLDER EXISTS WITH THIS NAME" . $unitRootFolderName );
85 92 }
86 93  
87 94 } else {
... ... @@ -90,11 +97,16 @@ class FolderBrowser extends Browser {
90 97 $iFolderID = lookupID($default->folders_table, "parent_id", 0);
91 98 }
92 99 }
  100 + else
  101 + {
  102 + $default->log->debug("Folder specified " . $iFolderID );
  103 + }
93 104  
94   - $default->log->debug("FolderBrowser::browseByFolder: folderID=$iFolderID");
  105 + $default->log->debug("FolderBrowser::browseByFolder: folderID=" . $iFolderID);
95 106  
96 107 // get the folder
97   - $results["folders"][] = & Folder::get($iFolderID);
  108 + $rootFolder = Folder::get($iFolderID);
  109 + $results["folders"][] = & $rootFolder;
98 110 if ($results["folders"][0]) {
99 111  
100 112 // now find all the child folders relative to this one
... ... @@ -103,6 +115,7 @@ class FolderBrowser extends Browser {
103 115 $aLookupCriteria = $this->aSortCriteria[$this->sSortField]["lookup"];
104 116  
105 117 // if we're sorting by name or creator_id then sort folders in the appropriate direction
  118 +
106 119 $sFolderQuery = "SELECT f.id FROM $default->folders_table AS f ";
107 120 if (in_array($this->sSortField, array("name", "creator_id"))) {
108 121 if (isset($aLookupCriteria)) {
... ... @@ -114,14 +127,35 @@ class FolderBrowser extends Browser {
114 127 } else {
115 128 $sFolderQuery .= "WHERE parent_id=$iFolderID ORDER BY f.name asc";
116 129 }
117   - $default->log->debug("folderQuery = $sFolderQuery");
  130 + $default->log->debug("Ordering folderQuery = $sFolderQuery");
  131 +
118 132 if ($sql->query($sFolderQuery)) {
119 133 while ($sql->next_record()) {
120   - // add the child folders to the array
121   - $results["folders"][] = & Folder::get($sql->f("id"));
  134 + $default->log->debug("In folder iteration while, with folder_id " . $sql->f("id"));
  135 + // check whether to display folders which are not readable and display/hide these accordingly
  136 + $oFolder = Folder::get($sql->f("id"));
  137 + if ($default->folderHidingFlag)
  138 + {
  139 + if (Permission::userHasFolderReadPermission($oFolder))
  140 + {
  141 + $default->log->debug("FOLDER PERMISSIONS: Does have permission for folder " . $oFolder->getID() . ":" . $sql->f("id") );
  142 + $results["folders"][] = $oFolder;
  143 + }
  144 + else
  145 + {
  146 + $default->log->debug("FOLDER PERMISSIONS: Does NOT have permission for folder " . $sql->f("id") );
  147 + }
  148 + }
  149 + else
  150 + {
  151 + $results["folders"][] = $oFolder;
  152 + }
  153 +
122 154 }
123 155 }
124 156  
  157 + $default->log->debug("Going on to document checking");
  158 +
125 159 // create query to retrieve documents in this folder
126 160 $documentQuery = "SELECT d.id as id FROM $default->documents_table AS d ";
127 161 if ( isset($aLookupCriteria) ) {
... ... @@ -139,12 +173,17 @@ class FolderBrowser extends Browser {
139 173 // initialise access flag;
140 174 $results["accessDenied"] = false;
141 175 if ($sql->query($documentQuery)) {
  176 +
  177 + // do the check for whether this documents have folder read permission, if they do, it's all good.
  178 + $hasFolderRead = Permission::userHasFolderReadPermission($rootFolder);
  179 +
142 180 while ($sql->next_record()) {
  181 + $oDocument = & Document::get($sql->f("id"));
143 182 // check permissions
144   - if (Permission::userHasDocumentReadPermission($sql->f("id"))) {
  183 + if ($hasFolderRead || Permission::userHasDocumentReadPermission($oDocument)) {
145 184 // add documents to array
146 185 // set file attributes
147   - $oDocument = & Document::get($sql->f("id"));
  186 + //$oDocument = & Document::get($sql->f("id"));
148 187 if ($oDocument->isLive()) {
149 188 $results["documents"][] = $oDocument;
150 189 }
... ... @@ -157,6 +196,7 @@ class FolderBrowser extends Browser {
157 196 $_SESSION["errorMessage"] = "documents table select failed";
158 197 }
159 198  
  199 + $default->log->debug("Finished Documment permission checking I think ... end of browswe anyhow");
160 200 return $results;
161 201 }
162 202 }
... ...