mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-06 03:22:39 +00:00
Fixing ACL script for new model interface (Ticket #2164)
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5062 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
5b42ca4355
commit
7154feb7c8
1 changed files with 116 additions and 77 deletions
|
@ -94,36 +94,74 @@ class AclShell extends Shell {
|
|||
|
||||
}
|
||||
/**
|
||||
* Enter description here...
|
||||
* Override main() for help message hook
|
||||
*
|
||||
*/
|
||||
function main() {
|
||||
$out = "Available ACL commands:\n";
|
||||
$out .= "\t - create\n";
|
||||
$out .= "\t - delete\n";
|
||||
$out .= "\t - setParent\n";
|
||||
$out .= "\t - getPath\n";
|
||||
$out .= "\t - grant\n";
|
||||
$out .= "\t - deny\n";
|
||||
$out .= "\t - inherit\n";
|
||||
$out .= "\t - view\n";
|
||||
$out .= "\t - initdb\n";
|
||||
$out .= "\t - help\n\n";
|
||||
$out .= "For help, run the 'help' command. For help on a specific command, run 'help <command>'";
|
||||
$this->out($out);
|
||||
}
|
||||
/**
|
||||
* Creates an ARO/ACO node
|
||||
*
|
||||
*/
|
||||
function create() {
|
||||
$this->_checkArgs(4, 'create');
|
||||
$this->_checkArgs(3, 'create');
|
||||
$this->checkNodeType();
|
||||
extract($this->__dataVars());
|
||||
|
||||
if (preg_match('/^([\w]+)\.(.*)$/', $this->args[2], $matches)) {
|
||||
pr($matches);
|
||||
die();
|
||||
$class = ucfirst($this->args[1]);
|
||||
$object = new $class();
|
||||
|
||||
if (preg_match('/^([\w]+)\.(.*)$/', $this->args[2], $matches) && count($matches) == 3) {
|
||||
$parent = array(
|
||||
'model' => $matches[1],
|
||||
'foreign_key' => $matches[2],
|
||||
);
|
||||
} else {
|
||||
$parent = $this->args[2];
|
||||
}
|
||||
|
||||
/*if (!empty($parent)) {
|
||||
$parent = $this->{$class}->node($model, $parent);
|
||||
if (!empty($parent) && $parent != '/' && $parent != 'root') {
|
||||
@$parent = $object->node($parent);
|
||||
if (empty($parent)) {
|
||||
$this->err('Could not find parent node using reference "' . $this->args[2] . '"');
|
||||
return;
|
||||
} else {
|
||||
$parent = Set::extract($parent, "0.{$class}.id");
|
||||
}
|
||||
} else {
|
||||
$parent = null;
|
||||
}*/
|
||||
|
||||
$this->Acl->{$class}->create();
|
||||
if($this->Acl->{$class}->save(array(
|
||||
'parent_id' => Set::extract($parent, "0.{$class}.id"),
|
||||
'model' => null,
|
||||
'foreign_key' => null
|
||||
))) {
|
||||
$this->displayError("Parent Node Not Found", "There was an error creating the ".$class.", probably couldn't find the parent node.\n If you wish to create a new root node, specify the <parent_id> as '0'.");
|
||||
}
|
||||
$this->out("New $class '".$this->args[3]."' created.\n\n");
|
||||
|
||||
if (preg_match('/^([\w]+)\.(.*)$/', $this->args[3], $matches) && count($matches) == 3) {
|
||||
$data = array(
|
||||
'model' => $matches[1],
|
||||
'foreign_key' => $matches[2],
|
||||
);
|
||||
} else {
|
||||
$data = array('alias' => $this->args[3]);
|
||||
}
|
||||
|
||||
$data['parent_id'] = $parent;
|
||||
$object->create();
|
||||
|
||||
if($object->save($data)) {
|
||||
$this->out("New $class '".$this->args[3]."' created.\n\n");
|
||||
} else {
|
||||
$this->err("There was a problem creating a new $class '".$this->args[3]."'.");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Enter description here...
|
||||
|
@ -302,72 +340,73 @@ class AclShell extends Shell {
|
|||
*
|
||||
*/
|
||||
function help() {
|
||||
$out = "Usage: cake acl <command> <arg1> <arg2>...\n";
|
||||
$out .= "-----------------------------------------------\n";
|
||||
$out .= "Commands:\n";
|
||||
$out .= "\n";
|
||||
$out .= "\tcreate aro|aco <parent> <node>\n";
|
||||
$out .= "\t\tCreates a new ACL object <node> under the parent specified by <parent>, an id/alias.\n";
|
||||
$out .= "\t\tThe <parent> and <node> references can be in one of the following formats:\n";
|
||||
$out .= "\t\t\t- <model>.<id> - The node will be bound to a specific record of the given model\n";
|
||||
$out .= "\t\t\t- <alias> - The node will be given a string alias (or path, in the case of <parent>),\n";
|
||||
$out .= "\t\t\t i.e. 'John'. When used with <parent>, this takes the form of an alias path,\n";
|
||||
$out .= "\t\t\t i.e. <group>/<subgroup>/<parent>.\n";
|
||||
$out .= "\n";
|
||||
$out .= "\n";
|
||||
$out .= "\tdelete aro|aco <node>\n";
|
||||
$out .= "\t\tDeletes the ACL object with the given <node> reference (see 'create' for info on node references).\n";
|
||||
$out .= "\n";
|
||||
$out .= "\n";
|
||||
$out .= "\tsetParent aro|aco <node> <parent>\n";
|
||||
$out .= "\t\tMoves the ACL object specified by <node> beneath the parent ACL object specified by <parent>.\n";
|
||||
$out .= "\n";
|
||||
$out .= "\n";
|
||||
$out .= "\tgetPath aro|aco <node>\n";
|
||||
$out .= "\t\tReturns the path to the ACL object specified by <node>. This command is\n";
|
||||
$out .= "\t\tis useful in determining the inhertiance of permissions for a certain\n";
|
||||
$out .= "\t\tobject in the tree.\n";
|
||||
$out .= "\n";
|
||||
$out .= "\n";
|
||||
$out .= "\tgrant <aro_id> <aco_id> [<aco_action>]\n";
|
||||
$out .= "\t\tUse this command to grant ACL permissions. Once executed, the ARO\n";
|
||||
$out .= "\t\tspecified (and its children, if any) will have ALLOW access to the\n";
|
||||
$out .= "\t\tspecified ACO action (and the ACO's children, if any).\n";
|
||||
$out .= "\n";
|
||||
$out .= "\n";
|
||||
$out .= "\tdeny <aro_id> <aco_id> [<aco_action>]\n";
|
||||
$out .= "\t\tUse this command to deny ACL permissions. Once executed, the ARO\n";
|
||||
$out .= "\t\tspecified (and its children, if any) will have DENY access to the\n";
|
||||
$out .= "\t\tspecified ACO action (and the ACO's children, if any).\n";
|
||||
$out .= "\n";
|
||||
$out .= "\n";
|
||||
$out .= "\tinherit <aro_id> <aco_id> [<aco_action>]\n";
|
||||
$out .= "\t\tUse this command to force a child ARO object to inherit its\n";
|
||||
$out .= "\t\tpermissions settings from its parent.\n";
|
||||
$out .= "\n";
|
||||
$out .= "\n";
|
||||
$out .= "\tview aro|aco [<node>]\n";
|
||||
$out .= "\t\tThe view command will return the ARO or ACO tree. The optional\n";
|
||||
$out .= "\t\tid/alias parameter allows you to return only a portion of the requested\n";
|
||||
$out .= "\t\ttree.\n";
|
||||
$out .= "\n";
|
||||
$out .= "\n";
|
||||
$out .= "\tinitdb\n";
|
||||
$out .= "\t\tUse this command to create the database tables needed to use DB ACL.\n";
|
||||
$out .= "\n";
|
||||
$out .= "\n";
|
||||
$out .= "\thelp\n";
|
||||
$out .= "\t\tDisplays this help message.\n";
|
||||
$out .= "\n";
|
||||
$out .= "\n";
|
||||
$this->out($out);
|
||||
$head = "Usage: cake acl <command> <arg1> <arg2>...\n";
|
||||
$head .= "-----------------------------------------------\n";
|
||||
$head .= "Commands:\n\n";
|
||||
|
||||
$commands = array(
|
||||
'create' => "\tcreate aro|aco <parent> <node>\n" .
|
||||
"\t\tCreates a new ACL object <node> under the parent specified by <parent>, an id/alias.\n" .
|
||||
"\t\tThe <parent> and <node> references can be in one of the following formats:\n" .
|
||||
"\t\t\t- <model>.<id> - The node will be bound to a specific record of the given model\n" .
|
||||
"\t\t\t- <alias> - The node will be given a string alias (or path, in the case of <parent>),\n" .
|
||||
"\t\t\t i.e. 'John'. When used with <parent>, this takes the form of an alias path,\n" .
|
||||
"\t\t\t i.e. <group>/<subgroup>/<parent>.\n",
|
||||
|
||||
'delete' => "\tdelete aro|aco <node>\n" .
|
||||
"\t\tDeletes the ACL object with the given <node> reference (see 'create' for info on node references).\n",
|
||||
|
||||
'setparent' => "\tsetParent aro|aco <node> <parent>\n" .
|
||||
"\t\tMoves the ACL object specified by <node> beneath the parent ACL object specified by <parent>.\n",
|
||||
|
||||
'getpath' => "\tgetPath aro|aco <node>\n" .
|
||||
"\t\tReturns the path to the ACL object specified by <node>. This command is\n" .
|
||||
"\t\tis useful in determining the inhertiance of permissions for a certain\n" .
|
||||
"\t\tobject in the tree.\n",
|
||||
|
||||
'grant' => "\tgrant <aro_id> <aco_id> [<aco_action>]\n" .
|
||||
"\t\tUse this command to grant ACL permissions. Once executed, the ARO\n" .
|
||||
"\t\tspecified (and its children, if any) will have ALLOW access to the\n" .
|
||||
"\t\tspecified ACO action (and the ACO's children, if any).\n",
|
||||
|
||||
'deny' => "\tdeny <aro_id> <aco_id> [<aco_action>]\n" .
|
||||
"\t\tUse this command to deny ACL permissions. Once executed, the ARO\n" .
|
||||
"\t\tspecified (and its children, if any) will have DENY access to the\n" .
|
||||
"\t\tspecified ACO action (and the ACO's children, if any).\n",
|
||||
|
||||
'inherit' => "\tinherit <aro_id> <aco_id> [<aco_action>]\n" .
|
||||
"\t\tUse this command to force a child ARO object to inherit its\n" .
|
||||
"\t\tpermissions settings from its parent.\n",
|
||||
|
||||
'view' => "\tview aro|aco [<node>]\n" .
|
||||
"\t\tThe view command will return the ARO or ACO tree. The optional\n" .
|
||||
"\t\tid/alias parameter allows you to return only a portion of the requested\n" .
|
||||
"\t\ttree.\n",
|
||||
|
||||
'initdb' => "\tinitdb\n".
|
||||
"\t\tUse this command to create the database tables needed to use DB ACL.\n",
|
||||
|
||||
'help' => "\thelp [<command>]\n" .
|
||||
"\t\tDisplays this help message, or a message on a specific command.\n"
|
||||
);
|
||||
|
||||
$this->out($head);
|
||||
if (!isset($this->args[1])) {
|
||||
foreach ($commands as $cmd) {
|
||||
$this->out("{$cmd}\n\n");
|
||||
}
|
||||
} elseif (isset($commands[low($this->args[1])])) {
|
||||
$this->out($commands[low($this->args[1])]);
|
||||
} else {
|
||||
$this->out("Command '" . $this->args[1] . "' not found");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
*/
|
||||
function checkNodeType() {
|
||||
if ($this->args[0] != 'aco' && $this->args[0] != 'aro') {
|
||||
if ($this->args[1] != 'aco' && $this->args[1] != 'aro') {
|
||||
$this->displayError("Missing/Unknown node type: '".$this->args[0]."'", 'Please specify which ACL object type you wish to create.');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue