Commit bb28cfd04c58b04152d5c6d0220f95c7109f4b85

Authored by Megan Watson
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
lib/permissions/permissiondynamiccondition.inc.php
@@ -80,6 +80,12 @@ class KTPermissionDynamicCondition extends KTEntity { @@ -80,6 +80,12 @@ class KTPermissionDynamicCondition extends KTEntity {
80 return KTEntityUtil::getList2('KTPermissionDynamicCondition', $sWhereClause); 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 function &getByPermissionObject($oPermissionObject) { 89 function &getByPermissionObject($oPermissionObject) {
84 $iPermissionObjectId = KTUtil::getId($oPermissionObject); 90 $iPermissionObjectId = KTUtil::getId($oPermissionObject);
85 return KTEntityUtil::getByDict('KTPermissionDynamicCondition', array( 91 return KTEntityUtil::getByDict('KTPermissionDynamicCondition', array(
plugins/ktcore/admin/conditions.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 */
@@ -39,6 +39,7 @@ require_once(KT_LIB_DIR . &quot;/templating/templating.inc.php&quot;); @@ -39,6 +39,7 @@ require_once(KT_LIB_DIR . &quot;/templating/templating.inc.php&quot;);
39 require_once(KT_LIB_DIR . "/dispatcher.inc.php"); 39 require_once(KT_LIB_DIR . "/dispatcher.inc.php");
40 require_once(KT_LIB_DIR . "/browse/Criteria.inc"); 40 require_once(KT_LIB_DIR . "/browse/Criteria.inc");
41 require_once(KT_LIB_DIR . "/search/savedsearch.inc.php"); 41 require_once(KT_LIB_DIR . "/search/savedsearch.inc.php");
  42 +require_once(KT_LIB_DIR .'/permissions/permissiondynamiccondition.inc.php');
42 43
43 class KTConditionDispatcher extends KTAdminDispatcher { 44 class KTConditionDispatcher extends KTAdminDispatcher {
44 var $bAutomaticTransaction = true; 45 var $bAutomaticTransaction = true;
@@ -72,6 +73,12 @@ class KTConditionDispatcher extends KTAdminDispatcher { @@ -72,6 +73,12 @@ class KTConditionDispatcher extends KTAdminDispatcher {
72 73
73 function do_delete_confirmed() { 74 function do_delete_confirmed() {
74 $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId'); 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 $oSearch = KTSavedSearch::get($id); 82 $oSearch = KTSavedSearch::get($id);
76 KTPermissionDynamicCondition::deleteByCondition($oSearch); 83 KTPermissionDynamicCondition::deleteByCondition($oSearch);
77 $res = $oSearch->delete(); 84 $res = $oSearch->delete();
@@ -79,19 +86,29 @@ class KTConditionDispatcher extends KTAdminDispatcher { @@ -79,19 +86,29 @@ class KTConditionDispatcher extends KTAdminDispatcher {
79 'redirect_to' => 'main', 86 'redirect_to' => 'main',
80 'message' => _kt('Search not deleted'), 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 $this->successRedirectToMain(_kt('Dynamic condition deleted')); 99 $this->successRedirectToMain(_kt('Dynamic condition deleted'));
83 } 100 }
84 101
85 function do_new() { 102 function do_new() {
86 $this->oPage->setBreadcrumbDetails(_kt('Create a new condition')); 103 $this->oPage->setBreadcrumbDetails(_kt('Create a new condition'));
87 $this->oPage->setTitle(_kt('Create a new condition')); 104 $this->oPage->setTitle(_kt('Create a new condition'));
88 - 105 +
89 $oTemplating =& KTTemplating::getSingleton(); 106 $oTemplating =& KTTemplating::getSingleton();
90 $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search"); 107 $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search");
91 - 108 +
92 $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton(); 109 $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
93 $aCriteria =& $oCriteriaRegistry->getCriteria(); 110 $aCriteria =& $oCriteriaRegistry->getCriteria();
94 - 111 +
95 $aTemplateData = array( 112 $aTemplateData = array(
96 "title" => _kt("Create a new condition"), 113 "title" => _kt("Create a new condition"),
97 "sNameTitle" => _kt("Name of condition"), 114 "sNameTitle" => _kt("Name of condition"),
@@ -105,24 +122,24 @@ class KTConditionDispatcher extends KTAdminDispatcher { @@ -105,24 +122,24 @@ class KTConditionDispatcher extends KTAdminDispatcher {
105 function do_view() { 122 function do_view() {
106 123
107 } 124 }
108 - 125 +
109 function do_edit() { 126 function do_edit() {
110 $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId'); 127 $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId');
111 $oSearch = KTSavedSearch::get($id); 128 $oSearch = KTSavedSearch::get($id);
112 - 129 +
113 if (PEAR::isError($oSearch) || ($oSearch == false)) { 130 if (PEAR::isError($oSearch) || ($oSearch == false)) {
114 $this->errorRedirectToMain('No such dynamic condition'); 131 $this->errorRedirectToMain('No such dynamic condition');
115 } 132 }
116 - 133 +
117 $aSearch = $oSearch->getSearch(); 134 $aSearch = $oSearch->getSearch();
118 -  
119 - 135 +
  136 +
120 $oTemplating =& KTTemplating::getSingleton(); 137 $oTemplating =& KTTemplating::getSingleton();
121 $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search_edit"); 138 $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search_edit");
122 - 139 +
123 $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton(); 140 $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
124 $aCriteria =& $oCriteriaRegistry->getCriteria(); 141 $aCriteria =& $oCriteriaRegistry->getCriteria();
125 - 142 +
126 // we need to help out here, since it gets unpleasant inside the template. 143 // we need to help out here, since it gets unpleasant inside the template.
127 foreach ($aSearch['subgroup'] as $isg => $as) { 144 foreach ($aSearch['subgroup'] as $isg => $as) {
128 $aSubgroup =& $aSearch['subgroup'][$isg]; 145 $aSubgroup =& $aSearch['subgroup'][$isg];
@@ -139,8 +156,8 @@ class KTConditionDispatcher extends KTAdminDispatcher { @@ -139,8 +156,8 @@ class KTConditionDispatcher extends KTAdminDispatcher {
139 } 156 }
140 } 157 }
141 } 158 }
142 -  
143 - 159 +
  160 +
144 $aTemplateData = array( 161 $aTemplateData = array(
145 "title" => _kt("Edit an existing condition"), 162 "title" => _kt("Edit an existing condition"),
146 "aCriteria" => $aCriteria, 163 "aCriteria" => $aCriteria,
@@ -151,26 +168,26 @@ class KTConditionDispatcher extends KTAdminDispatcher { @@ -151,26 +168,26 @@ class KTConditionDispatcher extends KTAdminDispatcher {
151 'old_name' => $oSearch->getName(), 168 'old_name' => $oSearch->getName(),
152 'sNameTitle' => _kt('Edit Dynamic Condition'), 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 // XXX: Rename to do_save 175 // XXX: Rename to do_save
159 function do_updateSearch() { 176 function do_updateSearch() {
160 $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId'); 177 $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId');
161 $sName = KTUtil::arrayGet($_REQUEST, 'name'); 178 $sName = KTUtil::arrayGet($_REQUEST, 'name');
162 $oSearch = KTSavedSearch::get($id); 179 $oSearch = KTSavedSearch::get($id);
163 - 180 +
164 if (PEAR::isError($oSearch) || ($oSearch == false)) { 181 if (PEAR::isError($oSearch) || ($oSearch == false)) {
165 $this->errorRedirectToMain('No such dynamic condition'); 182 $this->errorRedirectToMain('No such dynamic condition');
166 } 183 }
167 -  
168 - 184 +
  185 +
169 $datavars = KTUtil::arrayGet($_REQUEST, 'boolean_search'); 186 $datavars = KTUtil::arrayGet($_REQUEST, 'boolean_search');
170 if (!is_array($datavars)) { 187 if (!is_array($datavars)) {
171 $datavars = unserialize($datavars); 188 $datavars = unserialize($datavars);
172 } 189 }
173 - 190 +
174 if (empty($datavars)) { 191 if (empty($datavars)) {
175 $this->errorRedirectToMain(_kt('You need to have at least 1 condition.')); 192 $this->errorRedirectToMain(_kt('You need to have at least 1 condition.'));
176 } 193 }
@@ -179,16 +196,30 @@ class KTConditionDispatcher extends KTAdminDispatcher { @@ -179,16 +196,30 @@ class KTConditionDispatcher extends KTAdminDispatcher {
179 if (!empty($sName)) { 196 if (!empty($sName)) {
180 $oSearch->setName($sName); 197 $oSearch->setName($sName);
181 } 198 }
182 - 199 +
183 $oSearch->setSearch($datavars); 200 $oSearch->setSearch($datavars);
184 $res = $oSearch->update(); 201 $res = $oSearch->update();
185 - 202 +
186 $this->oValidator->notError($res, array( 203 $this->oValidator->notError($res, array(
187 'redirect_to' => 'main', 204 'redirect_to' => 'main',
188 'message' => _kt('Search not saved'), 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 $this->successRedirectToMain(_kt('Dynamic condition saved')); 221 $this->successRedirectToMain(_kt('Dynamic condition saved'));
191 - } 222 + }
192 223
193 // XXX: Rename to do_save 224 // XXX: Rename to do_save
194 function do_performSearch() { 225 function do_performSearch() {
@@ -196,17 +227,17 @@ class KTConditionDispatcher extends KTAdminDispatcher { @@ -196,17 +227,17 @@ class KTConditionDispatcher extends KTAdminDispatcher {
196 if (!is_array($datavars)) { 227 if (!is_array($datavars)) {
197 $datavars = unserialize($datavars); 228 $datavars = unserialize($datavars);
198 } 229 }
199 - 230 +
200 if (empty($datavars)) { 231 if (empty($datavars)) {
201 $this->errorRedirectToMain(_kt('You need to have at least 1 condition.')); 232 $this->errorRedirectToMain(_kt('You need to have at least 1 condition.'));
202 } 233 }
203 234
204 $sName = $this->oValidator->validateEntityName( 235 $sName = $this->oValidator->validateEntityName(
205 - 'KTSavedSearch',  
206 - KTUtil::arrayGet($_REQUEST, 'name'), 236 + 'KTSavedSearch',
  237 + KTUtil::arrayGet($_REQUEST, 'name'),
207 array('extra_condition' => 'is_condition', 'redirect_to' => array('new')) 238 array('extra_condition' => 'is_condition', 'redirect_to' => array('new'))
208 ); 239 );
209 - 240 +
210 $sNamespace = KTUtil::nameToLocalNamespace('Saved searches', $sName); 241 $sNamespace = KTUtil::nameToLocalNamespace('Saved searches', $sName);
211 242
212 $oSearch = KTSavedSearch::createFromArray(array( 243 $oSearch = KTSavedSearch::createFromArray(array(