Commit bb28cfd04c58b04152d5c6d0220f95c7109f4b85
1 parent
5392153e
KTS-2668
"When updating a Dynamic condition it does not the updated conditions with permissions already set in folders." Fixed. Updated the permission object on updating or deleting a condition. Committed by: Megan Watson Reviewed by: Jonathan Byrne git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8104 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
71 additions
and
34 deletions
lib/permissions/permissiondynamiccondition.inc.php
| ... | ... | @@ -80,6 +80,12 @@ class KTPermissionDynamicCondition extends KTEntity { |
| 80 | 80 | return KTEntityUtil::getList2('KTPermissionDynamicCondition', $sWhereClause); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | + function getPermissionObjectIdList($sWhereClause, $aParams) { | |
| 84 | + $query = 'SELECT DISTINCT(permission_object_id) FROM permission_dynamic_conditions WHERE '.$sWhereClause; | |
| 85 | + $aQuery = array($query, $aParams); | |
| 86 | + return DBUtil::getResultArray($aQuery); | |
| 87 | + } | |
| 88 | + | |
| 83 | 89 | function &getByPermissionObject($oPermissionObject) { |
| 84 | 90 | $iPermissionObjectId = KTUtil::getId($oPermissionObject); |
| 85 | 91 | return KTEntityUtil::getByDict('KTPermissionDynamicCondition', array( | ... | ... |
plugins/ktcore/admin/conditions.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 | */ |
| ... | ... | @@ -39,6 +39,7 @@ require_once(KT_LIB_DIR . "/templating/templating.inc.php"); |
| 39 | 39 | require_once(KT_LIB_DIR . "/dispatcher.inc.php"); |
| 40 | 40 | require_once(KT_LIB_DIR . "/browse/Criteria.inc"); |
| 41 | 41 | require_once(KT_LIB_DIR . "/search/savedsearch.inc.php"); |
| 42 | +require_once(KT_LIB_DIR .'/permissions/permissiondynamiccondition.inc.php'); | |
| 42 | 43 | |
| 43 | 44 | class KTConditionDispatcher extends KTAdminDispatcher { |
| 44 | 45 | var $bAutomaticTransaction = true; |
| ... | ... | @@ -72,6 +73,12 @@ class KTConditionDispatcher extends KTAdminDispatcher { |
| 72 | 73 | |
| 73 | 74 | function do_delete_confirmed() { |
| 74 | 75 | $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId'); |
| 76 | + | |
| 77 | + // Get associated permission objects before deleting the condition | |
| 78 | + $sWhere = 'condition_id = ?'; | |
| 79 | + $aParams = array($id); | |
| 80 | + $aPermissionObjects = KTPermissionDynamicCondition::getPermissionObjectIdList($sWhere, $aParams); | |
| 81 | + | |
| 75 | 82 | $oSearch = KTSavedSearch::get($id); |
| 76 | 83 | KTPermissionDynamicCondition::deleteByCondition($oSearch); |
| 77 | 84 | $res = $oSearch->delete(); |
| ... | ... | @@ -79,19 +86,29 @@ class KTConditionDispatcher extends KTAdminDispatcher { |
| 79 | 86 | 'redirect_to' => 'main', |
| 80 | 87 | 'message' => _kt('Search not deleted'), |
| 81 | 88 | )); |
| 89 | + | |
| 90 | + // Update permission objects if they exist | |
| 91 | + if(!PEAR::isError($aPermissionObjects) && !empty($aPermissionObjects)){ | |
| 92 | + // update permission objects | |
| 93 | + foreach($aPermissionObjects as $iPermObjectId){ | |
| 94 | + $oPO = KTPermissionObject::get($iPermObjectId['permission_object_id']); | |
| 95 | + KTPermissionUtil::updatePermissionLookupForPO($oPO); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + | |
| 82 | 99 | $this->successRedirectToMain(_kt('Dynamic condition deleted')); |
| 83 | 100 | } |
| 84 | 101 | |
| 85 | 102 | function do_new() { |
| 86 | 103 | $this->oPage->setBreadcrumbDetails(_kt('Create a new condition')); |
| 87 | 104 | $this->oPage->setTitle(_kt('Create a new condition')); |
| 88 | - | |
| 105 | + | |
| 89 | 106 | $oTemplating =& KTTemplating::getSingleton(); |
| 90 | 107 | $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search"); |
| 91 | - | |
| 108 | + | |
| 92 | 109 | $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton(); |
| 93 | 110 | $aCriteria =& $oCriteriaRegistry->getCriteria(); |
| 94 | - | |
| 111 | + | |
| 95 | 112 | $aTemplateData = array( |
| 96 | 113 | "title" => _kt("Create a new condition"), |
| 97 | 114 | "sNameTitle" => _kt("Name of condition"), |
| ... | ... | @@ -105,24 +122,24 @@ class KTConditionDispatcher extends KTAdminDispatcher { |
| 105 | 122 | function do_view() { |
| 106 | 123 | |
| 107 | 124 | } |
| 108 | - | |
| 125 | + | |
| 109 | 126 | function do_edit() { |
| 110 | 127 | $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId'); |
| 111 | 128 | $oSearch = KTSavedSearch::get($id); |
| 112 | - | |
| 129 | + | |
| 113 | 130 | if (PEAR::isError($oSearch) || ($oSearch == false)) { |
| 114 | 131 | $this->errorRedirectToMain('No such dynamic condition'); |
| 115 | 132 | } |
| 116 | - | |
| 133 | + | |
| 117 | 134 | $aSearch = $oSearch->getSearch(); |
| 118 | - | |
| 119 | - | |
| 135 | + | |
| 136 | + | |
| 120 | 137 | $oTemplating =& KTTemplating::getSingleton(); |
| 121 | 138 | $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search_edit"); |
| 122 | - | |
| 139 | + | |
| 123 | 140 | $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton(); |
| 124 | 141 | $aCriteria =& $oCriteriaRegistry->getCriteria(); |
| 125 | - | |
| 142 | + | |
| 126 | 143 | // we need to help out here, since it gets unpleasant inside the template. |
| 127 | 144 | foreach ($aSearch['subgroup'] as $isg => $as) { |
| 128 | 145 | $aSubgroup =& $aSearch['subgroup'][$isg]; |
| ... | ... | @@ -139,8 +156,8 @@ class KTConditionDispatcher extends KTAdminDispatcher { |
| 139 | 156 | } |
| 140 | 157 | } |
| 141 | 158 | } |
| 142 | - | |
| 143 | - | |
| 159 | + | |
| 160 | + | |
| 144 | 161 | $aTemplateData = array( |
| 145 | 162 | "title" => _kt("Edit an existing condition"), |
| 146 | 163 | "aCriteria" => $aCriteria, |
| ... | ... | @@ -151,26 +168,26 @@ class KTConditionDispatcher extends KTAdminDispatcher { |
| 151 | 168 | 'old_name' => $oSearch->getName(), |
| 152 | 169 | 'sNameTitle' => _kt('Edit Dynamic Condition'), |
| 153 | 170 | ); |
| 154 | - return $oTemplate->render($aTemplateData); | |
| 171 | + return $oTemplate->render($aTemplateData); | |
| 155 | 172 | } |
| 156 | - | |
| 173 | + | |
| 157 | 174 | |
| 158 | 175 | // XXX: Rename to do_save |
| 159 | 176 | function do_updateSearch() { |
| 160 | 177 | $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId'); |
| 161 | 178 | $sName = KTUtil::arrayGet($_REQUEST, 'name'); |
| 162 | 179 | $oSearch = KTSavedSearch::get($id); |
| 163 | - | |
| 180 | + | |
| 164 | 181 | if (PEAR::isError($oSearch) || ($oSearch == false)) { |
| 165 | 182 | $this->errorRedirectToMain('No such dynamic condition'); |
| 166 | 183 | } |
| 167 | - | |
| 168 | - | |
| 184 | + | |
| 185 | + | |
| 169 | 186 | $datavars = KTUtil::arrayGet($_REQUEST, 'boolean_search'); |
| 170 | 187 | if (!is_array($datavars)) { |
| 171 | 188 | $datavars = unserialize($datavars); |
| 172 | 189 | } |
| 173 | - | |
| 190 | + | |
| 174 | 191 | if (empty($datavars)) { |
| 175 | 192 | $this->errorRedirectToMain(_kt('You need to have at least 1 condition.')); |
| 176 | 193 | } |
| ... | ... | @@ -179,16 +196,30 @@ class KTConditionDispatcher extends KTAdminDispatcher { |
| 179 | 196 | if (!empty($sName)) { |
| 180 | 197 | $oSearch->setName($sName); |
| 181 | 198 | } |
| 182 | - | |
| 199 | + | |
| 183 | 200 | $oSearch->setSearch($datavars); |
| 184 | 201 | $res = $oSearch->update(); |
| 185 | - | |
| 202 | + | |
| 186 | 203 | $this->oValidator->notError($res, array( |
| 187 | 204 | 'redirect_to' => 'main', |
| 188 | 205 | 'message' => _kt('Search not saved'), |
| 189 | 206 | )); |
| 207 | + | |
| 208 | + // Update permission object if exists | |
| 209 | + $sWhere = 'condition_id = ?'; | |
| 210 | + $aParams = array($id); | |
| 211 | + $aPermissionObjects = KTPermissionDynamicCondition::getPermissionObjectIdList($sWhere, $aParams); | |
| 212 | + | |
| 213 | + if(!PEAR::isError($aPermissionObjects) && !empty($aPermissionObjects)){ | |
| 214 | + // update permission objects | |
| 215 | + foreach($aPermissionObjects as $iPermObjectId){ | |
| 216 | + $oPO = KTPermissionObject::get($iPermObjectId['permission_object_id']); | |
| 217 | + KTPermissionUtil::updatePermissionLookupForPO($oPO); | |
| 218 | + } | |
| 219 | + } | |
| 220 | + | |
| 190 | 221 | $this->successRedirectToMain(_kt('Dynamic condition saved')); |
| 191 | - } | |
| 222 | + } | |
| 192 | 223 | |
| 193 | 224 | // XXX: Rename to do_save |
| 194 | 225 | function do_performSearch() { |
| ... | ... | @@ -196,17 +227,17 @@ class KTConditionDispatcher extends KTAdminDispatcher { |
| 196 | 227 | if (!is_array($datavars)) { |
| 197 | 228 | $datavars = unserialize($datavars); |
| 198 | 229 | } |
| 199 | - | |
| 230 | + | |
| 200 | 231 | if (empty($datavars)) { |
| 201 | 232 | $this->errorRedirectToMain(_kt('You need to have at least 1 condition.')); |
| 202 | 233 | } |
| 203 | 234 | |
| 204 | 235 | $sName = $this->oValidator->validateEntityName( |
| 205 | - 'KTSavedSearch', | |
| 206 | - KTUtil::arrayGet($_REQUEST, 'name'), | |
| 236 | + 'KTSavedSearch', | |
| 237 | + KTUtil::arrayGet($_REQUEST, 'name'), | |
| 207 | 238 | array('extra_condition' => 'is_condition', 'redirect_to' => array('new')) |
| 208 | 239 | ); |
| 209 | - | |
| 240 | + | |
| 210 | 241 | $sNamespace = KTUtil::nameToLocalNamespace('Saved searches', $sName); |
| 211 | 242 | |
| 212 | 243 | $oSearch = KTSavedSearch::createFromArray(array( | ... | ... |