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