diff --git a/lib/documentmanagement/documentutil.inc.php b/lib/documentmanagement/documentutil.inc.php index f00dd9a..b4c91f4 100644 --- a/lib/documentmanagement/documentutil.inc.php +++ b/lib/documentmanagement/documentutil.inc.php @@ -558,12 +558,12 @@ class KTDocumentUtil { DBUtil::startTransaction(); $oDocument =& KTDocumentUtil::_add($oFolder, $sFilename, $oUser, $aOptions); - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Document created'))); + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Document created'))); if (PEAR::isError($oDocument)) { return $oDocument; } - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Scanning file'))); + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Scanning file'))); $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'scan'); $iTrigger = 0; @@ -582,22 +582,8 @@ class KTDocumentUtil { // NEW SEARCH Indexer::index($oDocument); - /* - $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Transforming file'))); - $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); - $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform'); - foreach ($aTriggers as $aTrigger) { - $sTrigger = $aTrigger[0]; - if ($aTrigger[1]) { - require_once($aTrigger[1]); - } - $oTrigger = new $sTrigger; - $oTrigger->setDocument($oDocument); - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(sprintf(_kt(" (trigger %s)"), $sTrigger))); - $oTrigger->transform(); - }*/ - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Creating transaction'))); + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Creating transaction'))); $aOptions = array('user' => $oUser); //create the document transaction record $oDocumentTransaction = new DocumentTransaction($oDocument, _kt('Document created'), 'ktcore.transactions.create', $aOptions); @@ -607,7 +593,7 @@ class KTDocumentUtil { return $res; } - // $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions'))); + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Sending subscriptions'))); // fire subscription alerts for the checked in document $oSubscriptionEvent = new SubscriptionEvent(); $oFolder = Folder::get($oDocument->getFolderID()); @@ -630,6 +616,20 @@ class KTDocumentUtil { KTDocumentUtil::updateSearchableText($oDocument, true); DBUtil::commit(); + + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Checking permissions...'))); + + // Check if there are any dynamic conditions / permissions that need to be updated on the document + // If there are dynamic conditions then update the permissions on the document + // The dynamic condition test fails unless the document exists in the DB therefore update permissions after committing the transaction. + include_once(KT_LIB_DIR.'/permissions/permissiondynamiccondition.inc.php'); + $iPermissionObjectId = $oFolder->getPermissionObjectID(); + $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId); + + if(!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)){ + $res = KTPermissionUtil::updatePermissionLookup($oDocument); + } + $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('All done...'))); return $oDocument; diff --git a/lib/permissions/permissiondynamiccondition.inc.php b/lib/permissions/permissiondynamiccondition.inc.php index 4b37267..0329612 100644 --- a/lib/permissions/permissiondynamiccondition.inc.php +++ b/lib/permissions/permissiondynamiccondition.inc.php @@ -5,32 +5,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ @@ -89,6 +89,15 @@ class KTPermissionDynamicCondition extends KTEntity { )); } + function &getByPermissionObjectId($iPermissionObjectId) { + return KTEntityUtil::getByDict('KTPermissionDynamicCondition', array( + 'permission_object_id' => $iPermissionObjectId, + ), array( + 'multi' => true, + )); + } + + function &getByPermissionObjectAndCondition($oPermissionObject, $oCondition) { $iPermissionObjectId = KTUtil::getId($oPermissionObject); $iConditionId = KTUtil::getId($oCondition); @@ -142,7 +151,7 @@ class KTPermissionDynamicCondition extends KTEntity { array($iConditionId), ); $aIds = DBUtil::getResultArrayKey($aQuery, 'id'); - + $sParam = DBUtil::paramArray($aIds); diff --git a/lib/permissions/permissionutil.inc.php b/lib/permissions/permissionutil.inc.php index f37c2cc..01e8f39 100644 --- a/lib/permissions/permissionutil.inc.php +++ b/lib/permissions/permissionutil.inc.php @@ -431,7 +431,7 @@ class KTPermissionUtil { */ - if (is_null($oPermLookup)) { + //if (is_null($oPermLookup)) { $aMapPermDesc = array(); foreach ($aMapPermAllowed as $iPermissionId => $aAllowed) { $oLookupPD = KTPermissionUtil::getOrCreateDescriptor($aAllowed); @@ -439,7 +439,7 @@ class KTPermissionUtil { } $oPermLookup = KTPermissionLookupAssignment::findOrCreateLookupByPermissionDescriptorMap($aMapPermDesc); - } + //} $oFolderOrDocument->setPermissionLookupID($oPermLookup->getID()); $oFolderOrDocument->update(); diff --git a/plugins/ktcore/document/edit.php b/plugins/ktcore/document/edit.php index af0cdc8..f466b02 100644 --- a/plugins/ktcore/document/edit.php +++ b/plugins/ktcore/document/edit.php @@ -49,6 +49,7 @@ require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php'); require_once(KT_LIB_DIR . "/widgets/forms.inc.php"); require_once(KT_LIB_DIR . "/metadata/fieldsetregistry.inc.php"); require_once(KT_LIB_DIR . "/util/sanitize.inc"); +require_once(KT_LIB_DIR.'/permissions/permissiondynamiccondition.inc.php'); // {{{ KTDocumentEditAction class KTDocumentEditAction extends KTDocumentAction { @@ -233,6 +234,16 @@ class KTDocumentEditAction extends KTDocumentAction { $oDocumentTransaction = & new DocumentTransaction($this->oDocument, _kt('Document metadata updated'), 'ktcore.transactions.update'); $oDocumentTransaction->create(); + // Check if there are any dynamic conditions / permissions that need to be updated on the document + // If there are dynamic conditions then update the permissions on the document + // The dynamic condition test fails unless the changes exists in the DB therefore update permissions after committing the transaction. + $iPermissionObjectId = $this->oDocument->getPermissionObjectID(); + $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId); + + if(!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)){ + $res = KTPermissionUtil::updatePermissionLookup($this->oDocument); + } + redirect(KTBrowseUtil::getUrlForDocument($this->oDocument->getId())); exit(0); } @@ -369,6 +380,16 @@ class KTDocumentEditAction extends KTDocumentAction { $ret = $oTrigger->postValidate(); } + // Check if there are any dynamic conditions / permissions that need to be updated on the document + // If there are dynamic conditions then update the permissions on the document + // The dynamic condition test fails unless the changes exists in the DB therefore update permissions after committing the transaction. + $iPermissionObjectId = $this->oDocument->getPermissionObjectID(); + $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId); + + if(!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)){ + $res = KTPermissionUtil::updatePermissionLookup($this->oDocument); + } + $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName())); } }