Tuesday, January 1, 2013

Create new ACO automatically for CakePHP ACL

If you have been working with CakePHP ACL for quite a while, you might be familiar with the tedious process of creating ACO's manually via command line as soon as you add a new Controller or add any method to an existing controller.

Lets say, your have 10 new Controllers having 4 actions each, you need to run approximately 50 commands on the shell to add all of them to the ACL ( 10 commands for adding each controller ACO, and 1 command each to add 40 controller actions ).

This inspired me to write a CakePHP shell extension which can simplify most of this task for us.  The extension can be downloaded from my github profile link:

https://github.com/codingthoughts/cakephp-aco-check

Usage is pretty simple:

Copy the file AcoCheckShell.php to your cake_install_folder/app/Console/Command folder.
Th extension assumes that you have CakePHP ACL set up properly with DBAcl. All you need to do is run:
Console/cake aco_check
from your app folder. The extension will ask you the name of the root ACO in your ACL setup. After entering this name, the extension scans all your Controllers and actions against the ACL to find which ones are missing in the ACL. It will then display a list of the ACOs missing in the ACL. You also have an option to see command suggestions which you can simply copy and paste in a shell script or the extension can execute them for you.

This saves us from a lot of manual work of figuring out what ACOs are missing in the ACL and then adding them manually.

I hope this extension is helpful for all the fellow developers.

No comments:

Post a Comment