Commit 36f339993dfd6fa2d5dca238030108dc95a38dd0
1 parent
a9e0e3d8
Type: functionality change
Description: Passing through document object instead of document id to permissions checks to avoid redundant DB accesses to intsantiate db model objects git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2879 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
12 changed files
with
36 additions
and
25 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentLinkBL.php
| @@ -37,10 +37,12 @@ if (checkSession()) { | @@ -37,10 +37,12 @@ if (checkSession()) { | ||
| 37 | require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | 37 | require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); |
| 38 | require_once("$default->fileSystemRoot/lib/security/Permission.inc"); | 38 | require_once("$default->fileSystemRoot/lib/security/Permission.inc"); |
| 39 | require_once("$default->fileSystemRoot/presentation/Html.inc"); | 39 | require_once("$default->fileSystemRoot/presentation/Html.inc"); |
| 40 | + require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | ||
| 40 | require_once("documentUI.inc"); | 41 | require_once("documentUI.inc"); |
| 41 | require_once("addDocumentLinkUI.inc"); | 42 | require_once("addDocumentLinkUI.inc"); |
| 42 | 43 | ||
| 43 | - if (Permission::userHasDocumentWritePermission($fDocumentID)) { | 44 | + $oDocument = Document::get($fDocumentID); |
| 45 | + if (Permission::userHasDocumentWritePermission($oDocument)) { | ||
| 44 | //user has permission to link this document to another | 46 | //user has permission to link this document to another |
| 45 | if (isset($fForStore)) { | 47 | if (isset($fForStore)) { |
| 46 | //create a new document link | 48 | //create a new document link |
presentation/lookAndFeel/knowledgeTree/documentmanagement/checkInDocumentBL.php
| @@ -60,13 +60,13 @@ if (checkSession()) { | @@ -60,13 +60,13 @@ if (checkSession()) { | ||
| 60 | require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); | 60 | require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); |
| 61 | 61 | ||
| 62 | $oPatternCustom = & new PatternCustom(); | 62 | $oPatternCustom = & new PatternCustom(); |
| 63 | - | 63 | + |
| 64 | if (isset($fDocumentID)) { | 64 | if (isset($fDocumentID)) { |
| 65 | // instantiate the document | 65 | // instantiate the document |
| 66 | $oDocument = & Document::get($fDocumentID); | 66 | $oDocument = & Document::get($fDocumentID); |
| 67 | if ($oDocument) { | 67 | if ($oDocument) { |
| 68 | // user has permission to check the document in | 68 | // user has permission to check the document in |
| 69 | - if (Permission::userHasDocumentWritePermission($fDocumentID)) { | 69 | + if (Permission::userHasDocumentWritePermission($oDocument)) { |
| 70 | // and the document is checked out | 70 | // and the document is checked out |
| 71 | if ($oDocument->getIsCheckedOut()) { | 71 | if ($oDocument->getIsCheckedOut()) { |
| 72 | // by you | 72 | // by you |
presentation/lookAndFeel/knowledgeTree/documentmanagement/checkOutDocumentBL.php
| @@ -61,13 +61,13 @@ if (checkSession()) { | @@ -61,13 +61,13 @@ if (checkSession()) { | ||
| 61 | require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); | 61 | require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); |
| 62 | 62 | ||
| 63 | $oPatternCustom = & new PatternCustom(); | 63 | $oPatternCustom = & new PatternCustom(); |
| 64 | - | 64 | + |
| 65 | if (isset($fDocumentID)) { | 65 | if (isset($fDocumentID)) { |
| 66 | // instantiate the document | 66 | // instantiate the document |
| 67 | $oDocument = & Document::get($fDocumentID); | 67 | $oDocument = & Document::get($fDocumentID); |
| 68 | if ($oDocument) { | 68 | if ($oDocument) { |
| 69 | // user has permission to check the document out | 69 | // user has permission to check the document out |
| 70 | - if (Permission::userHasDocumentWritePermission($fDocumentID)) { | 70 | + if (Permission::userHasDocumentWritePermission($oDocument)) { |
| 71 | // and its not checked out already | 71 | // and its not checked out already |
| 72 | if (!$oDocument->getIsCheckedOut()) { | 72 | if (!$oDocument->getIsCheckedOut()) { |
| 73 | // if we're ready to perform the updates | 73 | // if we're ready to perform the updates |
presentation/lookAndFeel/knowledgeTree/documentmanagement/collaborationBL.php
| @@ -56,7 +56,8 @@ if (checkSession()) { | @@ -56,7 +56,8 @@ if (checkSession()) { | ||
| 56 | //if the required form variabled are set | 56 | //if the required form variabled are set |
| 57 | if (isset($fFolderCollaborationID) && isset($fDocumentID)) { | 57 | if (isset($fFolderCollaborationID) && isset($fDocumentID)) { |
| 58 | //if the user has write permission for the document | 58 | //if the user has write permission for the document |
| 59 | - if (Permission::userHasDocumentWritePermission($fDocumentID)) { | 59 | + $oDocument = Document::get($fDocumentID); |
| 60 | + if (Permission::userHasDocumentWritePermission($oDocument)) { | ||
| 60 | if ($fIsActive) { | 61 | if ($fIsActive) { |
| 61 | //if the document collaboration step the user is attempting to edit is underway, you may not edit it | 62 | //if the document collaboration step the user is attempting to edit is underway, you may not edit it |
| 62 | //so bounce the user back to the document view page and display an error message | 63 | //so bounce the user back to the document view page and display an error message |
presentation/lookAndFeel/knowledgeTree/documentmanagement/deleteDocumentBL.php
| @@ -43,8 +43,10 @@ require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/fo | @@ -43,8 +43,10 @@ require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/fo | ||
| 43 | require_once("deleteDocumentUI.inc"); | 43 | require_once("deleteDocumentUI.inc"); |
| 44 | 44 | ||
| 45 | if (checkSession()) { | 45 | if (checkSession()) { |
| 46 | + | ||
| 46 | if (isset($fDocumentID)) { | 47 | if (isset($fDocumentID)) { |
| 47 | - if (Permission::userHasDocumentWritePermission($fDocumentID)) { | 48 | + $oDocument = Document::get($fDocumentID); |
| 49 | + if (Permission::userHasDocumentWritePermission($oDocument)) { | ||
| 48 | // check if there is collaboration for this document | 50 | // check if there is collaboration for this document |
| 49 | $aFolderUserRoles = FolderUserRole::getList("document_id = $fDocumentID"); | 51 | $aFolderUserRoles = FolderUserRole::getList("document_id = $fDocumentID"); |
| 50 | // check if any of them are active | 52 | // check if any of them are active |
presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyBL.php
| @@ -50,9 +50,9 @@ if (checkSession()) { | @@ -50,9 +50,9 @@ if (checkSession()) { | ||
| 50 | require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); | 50 | require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); |
| 51 | require_once("$default->fileSystemRoot/presentation/Html.inc"); | 51 | require_once("$default->fileSystemRoot/presentation/Html.inc"); |
| 52 | 52 | ||
| 53 | - if (Permission::userHasDocumentWritePermission($fDocumentID)) { | 53 | + $oDocument = & Document::get($fDocumentID); |
| 54 | + if (Permission::userHasDocumentWritePermission($oDocument)) { | ||
| 54 | //if the user has write permission | 55 | //if the user has write permission |
| 55 | - $oDocument = & Document::get($fDocumentID); | ||
| 56 | if (isset($fForUpdate)) { | 56 | if (isset($fForUpdate)) { |
| 57 | //if the user is updating the values | 57 | //if the user is updating the values |
| 58 | $oDocument->setName($fDocumentName); | 58 | $oDocument->setName($fDocumentName); |
presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyGenericMetaDataBL.php
| @@ -42,8 +42,10 @@ if (checkSession()) { | @@ -42,8 +42,10 @@ if (checkSession()) { | ||
| 42 | require_once("documentUI.inc"); | 42 | require_once("documentUI.inc"); |
| 43 | require_once("modifyGenericMetaDataUI.inc"); | 43 | require_once("modifyGenericMetaDataUI.inc"); |
| 44 | 44 | ||
| 45 | - if (Permission::userHasDocumentWritePermission($fDocumentID)) { | ||
| 46 | - $oDocument = Document::get($fDocumentID); | 45 | + |
| 46 | + $oDocument = Document::get($fDocumentID); | ||
| 47 | + if (Permission::userHasDocumentWritePermission($oDocument)) { | ||
| 48 | + | ||
| 47 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | 49 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); |
| 48 | $oPatternCustom = & new PatternCustom(); | 50 | $oPatternCustom = & new PatternCustom(); |
| 49 | $oPatternCustom->setHtml(getPage($fDocumentID, $oDocument->getDocumentTypeID(), $fFirstEdit)); | 51 | $oPatternCustom->setHtml(getPage($fDocumentID, $oDocument->getDocumentTypeID(), $fFirstEdit)); |
presentation/lookAndFeel/knowledgeTree/documentmanagement/modifySpecificMetaDataBL.php
| @@ -38,8 +38,9 @@ if (checkSession()) { | @@ -38,8 +38,9 @@ if (checkSession()) { | ||
| 38 | require_once("documentUI.inc"); | 38 | require_once("documentUI.inc"); |
| 39 | require_once("modifySpecificMetaDataUI.inc"); | 39 | require_once("modifySpecificMetaDataUI.inc"); |
| 40 | 40 | ||
| 41 | - if (Permission::userHasDocumentWritePermission($fDocumentID)) { | ||
| 42 | - $oDocument = Document::get($fDocumentID); | 41 | + $oDocument = Document::get($fDocumentID); |
| 42 | + if (Permission::userHasDocumentWritePermission($oDocument)) { | ||
| 43 | + | ||
| 43 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | 44 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); |
| 44 | $oPatternCustom = & new PatternCustom(); | 45 | $oPatternCustom = & new PatternCustom(); |
| 45 | $oPatternCustom->setHtml(getPage($fDocumentID, $oDocument->getDocumentTypeID(), $fFirstEdit)); | 46 | $oPatternCustom->setHtml(getPage($fDocumentID, $oDocument->getDocumentTypeID(), $fFirstEdit)); |
presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentBL.php
| @@ -54,7 +54,7 @@ if (checkSession()) { | @@ -54,7 +54,7 @@ if (checkSession()) { | ||
| 54 | $oDocument = & Document::get($fDocumentID); | 54 | $oDocument = & Document::get($fDocumentID); |
| 55 | $oFolder = & Folder::get($fFolderID); | 55 | $oFolder = & Folder::get($fFolderID); |
| 56 | $iOldFolderID = $oDocument->getFolderID(); | 56 | $iOldFolderID = $oDocument->getFolderID(); |
| 57 | - if (Permission::userHasDocumentWritePermission($fDocumentID) && Permission::userHasFolderWritePermission($fFolderID)) { | 57 | + if (Permission::userHasDocumentWritePermission($oDocument) && Permission::userHasFolderWritePermission($oFolder)) { |
| 58 | //if the user has both document and folder write permissions | 58 | //if the user has both document and folder write permissions |
| 59 | //get the old document path | 59 | //get the old document path |
| 60 | $sOldDocumentFileSystemPath = Folder::getFolderPath($iOldFolderID) . $oDocument->getFileName(); | 60 | $sOldDocumentFileSystemPath = Folder::getFolderPath($iOldFolderID) . $oDocument->getFileName(); |
presentation/lookAndFeel/knowledgeTree/documentmanagement/removeDocumentLinkBL.php
| @@ -37,10 +37,12 @@ if (checkSession()) { | @@ -37,10 +37,12 @@ if (checkSession()) { | ||
| 37 | require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | 37 | require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); |
| 38 | require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentLink.inc"); | 38 | require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentLink.inc"); |
| 39 | require_once("$default->fileSystemRoot/presentation/Html.inc"); | 39 | require_once("$default->fileSystemRoot/presentation/Html.inc"); |
| 40 | + require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | ||
| 40 | require_once("documentUI.inc"); | 41 | require_once("documentUI.inc"); |
| 41 | require_once("removeDocumentLinkUI.inc"); | 42 | require_once("removeDocumentLinkUI.inc"); |
| 42 | 43 | ||
| 43 | - if (Permission::userHasDocumentWritePermission($fParentDocumentID)) { | 44 | + $oDocument = Document::get($fDocumentID); |
| 45 | + if (Permission::userHasDocumentWritePermission($oDocument)) { | ||
| 44 | if (isset($fForDelete)) { | 46 | if (isset($fForDelete)) { |
| 45 | //deleting a document link | 47 | //deleting a document link |
| 46 | $oDocumentLink = DocumentLink::get($fDocumentLinkID); | 48 | $oDocumentLink = DocumentLink::get($fDocumentLinkID); |
presentation/lookAndFeel/knowledgeTree/documentmanagement/viewBL.php
| @@ -222,7 +222,7 @@ if (checkSession()) { | @@ -222,7 +222,7 @@ if (checkSession()) { | ||
| 222 | } | 222 | } |
| 223 | $main->setDHTMLScrolling(false); | 223 | $main->setDHTMLScrolling(false); |
| 224 | 224 | ||
| 225 | - } else if (Permission::userHasDocumentWritePermission($oDocument) || Permission::userHasDocumentReadPermission($fDocumentID)) { | 225 | + } else if (Permission::userHasDocumentWritePermission($oDocument) || Permission::userHasDocumentReadPermission($oDocument)) { |
| 226 | 226 | ||
| 227 | // check subscription flag | 227 | // check subscription flag |
| 228 | // ?? | 228 | // ?? |
| @@ -238,7 +238,7 @@ if (checkSession()) { | @@ -238,7 +238,7 @@ if (checkSession()) { | ||
| 238 | if ($oDocument->isLive()) { | 238 | if ($oDocument->isLive()) { |
| 239 | if (Permission::userHasDocumentWritePermission($oDocument)) { | 239 | if (Permission::userHasDocumentWritePermission($oDocument)) { |
| 240 | $oPatternCustom->setHtml(getPage($oDocument, true)); | 240 | $oPatternCustom->setHtml(getPage($oDocument, true)); |
| 241 | - } else if (Permission::userHasDocumentReadPermission($fDocumentID)) { | 241 | + } else if (Permission::userHasDocumentReadPermission($oDocument)) { |
| 242 | $oPatternCustom->setHtml(getPage($oDocument, false)); | 242 | $oPatternCustom->setHtml(getPage($oDocument, false)); |
| 243 | } | 243 | } |
| 244 | $main->setDHTMLScrolling(false); | 244 | $main->setDHTMLScrolling(false); |
tests/documentmanagement/viewBL.php
| @@ -59,24 +59,25 @@ require_once("$default->fileSystemRoot/presentation/Html.inc"); | @@ -59,24 +59,25 @@ require_once("$default->fileSystemRoot/presentation/Html.inc"); | ||
| 59 | 59 | ||
| 60 | if (checkSession()) { | 60 | if (checkSession()) { |
| 61 | if (isset($fDocumentID)) { | 61 | if (isset($fDocumentID)) { |
| 62 | - if (isset($fCollaborationEdit) && Permission::userHasDocumentWritePermission($fDocumentID)) { | 62 | + $oDocument = & Document::get($fDocumentID); |
| 63 | + if (isset($fCollaborationEdit) && Permission::userHasDocumentWritePermission($oDocument)) { | ||
| 63 | //return value from collaborationBL.php. User attempted to edt | 64 | //return value from collaborationBL.php. User attempted to edt |
| 64 | //a step in the document collaboration process that is currently being | 65 | //a step in the document collaboration process that is currently being |
| 65 | //executed | 66 | //executed |
| 66 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | 67 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); |
| 67 | 68 | ||
| 68 | - $oDocument = & Document::get($fDocumentID); | 69 | + |
| 69 | $oPatternCustom = & new PatternCustom(); | 70 | $oPatternCustom = & new PatternCustom(); |
| 70 | $oPatternCustom->setHtml(getEditPage($oDocument)); | 71 | $oPatternCustom->setHtml(getEditPage($oDocument)); |
| 71 | $main->setCentralPayload($oPatternCustom); | 72 | $main->setCentralPayload($oPatternCustom); |
| 72 | $main->setErrorMessage("You cannot edit a document collaboration step that is completed or currently underway"); | 73 | $main->setErrorMessage("You cannot edit a document collaboration step that is completed or currently underway"); |
| 73 | $main->setFormAction("$default->rootUrl/control.php?action=modifyDocument&fDocumentID=" . $oDocument->getID()); | 74 | $main->setFormAction("$default->rootUrl/control.php?action=modifyDocument&fDocumentID=" . $oDocument->getID()); |
| 74 | $main->render(); | 75 | $main->render(); |
| 75 | - } else if (isset($fForInlineView) && Permission::userHasDocumentReadPermission($fDocumentID)) { | 76 | + } else if (isset($fForInlineView) && Permission::userHasDocumentReadPermission($oDocument)) { |
| 76 | $oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Inline view", VIEW); | 77 | $oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Inline view", VIEW); |
| 77 | $oDocumentTransaction->create(); | 78 | $oDocumentTransaction->create(); |
| 78 | PhysicalDocumentManager::inlineViewPhysicalDocument($fDocumentID); | 79 | PhysicalDocumentManager::inlineViewPhysicalDocument($fDocumentID); |
| 79 | - } else if (isset($fForDownload) && Permission::userHasDocumentReadPermission($fDocumentID)) { | 80 | + } else if (isset($fForDownload) && Permission::userHasDocumentReadPermission($oDocument)) { |
| 80 | //if the user has document read permission, perform the download | 81 | //if the user has document read permission, perform the download |
| 81 | if (isset($fVersion)) { | 82 | if (isset($fVersion)) { |
| 82 | // we're downloading an old version of the document | 83 | // we're downloading an old version of the document |
| @@ -89,7 +90,7 @@ if (checkSession()) { | @@ -89,7 +90,7 @@ if (checkSession()) { | ||
| 89 | $oDocumentTransaction->create(); | 90 | $oDocumentTransaction->create(); |
| 90 | PhysicalDocumentManager::downloadPhysicalDocument($fDocumentID); | 91 | PhysicalDocumentManager::downloadPhysicalDocument($fDocumentID); |
| 91 | } | 92 | } |
| 92 | - } else if (isset($fBeginCollaboration) && Permission::userHasDocumentWritePermission($fDocumentID)) { | 93 | + } else if (isset($fBeginCollaboration) && Permission::userHasDocumentWritePermission($oDocument)) { |
| 93 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | 94 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); |
| 94 | //begin the collaboration process | 95 | //begin the collaboration process |
| 95 | //first ensure that all steps in the collaboration process are assigned | 96 | //first ensure that all steps in the collaboration process are assigned |
| @@ -209,7 +210,7 @@ if (checkSession()) { | @@ -209,7 +210,7 @@ if (checkSession()) { | ||
| 209 | $main->render(); | 210 | $main->render(); |
| 210 | } | 211 | } |
| 211 | 212 | ||
| 212 | - } else if (Permission::userHasDocumentWritePermission($fDocumentID) || Permission::userHasDocumentReadPermission($fDocumentID)) { | 213 | + } else if (Permission::userHasDocumentWritePermission($oDocument) || Permission::userHasDocumentReadPermission($oDocument)) { |
| 213 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | 214 | require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); |
| 214 | require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); | 215 | require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); |
| 215 | 216 | ||
| @@ -227,9 +228,9 @@ if (checkSession()) { | @@ -227,9 +228,9 @@ if (checkSession()) { | ||
| 227 | 228 | ||
| 228 | $oPatternCustom = & new PatternCustom(); | 229 | $oPatternCustom = & new PatternCustom(); |
| 229 | if ($oDocument->isLive()) { | 230 | if ($oDocument->isLive()) { |
| 230 | - if (Permission::userHasDocumentWritePermission($fDocumentID)) { | 231 | + if (Permission::userHasDocumentWritePermission($oDocument)) { |
| 231 | $oPatternCustom->setHtml(getPage($oDocument, true)); | 232 | $oPatternCustom->setHtml(getPage($oDocument, true)); |
| 232 | - } else if (Permission::userHasDocumentReadPermission($fDocumentID)) { | 233 | + } else if (Permission::userHasDocumentReadPermission($oDocument)) { |
| 233 | $oPatternCustom->setHtml(getPage($oDocument, false)); | 234 | $oPatternCustom->setHtml(getPage($oDocument, false)); |
| 234 | } | 235 | } |
| 235 | } else if ($oDocument->isArchived()) { | 236 | } else if ($oDocument->isArchived()) { |