Permissions Plugin

This article is also available in the following languages:
By jonbradley
The Permission plugin is a simple variation of the classic ACL permissions structure for the CakePHP framework. This allows a simple flat table lookup to verify if a user has permission to a particular action with-in a controller based upon their group.
##Setup

1. Download the code
git clone git://github.com/jonbradley/CakePHP-Permissions-Plugin.git
2. Add these to your app/config/routes.php
// Permissions Plugin Routes
Router::connect('/groups', array('plugin' => 'permission', 'controller' => 'groups', 'action' => 'index'));
Router::connect('/groups/:action/*', array('plugin' => 'permission', 'controller' => 'groups'));
Router::connect('/privileges/:action/*', array('plugin' => 'permission', 'controller' => 'privileges'));

3. Import the permission.sql into your database
CREATE TABLE `groups` ( 
   `id` varchar(10) NOT NULL,
   `name` varchar(100) NOT NULL DEFAULT '',
   PRIMARY KEY (`name`),
   UNIQUE KEY `name` (`name`)
);

CREATE TABLE `privileges` (
   `id` int(10) NOT NULL AUTO_INCREMENT,
   `controller` varchar(100) DEFAULT NULL,
   `action` varchar(100) DEFAULT NULL,
   `group_id` varchar(10) DEFAULT NULL,
   PRIMARY KEY (`id`)
);

4. Create the following Groups
99 | Admin 
88 | Moderator
77 | User
NULL | Anonymous

Once you have everything done in your application it is recommended that you just do the following to initialize the permissions to ease development issues


5. Add the following to your app/app_controller.php
var $components = array('Permission.Permission');
If you wish to autocreate all the possible privileges for every user group based on your controllers and actions, you can initial the following from the beforeFilter in your app_controller.php
$this->Permission->setPrivileges();

Comments

  • Posted 09/26/10 07:39:37 PM
    Git Repo was fixed, no clue how it was removed. sorry about that.
  • Posted 09/07/10 03:34:27 PM
    First step doesn't werk - Git doesn't exist
    • Posted 09/10/10 12:57:49 PM
      First step doesn't werk - Git doesn't exist
      Anyone know if this is every going to be fixed, or has it just been abandoned? It seems like it is a very useful implementation of auth, but I think this post should be removed if it isn't going do anything.

      Be nice to know where the process is at on this project if someone wouldn't mind taking some time to find out and post it.

Comments are closed for articles over a year old