Commit b6cd6dae87058f3049a5dcb44fc51be99da419d3

Authored by Megan Watson
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
lib/documentmanagement/documentutil.inc.php
@@ -558,12 +558,12 @@ class KTDocumentUtil { @@ -558,12 +558,12 @@ class KTDocumentUtil {
558 DBUtil::startTransaction(); 558 DBUtil::startTransaction();
559 $oDocument =& KTDocumentUtil::_add($oFolder, $sFilename, $oUser, $aOptions); 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 if (PEAR::isError($oDocument)) { 562 if (PEAR::isError($oDocument)) {
563 return $oDocument; 563 return $oDocument;
564 } 564 }
565 565
566 - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Scanning file'))); 566 + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Scanning file')));
567 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); 567 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
568 $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'scan'); 568 $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'scan');
569 $iTrigger = 0; 569 $iTrigger = 0;
@@ -582,22 +582,8 @@ class KTDocumentUtil { @@ -582,22 +582,8 @@ class KTDocumentUtil {
582 // NEW SEARCH 582 // NEW SEARCH
583 583
584 Indexer::index($oDocument); 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 $aOptions = array('user' => $oUser); 587 $aOptions = array('user' => $oUser);
602 //create the document transaction record 588 //create the document transaction record
603 $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document created'), 'ktcore.transactions.create', $aOptions); 589 $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document created'), 'ktcore.transactions.create', $aOptions);
@@ -607,7 +593,7 @@ class KTDocumentUtil { @@ -607,7 +593,7 @@ class KTDocumentUtil {
607 return $res; 593 return $res;
608 } 594 }
609 595
610 - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions'))); 596 + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions')));
611 // fire subscription alerts for the checked in document 597 // fire subscription alerts for the checked in document
612 $oSubscriptionEvent = new SubscriptionEvent(); 598 $oSubscriptionEvent = new SubscriptionEvent();
613 $oFolder = Folder::get($oDocument->getFolderID()); 599 $oFolder = Folder::get($oDocument->getFolderID());
@@ -630,6 +616,20 @@ class KTDocumentUtil { @@ -630,6 +616,20 @@ class KTDocumentUtil {
630 KTDocumentUtil::updateSearchableText($oDocument, true); 616 KTDocumentUtil::updateSearchableText($oDocument, true);
631 617
632 DBUtil::commit(); 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 $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('All done...'))); 633 $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('All done...')));
634 634
635 return $oDocument; 635 return $oDocument;
lib/permissions/permissiondynamiccondition.inc.php
@@ -5,32 +5,32 @@ @@ -5,32 +5,32 @@
5 * KnowledgeTree Open Source Edition 5 * KnowledgeTree Open Source Edition
6 * Document Management Made Simple 6 * Document Management Made Simple
7 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited 7 * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited
8 - * 8 + *
9 * This program is free software; you can redistribute it and/or modify it under 9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 3 as published by the 10 * the terms of the GNU General Public License version 3 as published by the
11 * Free Software Foundation. 11 * Free Software Foundation.
12 - * 12 + *
13 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details. 16 * details.
17 - * 17 + *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 - * 20 + *
21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, 21 * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place,
22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. 22 * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com.
23 - * 23 + *
24 * The interactive user interfaces in modified source and object code versions 24 * The interactive user interfaces in modified source and object code versions
25 * of this program must display Appropriate Legal Notices, as required under 25 * of this program must display Appropriate Legal Notices, as required under
26 * Section 5 of the GNU General Public License version 3. 26 * Section 5 of the GNU General Public License version 3.
27 - * 27 + *
28 * In accordance with Section 7(b) of the GNU General Public License version 3, 28 * In accordance with Section 7(b) of the GNU General Public License version 3,
29 * these Appropriate Legal Notices must retain the display of the "Powered by 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 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices 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 * Contributor( s): ______________________________________ 34 * Contributor( s): ______________________________________
35 * 35 *
36 */ 36 */
@@ -89,6 +89,15 @@ class KTPermissionDynamicCondition extends KTEntity { @@ -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 function &getByPermissionObjectAndCondition($oPermissionObject, $oCondition) { 101 function &getByPermissionObjectAndCondition($oPermissionObject, $oCondition) {
93 $iPermissionObjectId = KTUtil::getId($oPermissionObject); 102 $iPermissionObjectId = KTUtil::getId($oPermissionObject);
94 $iConditionId = KTUtil::getId($oCondition); 103 $iConditionId = KTUtil::getId($oCondition);
@@ -142,7 +151,7 @@ class KTPermissionDynamicCondition extends KTEntity { @@ -142,7 +151,7 @@ class KTPermissionDynamicCondition extends KTEntity {
142 array($iConditionId), 151 array($iConditionId),
143 ); 152 );
144 $aIds = DBUtil::getResultArrayKey($aQuery, 'id'); 153 $aIds = DBUtil::getResultArrayKey($aQuery, 'id');
145 - 154 +
146 155
147 $sParam = DBUtil::paramArray($aIds); 156 $sParam = DBUtil::paramArray($aIds);
148 157
lib/permissions/permissionutil.inc.php
@@ -431,7 +431,7 @@ class KTPermissionUtil { @@ -431,7 +431,7 @@ class KTPermissionUtil {
431 */ 431 */
432 432
433 433
434 - if (is_null($oPermLookup)) { 434 + //if (is_null($oPermLookup)) {
435 $aMapPermDesc = array(); 435 $aMapPermDesc = array();
436 foreach ($aMapPermAllowed as $iPermissionId => $aAllowed) { 436 foreach ($aMapPermAllowed as $iPermissionId => $aAllowed) {
437 $oLookupPD = KTPermissionUtil::getOrCreateDescriptor($aAllowed); 437 $oLookupPD = KTPermissionUtil::getOrCreateDescriptor($aAllowed);
@@ -439,7 +439,7 @@ class KTPermissionUtil { @@ -439,7 +439,7 @@ class KTPermissionUtil {
439 } 439 }
440 440
441 $oPermLookup = KTPermissionLookupAssignment::findOrCreateLookupByPermissionDescriptorMap($aMapPermDesc); 441 $oPermLookup = KTPermissionLookupAssignment::findOrCreateLookupByPermissionDescriptorMap($aMapPermDesc);
442 - } 442 + //}
443 443
444 $oFolderOrDocument->setPermissionLookupID($oPermLookup->getID()); 444 $oFolderOrDocument->setPermissionLookupID($oPermLookup->getID());
445 $oFolderOrDocument->update(); 445 $oFolderOrDocument->update();
plugins/ktcore/document/edit.php
@@ -49,6 +49,7 @@ require_once(KT_LIB_DIR . &#39;/permissions/permissionutil.inc.php&#39;); @@ -49,6 +49,7 @@ require_once(KT_LIB_DIR . &#39;/permissions/permissionutil.inc.php&#39;);
49 require_once(KT_LIB_DIR . "/widgets/forms.inc.php"); 49 require_once(KT_LIB_DIR . "/widgets/forms.inc.php");
50 require_once(KT_LIB_DIR . "/metadata/fieldsetregistry.inc.php"); 50 require_once(KT_LIB_DIR . "/metadata/fieldsetregistry.inc.php");
51 require_once(KT_LIB_DIR . "/util/sanitize.inc"); 51 require_once(KT_LIB_DIR . "/util/sanitize.inc");
  52 +require_once(KT_LIB_DIR.'/permissions/permissiondynamiccondition.inc.php');
52 53
53 // {{{ KTDocumentEditAction 54 // {{{ KTDocumentEditAction
54 class KTDocumentEditAction extends KTDocumentAction { 55 class KTDocumentEditAction extends KTDocumentAction {
@@ -233,6 +234,16 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -233,6 +234,16 @@ class KTDocumentEditAction extends KTDocumentAction {
233 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, _kt('Document metadata updated'), 'ktcore.transactions.update'); 234 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, _kt('Document metadata updated'), 'ktcore.transactions.update');
234 $oDocumentTransaction->create(); 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 redirect(KTBrowseUtil::getUrlForDocument($this->oDocument->getId())); 247 redirect(KTBrowseUtil::getUrlForDocument($this->oDocument->getId()));
237 exit(0); 248 exit(0);
238 } 249 }
@@ -369,6 +380,16 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -369,6 +380,16 @@ class KTDocumentEditAction extends KTDocumentAction {
369 $ret = $oTrigger->postValidate(); 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 $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName())); 393 $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName()));
373 } 394 }
374 } 395 }