Commit c159e7926904c214c8c21cd5e29e19337a1e4714

Authored by kevin_fourie
1 parent 38203192

Merged in from DEV trunk...

KTS-2402
"Display the search expression tree"
Implemented.

Committed By: Conrad Vermeulen
Reviewed By: Megan Watson

KTS-3178
"Checking for write permission doesn't check if document is immutable. if immutable, user cannot have write access."
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Martin Kirsten

KTS-3177
"Unit admin permissions"
Fixed. Changed logic which checks whether the Manage Security permission is being disabled.

Committed By: Jonathan Byrne
Reviewed By: Megan Watson

KTS-3187
"Problem with opendir() in windows under indexerCore"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Martin Kirsten

KTS-3187
"Problem with opendir() in windows under indexerCore"
Fixed. 

Committed By: Conrad Vermeulen
Reviewed By: Martin Kirsten

KTS-3188
"Indexing Diagnostics page provides an invalid link to documents"
Fixed.

Committed By: Conrad Vermeulen	
Reviewed By: Monique

KTS-3182
"documentutil->add function should at least throw a warning if 'contents' is there and 'temp_file' isn't"
Fixed. Added an error message if the temp file is not there.

Committed by: Megan Watson
Reviewed by: Jonathan Byrne



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@8295 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/documentutil.inc.php
@@ -254,15 +254,15 @@ class KTDocumentUtil { @@ -254,15 +254,15 @@ class KTDocumentUtil {
254 'folderid' => $oFolder->getID(), 254 'folderid' => $oFolder->getID(),
255 'creatorid' => $oUser->getID(), 255 'creatorid' => $oUser->getID(),
256 'documenttypeid' => $iDocumentTypeId, 256 'documenttypeid' => $iDocumentTypeId,
257 - )); 257 + ));
258 258
259 $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Storing contents'))); 259 $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Storing contents')));
260 $res = KTDocumentUtil::storeContents($oDocument, '', $aOptions); 260 $res = KTDocumentUtil::storeContents($oDocument, '', $aOptions);
261 if (PEAR::isError($res)) { 261 if (PEAR::isError($res)) {
262 if (!PEAR::isError($oDocument)) { 262 if (!PEAR::isError($oDocument)) {
263 - $oDocument->delete(); 263 + $oDocument->delete();
264 } 264 }
265 - return $res; 265 + return $res;
266 } 266 }
267 267
268 if (is_null($aMetadata)) { 268 if (is_null($aMetadata)) {
@@ -707,7 +707,7 @@ class KTDocumentUtil { @@ -707,7 +707,7 @@ class KTDocumentUtil {
707 $oKTConfig =& KTConfig::getSingleton(); 707 $oKTConfig =& KTConfig::getSingleton();
708 $sBasedir = $oKTConfig->get('urls/tmpDirectory'); 708 $sBasedir = $oKTConfig->get('urls/tmpDirectory');
709 709
710 - $sFilename = (isset($aOptions['temp_file'])) ? $aOptions['temp_file'] : tempnam($sBasedir, 'kt_storecontents'); 710 + $sFilename = (isset($aOptions['temp_file'])) ? $aOptions['temp_file'] : '';
711 711
712 // $oOutputFile = new KTFSFileLike($sFilename); 712 // $oOutputFile = new KTFSFileLike($sFilename);
713 // $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile); 713 // $res = KTFileLikeUtil::copy_contents($oContents, $oOutputFile);
@@ -717,6 +717,10 @@ class KTDocumentUtil { @@ -717,6 +717,10 @@ class KTDocumentUtil {
717 // return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage())); 717 // return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), $res->getMessage()));
718 // } 718 // }
719 719
  720 + if(empty($sFilename)){
  721 + return PEAR::raiseError(sprintf(_kt("Couldn't store contents: %s"), _kt('The uploaded file does not exist.')));
  722 + }
  723 +
720 $sType = KTMime::getMimeTypeFromFile($sFilename); 724 $sType = KTMime::getMimeTypeFromFile($sFilename);
721 $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName()); 725 $iMimeTypeId = KTMime::getMimeTypeID($sType, $oDocument->getFileName());
722 $oDocument->setMimeTypeId($iMimeTypeId); 726 $oDocument->setMimeTypeId($iMimeTypeId);
lib/groups/GroupUtil.php
@@ -309,7 +309,7 @@ class GroupUtil { @@ -309,7 +309,7 @@ class GroupUtil {
309 309
310 global $default; 310 global $default;
311 $sTable = $default->users_groups_table; 311 $sTable = $default->users_groups_table;
312 - $sQuery = "SELECT count(*) AS cnt FROM $sTable WHERE user_id = ? AND group_id IN (?)"; 312 + $sQuery = "SELECT COUNT(group_id) AS cnt FROM $sTable WHERE user_id = ? AND group_id IN (?)";
313 $aParams = array($iUserId, $sGroupIds); 313 $aParams = array($iUserId, $sGroupIds);
314 314
315 $res = DBUtil::getOneResult(array($sQuery, $aParams)); 315 $res = DBUtil::getOneResult(array($sQuery, $aParams));
lib/security/Permission.inc
@@ -59,6 +59,14 @@ class Permission { @@ -59,6 +59,14 @@ class Permission {
59 return false; 59 return false;
60 } 60 }
61 61
  62 + if ($oDocument->getIsCheckedOut())
  63 + {
  64 + if ($oDocument->getCheckedOutUserID() != $_SESSION["userID"])
  65 + {
  66 + return false;
  67 + }
  68 + }
  69 +
62 $oUser = User::get($_SESSION["userID"]); 70 $oUser = User::get($_SESSION["userID"]);
63 $oPermission = KTPermission::getByName('ktcore.permissions.write'); 71 $oPermission = KTPermission::getByName('ktcore.permissions.write');
64 72
plugins/ktcore/folder/Permissions.php
@@ -456,29 +456,55 @@ class KTFolderPermissionsAction extends KTFolderAction { @@ -456,29 +456,55 @@ class KTFolderPermissionsAction extends KTFolderAction {
456 456
457 $aFoo = $_REQUEST['foo']; 457 $aFoo = $_REQUEST['foo'];
458 $aPermissions = KTPermission::getList(); 458 $aPermissions = KTPermission::getList();
459 - 459 +
  460 + //-------------------
  461 + //This section is used to make sure that a user doesn't disable the admin groups
  462 + //Manage security permission or the Manage Security permission of a group they
  463 + //are currently a member of.
  464 +
460 // Check which groups have permission to manage security 465 // Check which groups have permission to manage security
461 - $aNewGroups = $aFoo[4]['group']; 466 + $aNewGroups = (isset($aFoo[4]['group']) ? $aFoo[4]['group'] : array());
462 $aNewRoles = (isset($aFoo[4]['role']) ? $aFoo[4]['role'] : array()); 467 $aNewRoles = (isset($aFoo[4]['role']) ? $aFoo[4]['role'] : array());
463 -  
464 - // Ensure the user is not removing his/her own permission to update the folder permissions (manage security)  
465 - if(!in_array(-3, $aNewRoles)){  
466 - $iUserId = $this->oUser->getId();  
467 - if(!GroupUtil::checkUserInGroups($iUserId, $aNewGroups)){  
468 - // If user no longer has permission, return an error.  
469 - $this->addErrorMessage(_kt('The selected permissions cannot be updated. You will no longer have permission to manage security on this folder.'));  
470 - $this->redirectTo('edit', 'fFolderId=' . $this->oFolder->getId());  
471 - exit(0);  
472 - } 468 +
  469 + $iUserId = $this->oUser->getId();
  470 +
  471 + //Check that they aren't removing the sys admin Manage Security permission
  472 + //1 in this case is the admin group.
  473 + if(!in_array('1', $aNewGroups))
  474 + {
  475 + $this->addErrorMessage(_kt('You cannot remove the Manage Security permission from the System Administrators Group'));
  476 + $this->redirectTo('edit', 'fFolderId=' . $this->oFolder->getId());
  477 + exit(0);
473 } 478 }
474 -  
475 - 479 +
  480 +
  481 + //Check that they aren't removing the Manage Security permission from a group
  482 + //They are a member of.
  483 + if(!GroupUtil::checkUserInGroups($iUserId, array(1)))
  484 + {
  485 + //Ensure the user is not removing his/her own permission to update the folder permissions (manage security)
  486 + if(!in_array(-3, $aNewRoles))
  487 + {
  488 +
  489 + if(!GroupUtil::checkUserInGroups($iUserId, $aNewGroups))
  490 + {
  491 + // If user no longer has permission, return an error.
  492 + $this->addErrorMessage(_kt('You cannot remove the Manage Security permission from a group you belong to.'));
  493 + $this->redirectTo('edit', 'fFolderId=' . $this->oFolder->getId());
  494 + exit(0);
  495 + }
  496 +
  497 + }
  498 + }
  499 + //-----------------
  500 +
  501 +
476 require_once(KT_LIB_DIR . '/documentmanagement/observers.inc.php'); 502 require_once(KT_LIB_DIR . '/documentmanagement/observers.inc.php');
477 $oPO = KTPermissionObject::get($this->oFolder->getPermissionObjectId()); 503 $oPO = KTPermissionObject::get($this->oFolder->getPermissionObjectId());
478 504
479 foreach ($aPermissions as $oPermission) { 505 foreach ($aPermissions as $oPermission) {
480 $iPermId = $oPermission->getId(); 506 $iPermId = $oPermission->getId();
481 - 507 +
482 $aAllowed = KTUtil::arrayGet($aFoo, $iPermId, array()); 508 $aAllowed = KTUtil::arrayGet($aFoo, $iPermId, array());
483 KTPermissionUtil::setPermissionForId($oPermission, $oPO, $aAllowed); 509 KTPermissionUtil::setPermissionForId($oPermission, $oPO, $aAllowed);
484 } 510 }
plugins/search2/reporting/templates/indexerrors.smarty
@@ -34,7 +34,7 @@ @@ -34,7 +34,7 @@
34 {foreach key=key from=$index_errors item=indexError} 34 {foreach key=key from=$index_errors item=indexError}
35 <tr> 35 <tr>
36 <td class="centered"><input type="checkbox" name="index_error[{$indexError.document_id}]" value="1"/></td> 36 <td class="centered"><input type="checkbox" name="index_error[{$indexError.document_id}]" value="1"/></td>
37 - <td><a href="/view.php?fDocumentId={$pendingDocs.document_id}">{$indexError.filename|truncate:40:'...'}</a></td> 37 + <td><a href="/view.php?fDocumentId={$indexError.document_id}">{$indexError.filename|truncate:40:'...'}</a></td>
38 <td>{if $indexError.extractor}{$indexError.extractor}{else}<p><font color="#FF9933">{i18n}n/a{/i18n}</font></p>{/if}</td> 38 <td>{if $indexError.extractor}{$indexError.extractor}{else}<p><font color="#FF9933">{i18n}n/a{/i18n}</font></p>{/if}</td>
39 <td>{$indexError.indexdate}</td> 39 <td>{$indexError.indexdate}</td>
40 40
search2/indexing/indexerCore.inc.php
@@ -475,10 +475,21 @@ abstract class Indexer @@ -475,10 +475,21 @@ abstract class Indexer
475 * @param string $document 475 * @param string $document
476 * @param string $what 476 * @param string $what
477 */ 477 */
478 - public static function index($document, $what='C') 478 + public static function index($document, $what='A')
479 { 479 {
480 global $default; 480 global $default;
481 481
  482 + if (is_numeric($document))
  483 + {
  484 + $document = Document::get($document+0);
  485 + }
  486 +
  487 + if (PEAR::isError($document))
  488 + {
  489 + $default->log->error("index: Could not index document: " .$document->getMessage());
  490 + return;
  491 + }
  492 +
482 $document_id = $document->getId(); 493 $document_id = $document->getId();
483 $userid=$_SESSION['userID']; 494 $userid=$_SESSION['userID'];
484 if (empty($userid)) $userid=1; 495 if (empty($userid)) $userid=1;
@@ -601,7 +612,8 @@ abstract class Indexer @@ -601,7 +612,8 @@ abstract class Indexer
601 $this->generalHookCache = array(); 612 $this->generalHookCache = array();
602 $this->mimeHookCache = array(); 613 $this->mimeHookCache = array();
603 614
604 - $dir = opendir($this->hookPath); 615 +
  616 + $dir = opendir(SearchHelper::correctPath($this->hookPath));
605 while (($file = readdir($dir)) !== false) 617 while (($file = readdir($dir)) !== false)
606 { 618 {
607 if (substr($file,-12) == 'Hook.inc.php') 619 if (substr($file,-12) == 'Hook.inc.php')
@@ -1361,7 +1373,8 @@ abstract class Indexer @@ -1361,7 +1373,8 @@ abstract class Indexer
1361 global $default; 1373 global $default;
1362 1374
1363 $diagnoses = array(); 1375 $diagnoses = array();
1364 - $dir = opendir($path); 1376 +
  1377 + $dir = opendir(SearchHelper::correctPath($path));
1365 $extlen = - strlen($extension); 1378 $extlen = - strlen($extension);
1366 1379
1367 while (($file = readdir($dir)) !== false) 1380 while (($file = readdir($dir)) !== false)
@@ -1433,7 +1446,7 @@ abstract class Indexer @@ -1433,7 +1446,7 @@ abstract class Indexer
1433 { 1446 {
1434 $this->clearExtractors(); 1447 $this->clearExtractors();
1435 } 1448 }
1436 - $dir = opendir($this->extractorPath); 1449 + $dir = opendir(SearchHelper::correctPath($this->extractorPath));
1437 while (($file = readdir($dir)) !== false) 1450 while (($file = readdir($dir)) !== false)
1438 { 1451 {
1439 if (substr($file,-17) == 'Extractor.inc.php') 1452 if (substr($file,-17) == 'Extractor.inc.php')
search2/search/bin/search2graphviz.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +/**
  4 + * $Id:$
  5 + *
  6 + * KnowledgeTree Open Source Edition
  7 + * Document Management Made Simple
  8 + * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify it under
  11 + * the terms of the GNU General Public License version 3 as published by the
  12 + * Free Software Foundation.
  13 + *
  14 + * This program is distributed in the hope that it will be useful, but WITHOUT
  15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17 + * details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + *
  22 + * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
  23 + * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
  24 + *
  25 + * The interactive user interfaces in modified source and object code versions
  26 + * of this program must display Appropriate Legal Notices, as required under
  27 + * Section 5 of the GNU General Public License version 3.
  28 + *
  29 + * In accordance with Section 7(b) of the GNU General Public License version 3,
  30 + * these Appropriate Legal Notices must retain the display of the "Powered by
  31 + * KnowledgeTree" logo and retain the original copyright notice. If the display of the
  32 + * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
  33 + * must display the words "Powered by KnowledgeTree" and retain the original
  34 + * copyright notice.
  35 + * Contributor( s): ______________________________________
  36 + *
  37 + */
  38 +
  39 +$curdir = getcwd();
  40 +chdir(dirname(__FILE__));
  41 +require_once(realpath('../../../config/dmsDefaults.php'));
  42 +
  43 +$expr = '';
  44 +
  45 +$filename = 'search2graphviz.jpg';
  46 +$verbose = false;
  47 +if ($argc > 0)
  48 +{
  49 + foreach($argv as $arg)
  50 + {
  51 + if (strpos($arg, '=') === false)
  52 + {
  53 + $expr = $arg;
  54 + continue;
  55 + }
  56 + list($param, $value) = explode('=', $arg);
  57 +
  58 + switch (strtolower($param))
  59 + {
  60 + case 'verbose':
  61 + $verbose=true;
  62 + break;
  63 + case 'output':
  64 + $filename = $value;
  65 + if ($verbose) print "* output = $value\n";
  66 + break;
  67 + case 'user':
  68 + $username = $value;
  69 + if ($verbose) print "* User = $value\n";
  70 + break;
  71 + case 'pass':
  72 + $password = $value;
  73 + if ($verbose) print "* User = $value\n";
  74 + break;
  75 + case 'help':
  76 + print "Usage: search2graphviz.php [verbose] output=filename 'search criteria'\n";
  77 + exit;
  78 + }
  79 + }
  80 +}
  81 +
  82 +if ($verbose) print _kt('Visgraph search expression') . "...\n";
  83 +
  84 +try
  85 +{
  86 + $expr = parseExpression($expr);
  87 +
  88 + $expr->toVizGraph(array('tofile'=>$filename));
  89 +
  90 + if ($verbose)
  91 + {
  92 + print _kt("Done.") . "\n";
  93 + }
  94 +
  95 +}
  96 +catch(Exception $e)
  97 +{
  98 + print $e->getMessage();
  99 +}
  100 +
  101 +?>
0 \ No newline at end of file 102 \ No newline at end of file
search2/search/expr.inc.php
@@ -273,18 +273,21 @@ class Expr @@ -273,18 +273,21 @@ class Expr
273 $ext = pathinfo($filename, PATHINFO_EXTENSION); 273 $ext = pathinfo($filename, PATHINFO_EXTENSION);
274 $base = substr($filename, 0, -strlen($ext)-1); 274 $base = substr($filename, 0, -strlen($ext)-1);
275 275
276 - $dotfile="$path/$base.$ext";  
277 - $jpgfile="$path/$base.jpg"; 276 + $curdir = getcwd();
  277 + chdir($_ENV['PWD']);
  278 + $dotfile="$base.$ext";
  279 + $jpgfile="$base.jpg";
278 $fp = fopen($dotfile,'wt'); 280 $fp = fopen($dotfile,'wt');
279 fwrite($fp, $str); 281 fwrite($fp, $str);
280 fclose($fp); 282 fclose($fp);
281 283
282 - system("dot -Tjpg -o$jpgfile $dotfile"); 284 + system("dot -Tjpg -o$jpgfile $dotfile 2>1 >/dev/null ");
283 285
284 if (isset($options['view']) && $options['view']) 286 if (isset($options['view']) && $options['view'])
285 { 287 {
286 system("eog $jpgfile"); 288 system("eog $jpgfile");
287 } 289 }
  290 + chdir($curdir);
288 } 291 }
289 292
290 return $str; 293 return $str;
search2/search/fieldRegistry.inc.php
@@ -223,7 +223,7 @@ class ExprFieldRegistry @@ -223,7 +223,7 @@ class ExprFieldRegistry
223 { 223 {
224 $this->fields = array(); 224 $this->fields = array();
225 225
226 - $dir = opendir($this->path); 226 + $dir = opendir(SearchHelper::correctPath($this->path));
227 while (($file = readdir($dir)) !== false) 227 while (($file = readdir($dir)) !== false)
228 { 228 {
229 if (substr($file,-13) == 'Field.inc.php') 229 if (substr($file,-13) == 'Field.inc.php')
search2/search/search.inc.php
@@ -62,6 +62,18 @@ function search_alias_compare($a, $b) @@ -62,6 +62,18 @@ function search_alias_compare($a, $b)
62 62
63 class SearchHelper 63 class SearchHelper
64 { 64 {
  65 + public static function correctPath($path)
  66 + {
  67 + if (OS_WINDOWS)
  68 + {
  69 + return str_replace('/','\\', $path);
  70 + }
  71 + else
  72 + {
  73 + return str_replace('\\','/', $path);
  74 + }
  75 + }
  76 +
65 public static function checkOpenOfficeAvailablity() 77 public static function checkOpenOfficeAvailablity()
66 { 78 {
67 $config =& KTConfig::getSingleton(); 79 $config =& KTConfig::getSingleton();