Merging changes into trunk

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1567 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-12-22 01:17:03 +00:00
parent e0bc1cbb28
commit 217923eaec
8 changed files with 113 additions and 54 deletions

View file

@ -26,5 +26,5 @@
* @lastmodified $Date$ * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */
include_once('webroot'.DIRECTORY_SEPARATOR.'index.php'); require_once 'webroot'.DIRECTORY_SEPARATOR.'index.php';
?> ?>

View file

@ -66,9 +66,9 @@ if (!defined('WEBROOT_DIR'))
/** /**
* Configuration, directory layout and standard libraries * Configuration, directory layout and standard libraries
*/ */
require_once ROOT.'cake'.DS.'basics.php';
require_once ROOT.APP_DIR.DS.'config'.DS.'core.php'; require_once ROOT.APP_DIR.DS.'config'.DS.'core.php';
require_once ROOT.'cake'.DS.'config'.DS.'paths.php'; require_once ROOT.'cake'.DS.'config'.DS.'paths.php';
require_once CAKE.'basics.php';
require_once LIBS.'log.php'; require_once LIBS.'log.php';
require_once LIBS.'object.php'; require_once LIBS.'object.php';
require_once LIBS.'session.php'; require_once LIBS.'session.php';

View file

@ -11,8 +11,7 @@
* CakePHP : Rapid Development Framework <http://www.cakephp.org/> * CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright (c) 2005, CakePHP Authors/Developers * Copyright (c) 2005, CakePHP Authors/Developers
* *
* Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> * Author(s): Larry E. Masters aka PhpNut <nut@phpnut.com>
* Larry E. Masters aka PhpNut <nut@phpnut.com>
* Kamil Dzielinski aka Brego <brego.dk@gmail.com> * Kamil Dzielinski aka Brego <brego.dk@gmail.com>
* *
* Licensed under The MIT License * Licensed under The MIT License

View file

@ -72,8 +72,10 @@ class AclBase
* @param unknown_type $aco * @param unknown_type $aco
* @param unknown_type $action * @param unknown_type $action
*/ */
function check($aro, $aco, $action = "*") {} function check($aro, $aco, $action = "*")
{
} }
}
?> ?>

View file

@ -87,6 +87,11 @@ class DB_ACL extends AclBase
trigger_error('ACO permissions key "' . $action . '" does not exist in DB_ACL::check()', E_USER_ERROR); trigger_error('ACO permissions key "' . $action . '" does not exist in DB_ACL::check()', E_USER_ERROR);
} }
if($aroPath == false || $aroPath == null || count($aroPath) == 0 || $tmpAcoPath == false || $tmpAcoPath == null || count($tmpAcoPath) == 0)
{
return null;
}
foreach($tmpAcoPath as $a) foreach($tmpAcoPath as $a)
{ {
$acoPath[] = $a['Aco']['id']; $acoPath[] = $a['Aco']['id'];
@ -151,6 +156,13 @@ class DB_ACL extends AclBase
$permKeys = $this->_getAcoKeys($Perms->loadInfo()); $permKeys = $this->_getAcoKeys($Perms->loadInfo());
$save = array(); $save = array();
if($perms == false)
{
// One of the nodes does not exist
return false;
}
if(isset($perms[0])) if(isset($perms[0]))
{ {
$save = $perms[0]['aros_acos']; $save = $perms[0]['aros_acos'];
@ -173,6 +185,7 @@ class DB_ACL extends AclBase
else else
{ {
// Raise an error // Raise an error
return false;
} }
} }
@ -308,6 +321,11 @@ class DB_ACL extends AclBase
$obj['Aro'] = $obj['Aro']['Aro']; $obj['Aro'] = $obj['Aro']['Aro'];
$obj['Aco'] = $obj['Aco']['Aco']; $obj['Aco'] = $obj['Aco']['Aco'];
if($obj['Aro'] == null || count($obj['Aro']) == 0 || $obj['Aco'] == null || count($obj['Aco']) == 0)
{
return false;
}
return array( return array(
'aro' => $obj['Aro']['id'], 'aro' => $obj['Aro']['id'],
'aco' => $obj['Aco']['id'], 'aco' => $obj['Aco']['id'],

View file

@ -1,6 +1,7 @@
CREATE TABLE `acos` ( CREATE TABLE `acos` (
`id` int(11) NOT NULL auto_increment, `id` int(11) NOT NULL auto_increment,
`model` varchar(255) NOT NULL default '',
`object_id` int(11) default NULL, `object_id` int(11) default NULL,
`alias` varchar(255) NOT NULL default '', `alias` varchar(255) NOT NULL default '',
`lft` int(11) default NULL, `lft` int(11) default NULL,
@ -10,6 +11,7 @@ CREATE TABLE `acos` (
CREATE TABLE `aros` ( CREATE TABLE `aros` (
`id` int(11) NOT NULL auto_increment, `id` int(11) NOT NULL auto_increment,
`model` varchar(255) NOT NULL default '',
`user_id` int(11) default NULL, `user_id` int(11) default NULL,
`alias` varchar(255) NOT NULL default '', `alias` varchar(255) NOT NULL default '',
`lft` int(11) default NULL, `lft` int(11) default NULL,

View file

@ -58,29 +58,36 @@ class AclNode extends AppModel
* Enter description here... * Enter description here...
* *
*/ */
function __construct() function __construct($object = null, $parent = null)
{ {
parent::__construct(); parent::__construct();
$this->__setTable(); $this->__setTable();
if($object != null)
{
$this->create($object, $parent);
}
exit();
} }
/** /**
* Enter description here... * Enter description here...
* *
* @param unknown_type $link_id * @param unknown_type $object A new ACL object. This can be a string for alias-based ACL, or a Model for object-based ACL
* @param unknown_type $parent_id * @param unknown_type $parent The parent object
* @param unknown_type $alias
* @return unknown * @return unknown
*/ */
function create($link_id = 0, $parent_id = null, $alias = '') function create($object = null, $parent = null)
{ {
parent::create();
if (strtolower(get_class($this)) == "aclnode") if (strtolower(get_class($this)) == "aclnode")
{ {
trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR); trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR);
return NULL; return NULL;
} }
parent::create();
pr($this->__dataVars());
exit();
extract($this->__dataVars()); extract($this->__dataVars());
if($parent_id == null || $parent_id === 0) if($parent_id == null || $parent_id === 0)
@ -208,10 +215,10 @@ class AclNode extends AppModel
} }
/** /**
* Enter description here... * The path to a node as an array, where the first element of the array is at the root of the tree, and the last element is the requested node
* *
* @param unknown_type $id * @param mixed $id
* @return unknown * @return array
*/ */
function getPath($id) function getPath($id)
{ {
@ -223,14 +230,18 @@ class AclNode extends AppModel
extract($this->__dataVars()); extract($this->__dataVars());
$item = $this->find($this->_resolveID($id, $secondary_id)); $item = $this->find($this->_resolveID($id, $secondary_id));
if($item == null || count($item) == 0)
{
return null;
}
return $this->findAll("lft <= {$item[$class]['lft']} and rght >= {$item[$class]['rght']}"); return $this->findAll("lft <= {$item[$class]['lft']} and rght >= {$item[$class]['rght']}");
} }
/** /**
* Enter description here... * Gets the child nodes of a specified element
* *
* @param unknown_type $id * @param mixed $id
* @return unknown * @return array
*/ */
function getChildren($id) function getChildren($id)
{ {
@ -246,32 +257,57 @@ class AclNode extends AppModel
} }
/** /**
* Enter description here... * Gets a reference to a node object
* *
* @param unknown_type $id * @param unknown_type $obj
* @param unknown_type $fKey * @param unknown_type $fKey
* @return unknown * @return unknown
*/ */
function _resolveID($id, $fKey) function _resolveID($obj, $fKey)
{ {
extract($this->__dataVars());
if(is_object($obj))
{
if(isset($obj->id) && isset($obj->name))
{
return "model = '{$obj->name}' and {$secondary_id} = {$obj->id}";
}
return null;
}
else if(is_array($obj))
{
$keys = array_keys($obj);
$key1 = $keys[0];
if(is_string($key1) && is_array($obj[$key1]) && isset($obj[$key1]['id']))
{
return "model = '{$key1}' and {$secondary_id} = {$obj[$key1]['id']}";
}
return null;
}
else if(is_string($obj))
{
$path = explode('/', $obj);
}
$key = (is_string($id) ? 'alias' : $fKey); $key = (is_string($id) ? 'alias' : $fKey);
$val = (is_string($id) ? '"' . addslashes($id) . '"' : $id); $val = (is_string($id) ? '"' . addslashes($id) . '"' : $id);
return "{$key} = {$val}"; return "{$key} = {$val}";
} }
/** /**
* Enter description here... * Private method: modifies the left and right values of affected nodes in a tree when a node is added or removed
* *
* @param unknown_type $table * @param string $table aros or acos, depending on the tree to be modified
* @param unknown_type $dir * @param int $dir The direction in which to shift the nodes
* @param unknown_type $lft * @param int $lft The left position of the node being added or removed
* @param unknown_type $rght * @param int $rght The right position of the node being added or removed
*/ */
function _syncTable($table, $dir, $lft, $rght) function _syncTable($table, $dir, $lft, $rght)
{ {
$shift = ($dir == 2 ? 1 : 2); $shift = ($dir == 2 ? 1 : 2);
$this->db->query("UPDATE $table SET rght = rght " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE rght > " . $rght); $table = strtolower($table);
$this->db->query("UPDATE $table SET lft = lft " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE lft > " . $lft); $this->db->query("UPDATE {$table} SET rght = rght " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE rght > " . $rght);
$this->db->query("UPDATE {$table} SET lft = lft " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE lft > " . $lft);
} }
/** /**

View file

@ -39,9 +39,9 @@ define ('APP_DIR', 'app');
define ('DS', DIRECTORY_SEPARATOR); define ('DS', DIRECTORY_SEPARATOR);
define ('ROOT', dirname(__FILE__).DS); define ('ROOT', dirname(__FILE__).DS);
require_once ROOT.'cake'.DS.'basics.php';
require_once ROOT.APP_DIR.DS.'config'.DS.'core.php'; require_once ROOT.APP_DIR.DS.'config'.DS.'core.php';
require_once ROOT.'cake'.DS.'config'.DS.'paths.php'; require_once ROOT.'cake'.DS.'config'.DS.'paths.php';
require_once CAKE.'basics.php';
$uri = setUri(); $uri = setUri();
@ -53,11 +53,12 @@ $uri = setUri();
if ($uri === '/' || $uri === '/index.php') if ($uri === '/' || $uri === '/index.php')
{ {
$_GET['url'] = '/'; $_GET['url'] = '/';
include_once (ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php'); require_once ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php';
} }
else else
{ {
$elements = explode('/index.php', $uri); $elements = explode('/index.php', $uri);
if(!empty($elements[1])) if(!empty($elements[1]))
{ {
$path = $elements[1]; $path = $elements[1];
@ -66,8 +67,9 @@ $uri = setUri();
{ {
$path = '/'; $path = '/';
} }
$_GET['url'] = $path; $_GET['url'] = $path;
include_once (ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php'); require_once ROOT.APP_DIR.DS.WEBROOT_DIR.DS.'index.php';
} }
?> ?>