Commit b6cd6dae87058f3049a5dcb44fc51be99da419d3
1 parent
f5b32869
KTS-2432
"Dynamic Condition Doesnt Work in 3.4.3" Fixed. On adding / editing a document it now checks if dynamic conditions exist and updates the permission object. Committed by: Megan Watson Reviewed by: Conrad Vermeulen git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8089 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
4 changed files
with
60 additions
and
30 deletions
lib/documentmanagement/documentutil.inc.php
| ... | ... | @@ -558,12 +558,12 @@ class KTDocumentUtil { |
| 558 | 558 | DBUtil::startTransaction(); |
| 559 | 559 | $oDocument =& KTDocumentUtil::_add($oFolder, $sFilename, $oUser, $aOptions); |
| 560 | 560 | |
| 561 | - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Document created'))); | |
| 561 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Document created'))); | |
| 562 | 562 | if (PEAR::isError($oDocument)) { |
| 563 | 563 | return $oDocument; |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Scanning file'))); | |
| 566 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Scanning file'))); | |
| 567 | 567 | $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); |
| 568 | 568 | $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'scan'); |
| 569 | 569 | $iTrigger = 0; |
| ... | ... | @@ -582,22 +582,8 @@ class KTDocumentUtil { |
| 582 | 582 | // NEW SEARCH |
| 583 | 583 | |
| 584 | 584 | Indexer::index($oDocument); |
| 585 | - /* | |
| 586 | - $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Transforming file'))); | |
| 587 | - $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); | |
| 588 | - $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform'); | |
| 589 | - foreach ($aTriggers as $aTrigger) { | |
| 590 | - $sTrigger = $aTrigger[0]; | |
| 591 | - if ($aTrigger[1]) { | |
| 592 | - require_once($aTrigger[1]); | |
| 593 | - } | |
| 594 | - $oTrigger = new $sTrigger; | |
| 595 | - $oTrigger->setDocument($oDocument); | |
| 596 | - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(sprintf(_kt(" (trigger %s)"), $sTrigger))); | |
| 597 | - $oTrigger->transform(); | |
| 598 | - }*/ | |
| 599 | 585 | |
| 600 | - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Creating transaction'))); | |
| 586 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Creating transaction'))); | |
| 601 | 587 | $aOptions = array('user' => $oUser); |
| 602 | 588 | //create the document transaction record |
| 603 | 589 | $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document created'), 'ktcore.transactions.create', $aOptions); |
| ... | ... | @@ -607,7 +593,7 @@ class KTDocumentUtil { |
| 607 | 593 | return $res; |
| 608 | 594 | } |
| 609 | 595 | |
| 610 | - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions'))); | |
| 596 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions'))); | |
| 611 | 597 | // fire subscription alerts for the checked in document |
| 612 | 598 | $oSubscriptionEvent = new SubscriptionEvent(); |
| 613 | 599 | $oFolder = Folder::get($oDocument->getFolderID()); |
| ... | ... | @@ -630,6 +616,20 @@ class KTDocumentUtil { |
| 630 | 616 | KTDocumentUtil::updateSearchableText($oDocument, true); |
| 631 | 617 | |
| 632 | 618 | DBUtil::commit(); |
| 619 | + | |
| 620 | + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Checking permissions...'))); | |
| 621 | + | |
| 622 | + // Check if there are any dynamic conditions / permissions that need to be updated on the document | |
| 623 | + // If there are dynamic conditions then update the permissions on the document | |
| 624 | + // The dynamic condition test fails unless the document exists in the DB therefore update permissions after committing the transaction. | |
| 625 | + include_once(KT_LIB_DIR.'/permissions/permissiondynamiccondition.inc.php'); | |
| 626 | + $iPermissionObjectId = $oFolder->getPermissionObjectID(); | |
| 627 | + $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId); | |
| 628 | + | |
| 629 | + if(!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)){ | |
| 630 | + $res = KTPermissionUtil::updatePermissionLookup($oDocument); | |
| 631 | + } | |
| 632 | + | |
| 633 | 633 | $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('All done...'))); |
| 634 | 634 | |
| 635 | 635 | return $oDocument; | ... | ... |
lib/permissions/permissiondynamiccondition.inc.php
| ... | ... | @@ -5,32 +5,32 @@ |
| 5 | 5 | * KnowledgeTree Open Source Edition |
| 6 | 6 | * Document Management Made Simple |
| 7 | 7 | * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited |
| 8 | - * | |
| 8 | + * | |
| 9 | 9 | * This program is free software; you can redistribute it and/or modify it under |
| 10 | 10 | * the terms of the GNU General Public License version 3 as published by the |
| 11 | 11 | * Free Software Foundation. |
| 12 | - * | |
| 12 | + * | |
| 13 | 13 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 14 | 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 15 | 15 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 16 | 16 | * details. |
| 17 | - * | |
| 17 | + * | |
| 18 | 18 | * You should have received a copy of the GNU General Public License |
| 19 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | - * | |
| 20 | + * | |
| 21 | 21 | * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, |
| 22 | 22 | * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. |
| 23 | - * | |
| 23 | + * | |
| 24 | 24 | * The interactive user interfaces in modified source and object code versions |
| 25 | 25 | * of this program must display Appropriate Legal Notices, as required under |
| 26 | 26 | * Section 5 of the GNU General Public License version 3. |
| 27 | - * | |
| 27 | + * | |
| 28 | 28 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 29 | 29 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 30 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 30 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the | |
| 31 | 31 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 32 | - * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | - * copyright notice. | |
| 32 | + * must display the words "Powered by KnowledgeTree" and retain the original | |
| 33 | + * copyright notice. | |
| 34 | 34 | * Contributor( s): ______________________________________ |
| 35 | 35 | * |
| 36 | 36 | */ |
| ... | ... | @@ -89,6 +89,15 @@ class KTPermissionDynamicCondition extends KTEntity { |
| 89 | 89 | )); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | + function &getByPermissionObjectId($iPermissionObjectId) { | |
| 93 | + return KTEntityUtil::getByDict('KTPermissionDynamicCondition', array( | |
| 94 | + 'permission_object_id' => $iPermissionObjectId, | |
| 95 | + ), array( | |
| 96 | + 'multi' => true, | |
| 97 | + )); | |
| 98 | + } | |
| 99 | + | |
| 100 | + | |
| 92 | 101 | function &getByPermissionObjectAndCondition($oPermissionObject, $oCondition) { |
| 93 | 102 | $iPermissionObjectId = KTUtil::getId($oPermissionObject); |
| 94 | 103 | $iConditionId = KTUtil::getId($oCondition); |
| ... | ... | @@ -142,7 +151,7 @@ class KTPermissionDynamicCondition extends KTEntity { |
| 142 | 151 | array($iConditionId), |
| 143 | 152 | ); |
| 144 | 153 | $aIds = DBUtil::getResultArrayKey($aQuery, 'id'); |
| 145 | - | |
| 154 | + | |
| 146 | 155 | |
| 147 | 156 | $sParam = DBUtil::paramArray($aIds); |
| 148 | 157 | ... | ... |
lib/permissions/permissionutil.inc.php
| ... | ... | @@ -431,7 +431,7 @@ class KTPermissionUtil { |
| 431 | 431 | */ |
| 432 | 432 | |
| 433 | 433 | |
| 434 | - if (is_null($oPermLookup)) { | |
| 434 | + //if (is_null($oPermLookup)) { | |
| 435 | 435 | $aMapPermDesc = array(); |
| 436 | 436 | foreach ($aMapPermAllowed as $iPermissionId => $aAllowed) { |
| 437 | 437 | $oLookupPD = KTPermissionUtil::getOrCreateDescriptor($aAllowed); |
| ... | ... | @@ -439,7 +439,7 @@ class KTPermissionUtil { |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | $oPermLookup = KTPermissionLookupAssignment::findOrCreateLookupByPermissionDescriptorMap($aMapPermDesc); |
| 442 | - } | |
| 442 | + //} | |
| 443 | 443 | |
| 444 | 444 | $oFolderOrDocument->setPermissionLookupID($oPermLookup->getID()); |
| 445 | 445 | $oFolderOrDocument->update(); | ... | ... |
plugins/ktcore/document/edit.php
| ... | ... | @@ -49,6 +49,7 @@ require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php'); |
| 49 | 49 | require_once(KT_LIB_DIR . "/widgets/forms.inc.php"); |
| 50 | 50 | require_once(KT_LIB_DIR . "/metadata/fieldsetregistry.inc.php"); |
| 51 | 51 | require_once(KT_LIB_DIR . "/util/sanitize.inc"); |
| 52 | +require_once(KT_LIB_DIR.'/permissions/permissiondynamiccondition.inc.php'); | |
| 52 | 53 | |
| 53 | 54 | // {{{ KTDocumentEditAction |
| 54 | 55 | class KTDocumentEditAction extends KTDocumentAction { |
| ... | ... | @@ -233,6 +234,16 @@ class KTDocumentEditAction extends KTDocumentAction { |
| 233 | 234 | $oDocumentTransaction = & new DocumentTransaction($this->oDocument, _kt('Document metadata updated'), 'ktcore.transactions.update'); |
| 234 | 235 | $oDocumentTransaction->create(); |
| 235 | 236 | |
| 237 | + // Check if there are any dynamic conditions / permissions that need to be updated on the document | |
| 238 | + // If there are dynamic conditions then update the permissions on the document | |
| 239 | + // The dynamic condition test fails unless the changes exists in the DB therefore update permissions after committing the transaction. | |
| 240 | + $iPermissionObjectId = $this->oDocument->getPermissionObjectID(); | |
| 241 | + $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId); | |
| 242 | + | |
| 243 | + if(!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)){ | |
| 244 | + $res = KTPermissionUtil::updatePermissionLookup($this->oDocument); | |
| 245 | + } | |
| 246 | + | |
| 236 | 247 | redirect(KTBrowseUtil::getUrlForDocument($this->oDocument->getId())); |
| 237 | 248 | exit(0); |
| 238 | 249 | } |
| ... | ... | @@ -369,6 +380,16 @@ class KTDocumentEditAction extends KTDocumentAction { |
| 369 | 380 | $ret = $oTrigger->postValidate(); |
| 370 | 381 | } |
| 371 | 382 | |
| 383 | + // Check if there are any dynamic conditions / permissions that need to be updated on the document | |
| 384 | + // If there are dynamic conditions then update the permissions on the document | |
| 385 | + // The dynamic condition test fails unless the changes exists in the DB therefore update permissions after committing the transaction. | |
| 386 | + $iPermissionObjectId = $this->oDocument->getPermissionObjectID(); | |
| 387 | + $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId); | |
| 388 | + | |
| 389 | + if(!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)){ | |
| 390 | + $res = KTPermissionUtil::updatePermissionLookup($this->oDocument); | |
| 391 | + } | |
| 392 | + | |
| 372 | 393 | $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName())); |
| 373 | 394 | } |
| 374 | 395 | } | ... | ... |