Commit bf421a57f23899a7d2f4e14a3b0604233757e82b

Authored by Megan Watson
1 parent 84f60ac0

KTC-248

"Disable commercial plugins on license expiry and display dashlet"
Fixed. Changed delete user to deallocate the license. Changed isBaobabUser to isValid user on creating a session, so as not to lock the user out.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7409 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/session/Session.inc
@@ -45,10 +45,12 @@ class Session { @@ -45,10 +45,12 @@ class Session {
45 45
46 session_start(); 46 session_start();
47 47
  48 +
  49 + // Don't need to lock a user out the web interface if KT Tools exists and has no license.
48 if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { 50 if (KTPluginUtil::pluginIsActive('ktdms.wintools')) {
49 if (!$oUser->isAnonymous()) { 51 if (!$oUser->isAnonymous()) {
50 require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); 52 require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php');
51 - $res = BaobabKeyUtil::isBaobabUser($oUser); 53 + $res = BaobabKeyUtil::isValidUser($oUser);
52 if (PEAR::isError($res)) { 54 if (PEAR::isError($res)) {
53 return $res; 55 return $res;
54 } 56 }
lib/users/User.inc
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 * License Version 1.1.2 ("License"); You may not use this file except in 8 * License Version 1.1.2 ("License"); You may not use this file except in
9 * compliance with the License. You may obtain a copy of the License at 9 * compliance with the License. You may obtain a copy of the License at
10 * http://www.knowledgetree.com/KPL 10 * http://www.knowledgetree.com/KPL
11 - * 11 + *
12 * Software distributed under the License is distributed on an "AS IS" 12 * Software distributed under the License is distributed on an "AS IS"
13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
14 * See the License for the specific language governing rights and 14 * See the License for the specific language governing rights and
@@ -19,9 +19,9 @@ @@ -19,9 +19,9 @@
19 * (ii) the KnowledgeTree copyright notice 19 * (ii) the KnowledgeTree copyright notice
20 * in the same form as they appear in the distribution. See the License for 20 * in the same form as they appear in the distribution. See the License for
21 * requirements. 21 * requirements.
22 - * 22 + *
23 * The Original Code is: KnowledgeTree Open Source 23 * The Original Code is: KnowledgeTree Open Source
24 - * 24 + *
25 * The Initial Developer of the Original Code is The Jam Warehouse Software 25 * The Initial Developer of the Original Code is The Jam Warehouse Software
26 * (Pty) Ltd, trading as KnowledgeTree. 26 * (Pty) Ltd, trading as KnowledgeTree.
27 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright 27 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
@@ -29,13 +29,13 @@ @@ -29,13 +29,13 @@
29 * All Rights Reserved. 29 * All Rights Reserved.
30 * Contributor( s): ______________________________________ 30 * Contributor( s): ______________________________________
31 */ 31 */
32 -  
33 -require_once(KT_LIB_DIR . '/database/dbutil.inc');  
34 -require_once(KT_LIB_DIR . '/ktentity.inc'); 32 +
  33 +require_once(KT_LIB_DIR . '/database/dbutil.inc');
  34 +require_once(KT_LIB_DIR . '/ktentity.inc');
35 require_once(KT_LIB_DIR . "/util/sanitize.inc"); 35 require_once(KT_LIB_DIR . "/util/sanitize.inc");
36 36
37 define('ADMIN_USER_ID', 1); 37 define('ADMIN_USER_ID', 1);
38 - 38 +
39 class User extends KTEntity { 39 class User extends KTEntity {
40 /** user's login name */ 40 /** user's login name */
41 var $sUserName; 41 var $sUserName;
@@ -106,14 +106,14 @@ class User extends KTEntity { @@ -106,14 +106,14 @@ class User extends KTEntity {
106 function _table() { 106 function _table() {
107 return KTUtil::getTableName("users"); 107 return KTUtil::getTableName("users");
108 } 108 }
109 - 109 +
110 // STATIC 110 // STATIC
111 function _ktentityOptions() { 111 function _ktentityOptions() {
112 return array( 112 return array(
113 'orderby' => 'name', 113 'orderby' => 'name',
114 ); 114 );
115 } 115 }
116 - 116 +
117 117
118 function getUserName() { return sanitizeForSQLtoHTML($this->sUserName); } 118 function getUserName() { return sanitizeForSQLtoHTML($this->sUserName); }
119 function setUserName($sNewValue) { $this->sUserName = sanitizeForSQL($sNewValue); } 119 function setUserName($sNewValue) { $this->sUserName = sanitizeForSQL($sNewValue); }
@@ -169,11 +169,11 @@ class User extends KTEntity { @@ -169,11 +169,11 @@ class User extends KTEntity {
169 return 'dashboard-state-' . $this->getId(); 169 return 'dashboard-state-' . $this->getId();
170 } 170 }
171 171
172 - function getDashboardState() { 172 + function getDashboardState() {
173 return KTUtil::getSystemSetting($this->_getDashboardStateKey()); 173 return KTUtil::getSystemSetting($this->_getDashboardStateKey());
174 } 174 }
175 175
176 - function setDashboardState($mValue) { 176 + function setDashboardState($mValue) {
177 KTUtil::setSystemSetting($this->_getDashboardStateKey(), $mValue); 177 KTUtil::setSystemSetting($this->_getDashboardStateKey(), $mValue);
178 } 178 }
179 179
@@ -182,9 +182,9 @@ class User extends KTEntity { @@ -182,9 +182,9 @@ class User extends KTEntity {
182 require_once(KT_DIR . "/thirdparty/pear/JSON.php"); 182 require_once(KT_DIR . "/thirdparty/pear/JSON.php");
183 183
184 $dashletRegistry = & KTDashletRegistry::getSingleton(); 184 $dashletRegistry = & KTDashletRegistry::getSingleton();
185 - 185 +
186 $aDashlets = $dashletRegistry->getDashlets($this); 186 $aDashlets = $dashletRegistry->getDashlets($this);
187 - 187 +
188 $oJSON = new Services_JSON(); 188 $oJSON = new Services_JSON();
189 189
190 $state = $this->getDashboardState(); 190 $state = $this->getDashboardState();
@@ -193,18 +193,18 @@ class User extends KTEntity { @@ -193,18 +193,18 @@ class User extends KTEntity {
193 if (!isset($dashlets->left)) $dashlets->left = array(); 193 if (!isset($dashlets->left)) $dashlets->left = array();
194 if (!isset($dashlets->right)) $dashlets->right = array(); 194 if (!isset($dashlets->right)) $dashlets->right = array();
195 $mergedlist = kt_array_merge($dashlets->left,$dashlets->right); 195 $mergedlist = kt_array_merge($dashlets->left,$dashlets->right);
196 -  
197 - 196 +
  197 +
198 $knownlist = array(); 198 $knownlist = array();
199 foreach($mergedlist as $dashlet) 199 foreach($mergedlist as $dashlet)
200 { 200 {
201 array_push($knownlist,$dashlet->id); 201 array_push($knownlist,$dashlet->id);
202 } 202 }
203 $update=false; 203 $update=false;
204 - 204 +
205 //if (!isset($dashlets->left)) $dashlets->left=array(); 205 //if (!isset($dashlets->left)) $dashlets->left=array();
206 //if (!isset($dashlets->right)) $dashlets->right=array(); 206 //if (!isset($dashlets->right)) $dashlets->right=array();
207 - 207 +
208 $column=1; 208 $column=1;
209 foreach($aDashlets as $dashlet) 209 foreach($aDashlets as $dashlet)
210 { 210 {
@@ -215,7 +215,7 @@ class User extends KTEntity { @@ -215,7 +215,7 @@ class User extends KTEntity {
215 $obj = new stdClass(); 215 $obj = new stdClass();
216 $obj->id=$class; 216 $obj->id=$class;
217 $obj->state=0; 217 $obj->state=0;
218 - 218 +
219 if ($column == 0) 219 if ($column == 0)
220 array_push($dashlets->left,$obj); 220 array_push($dashlets->left,$obj);
221 else 221 else
@@ -223,19 +223,19 @@ class User extends KTEntity { @@ -223,19 +223,19 @@ class User extends KTEntity {
223 $update=true; 223 $update=true;
224 } 224 }
225 } 225 }
226 - 226 +
227 if ($update) 227 if ($update)
228 { 228 {
229 $state = $oJSON->encode($dashlets); 229 $state = $oJSON->encode($dashlets);
230 $this->setDashboardState($state); 230 $this->setDashboardState($state);
231 } 231 }
232 } 232 }
233 -  
234 - 233 +
  234 +
235 function &get($iId) { 235 function &get($iId) {
236 return KTEntityUtil::get('User', $iId); 236 return KTEntityUtil::get('User', $iId);
237 } 237 }
238 - 238 +
239 /** 239 /**
240 * update the datastore, without overwriting the password. 240 * update the datastore, without overwriting the password.
241 * 241 *
@@ -244,25 +244,25 @@ class User extends KTEntity { @@ -244,25 +244,25 @@ class User extends KTEntity {
244 function doLimitedUpdate() { 244 function doLimitedUpdate() {
245 $sQuery = 'UPDATE ' . $this->_table() . ' SET '; 245 $sQuery = 'UPDATE ' . $this->_table() . ' SET ';
246 $aParams = array(); 246 $aParams = array();
247 - 247 +
248 $blacklist = array( 248 $blacklist = array(
249 "sPassword" => 1, 249 "sPassword" => 1,
250 ); 250 );
251 - 251 +
252 $aParts = array(); // quick workaround to make the join less hurtful. 252 $aParts = array(); // quick workaround to make the join less hurtful.
253 - 253 +
254 foreach ($this->_aFieldToSelect as $attr => $column) { 254 foreach ($this->_aFieldToSelect as $attr => $column) {
255 if (!array_key_exists($attr, $blacklist)) { 255 if (!array_key_exists($attr, $blacklist)) {
256 $val = $this->$attr; 256 $val = $this->$attr;
257 $aParts[] = $column . ' = ?'; 257 $aParts[] = $column . ' = ?';
258 - $aParams[] = $val;  
259 - } 258 + $aParams[] = $val;
  259 + }
260 } 260 }
261 $sQuery .= join(', ', $aParts); 261 $sQuery .= join(', ', $aParts);
262 - 262 +
263 $sQuery .= ' WHERE id = ? '; 263 $sQuery .= ' WHERE id = ? ';
264 $aParams[] = $this->getId(); 264 $aParams[] = $this->getId();
265 - 265 +
266 $res = DBUtil::runQuery(array($sQuery, $aParams)); 266 $res = DBUtil::runQuery(array($sQuery, $aParams));
267 267
268 $group = sprintf("%s/%s", get_class($this), 'id'); 268 $group = sprintf("%s/%s", get_class($this), 'id');
@@ -272,8 +272,8 @@ class User extends KTEntity { @@ -272,8 +272,8 @@ class User extends KTEntity {
272 272
273 return $res; 273 return $res;
274 } 274 }
275 -  
276 - 275 +
  276 +
277 /** 277 /**
278 * Static function 278 * Static function
279 * Get a list of users 279 * Get a list of users
@@ -329,7 +329,7 @@ class User extends KTEntity { @@ -329,7 +329,7 @@ class User extends KTEntity {
329 329
330 $this->iId = $id; 330 $this->iId = $id;
331 } 331 }
332 - 332 +
333 /** Static function 333 /** Static function
334 * Gets the user's default top level folder for the current user 334 * Gets the user's default top level folder for the current user
335 */ 335 */
@@ -343,7 +343,7 @@ class User extends KTEntity { @@ -343,7 +343,7 @@ class User extends KTEntity {
343 $oUnit =& Unit::get($iUnitId); 343 $oUnit =& Unit::get($iUnitId);
344 return $oUnit->getFolderId(); 344 return $oUnit->getFolderId();
345 } 345 }
346 - 346 +
347 function &createFromArray($aOptions) { return KTEntityUtil::createFromArray('User', $aOptions); } 347 function &createFromArray($aOptions) { return KTEntityUtil::createFromArray('User', $aOptions); }
348 function &getByUserName($sUserName, $aOptions = null) { 348 function &getByUserName($sUserName, $aOptions = null) {
349 return KTEntityUtil::getBy('User', 'username', $sUserName, $aOptions); 349 return KTEntityUtil::getBy('User', 'username', $sUserName, $aOptions);
@@ -385,7 +385,7 @@ class User extends KTEntity { @@ -385,7 +385,7 @@ class User extends KTEntity {
385 $aParams = array(false); 385 $aParams = array(false);
386 return DBUtil::getOneResultKey(array($sQuery, $aParams), 'number'); 386 return DBUtil::getOneResultKey(array($sQuery, $aParams), 'number');
387 } 387 }
388 - 388 +
389 function isAnonymous() { return $this->iId == -2; } 389 function isAnonymous() { return $this->iId == -2; }
390 390
391 function disable() { 391 function disable() {
@@ -397,7 +397,7 @@ class User extends KTEntity { @@ -397,7 +397,7 @@ class User extends KTEntity {
397 } 397 }
398 return; 398 return;
399 } 399 }
400 - 400 +
401 function enable() { 401 function enable() {
402 $this->setDisabled(0); 402 $this->setDisabled(0);
403 $this->update(); 403 $this->update();
@@ -406,7 +406,7 @@ class User extends KTEntity { @@ -406,7 +406,7 @@ class User extends KTEntity {
406 BaobabKeyUtil::allocateUser($this); 406 BaobabKeyUtil::allocateUser($this);
407 } 407 }
408 return; 408 return;
409 - } 409 + }
410 410
411 function create() { 411 function create() {
412 if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { 412 if (KTPluginUtil::pluginIsActive('ktdms.wintools')) {
@@ -418,7 +418,7 @@ class User extends KTEntity { @@ -418,7 +418,7 @@ class User extends KTEntity {
418 } 418 }
419 return parent::create(); 419 return parent::create();
420 } 420 }
421 - 421 +
422 function delete() 422 function delete()
423 { 423 {
424 $this->setDisabled(2); 424 $this->setDisabled(2);
@@ -429,7 +429,7 @@ class User extends KTEntity { @@ -429,7 +429,7 @@ class User extends KTEntity {
429 $tempUserID = $this->iId; 429 $tempUserID = $this->iId;
430 $DeletedUsername = 'kt_deleted_'.$tempUsername.'_'.$tempUserID; 430 $DeletedUsername = 'kt_deleted_'.$tempUsername.'_'.$tempUserID;
431 $this->setUsername($DeletedUsername); 431 $this->setUsername($DeletedUsername);
432 - 432 +
433 //nullify all authentication_xxx fields 433 //nullify all authentication_xxx fields
434 $this->setAuthenticationSourceId(null); 434 $this->setAuthenticationSourceId(null);
435 $this->setAuthenticationDetails(null); 435 $this->setAuthenticationDetails(null);
@@ -440,13 +440,13 @@ class User extends KTEntity { @@ -440,13 +440,13 @@ class User extends KTEntity {
440 $this->setAuthenticationDetailsDate2(null); 440 $this->setAuthenticationDetailsDate2(null);
441 $this->setAuthenticationDetailsBool1(null); 441 $this->setAuthenticationDetailsBool1(null);
442 $this->setAuthenticationDetailsBool2(null); 442 $this->setAuthenticationDetailsBool2(null);
443 - 443 +
444 $this->update(); 444 $this->update();
445 if (KTPluginUtil::pluginIsActive('ktdms.wintools')) { 445 if (KTPluginUtil::pluginIsActive('ktdms.wintools')) {
446 require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php'); 446 require_once(KT_DIR . '/plugins/wintools/baobabkeyutil.inc.php');
447 - BaobabKeyUtil::allocateUser($this); 447 + BaobabKeyUtil::deallocateUser($this);
448 } 448 }
449 return; 449 return;
450 - 450 +
451 } 451 }
452 } 452 }