Permissionable Plugin

By Joshua McNeese (jmcneese)
A CakePHP 1.3 plugin that provides UNIX-like row-level permissions for model data.
quite awhile ago i released a behavior that provided row-level access to models, similar to how UNIX filesystems operate. many moons have come and gone since that original code was released, and gone through several iterations. a couple of weeks ago i dusted it off to show it the community in its new form, in the hopes that someone might find it useful.

i'll not go in to huge detail how it works or the greasy underpinnings, since that is covered elsewhere, but i'll give you a summary: the Permissionable plugin provides row-level access control to model records. this is done transparently via a behavior and component combination, provided you follow a couple rules. i encourage you to read the blog posts associated with this incarnation, as well as the previous version of the code, since they explain the hows and whys of what Permissionable is all about.

where to go

latest release: http://jmcneese.wordpress.com/2010/01/28/rmac-is-dead-long-live-rmac/
git repo: http://github.com/jmcneese/permissionable
git project page: http://jmcneese.github.com/permissionable/

how to try it out for yourself:


1. check out the code from github:
Download code $ cd /path/to/your/app/plugins && git clone git://github.com/jmcneese/permissionable.git if you already have your project under git you can do this (it's call sub-tree'ing), or muddle through setting up and using submodules. pick your poison.

2. create the required db table. you can either do this via the SQL files included in permissionable/config/schema (there are two, those who prefer UUID ids, and those who prefer INT), or you can use the schema shell to do this:
Download code $ cake schema create Permissionable.permission
3. take a look at permissionable/controllers/components/permissionable.php. you'll need to include this in the components array for whichever controllers use your permissioned models, or in AppController.

Controller Class:

Download code <?php public $components = array('Permissionable.Permissionable');?> also, you'll need to put some code in the initialize method of the component that sets the id of the logged in user (via AuthComponent or whatever method you use), as well as the group id(s).

4. next up, you'll need to include the behavior in whatever models you want to be permission-controlled:

Model Class:

Download code <?php public $actsAs = array('Permissionable.Permissionable' => array('defaultBits'=>480);?>
note: you need not include the defaultBits option to the behavior, unless you a) know what you are doing, b) can calculate up the proper bits and c) really need to. if any of the above apply, feel free. if you need a refresher course, look here: http://jmcneese.wordpress.com/2009/04/19/rmac-ftw-part-1/

a common example

if you are like most folks, you are using the AuthComponent, have a model called User and another called Group, with User hasAndBelongsToMany Group. for permissionable to work optimally, you should also have a primary group for each user. if you don't already, add a group_id to your users table, and add a belongsTo association to Group in the User model. now, open up app/plugins/permissionable/controllers/components/permissionable.php. there is some commented code showing you how to set user and group ids into the static class. assuming you are using the AuthComponent and that your models are associated as stated above, here's what you'd need to do:

Component Class:

Download code <?php 
$user_id 
$controller->Auth->user('id');
Permissionable::setUserId($user_id);
$group_id $controller->Auth->user('group_id');
Permissionable::setGroupId($group_id);

// if your User model only belongsTo Group, do this:
//
// Permissionable::setGroupIds($group_id);
//
// otherwise, do something to get a list of groups that your user is part of. 
// i cannot give an example, because people will try to cut and paste it, and there are far
// too many ways to go about it.  if you are even attempting to use this plugin
// i assume you know how to get a list of records associated with a particular record.
// once you have that list of group_ids, you just set them to the static class, ala: 
//
// Permissionable::setGroupIds($group_ids);
?>

 

Comments 1422

CakePHP Team Comments Author Comments
 

Comment

1 Awesome

I must say that this one is really unique one and hope that in future this one is going to be very useful.

Lets see.

Online Payroll
Posted May 10, 2010 by Andrew Jack
 

Comment

2 good post

Pretty good post. I just stumbled upon your blog and wanted to say that I have really Boost Your Page Rank enjoyed reading your blog posts xscityclub.Any way Ill be subscribing to your feed and I hope you post again soon.xsmedia
Posted Jul 13, 2010 by Alice
 

Comment

3 perspective online Auction

Thank you for providing the perspective Online Auction. I just read a part of the article,Bidding competition so I don't know much what to say. Good luck for the new member!
Posted Jul 13, 2010 by Jennifar
 

Comment

4 Permissionable Plugins and Zend PHP

Permissionable Plugins like this make the whole world of Cake PHP a lot easier. In a great deal of ways, it integrates zend coupons with openpress to provide a comprehensive PHP solution.
Posted Jul 13, 2010 by Sylfaen
 

Comment

5 Good to enough

I am hopeful about the programs that it will become the favorite for every user.
nursing scrubs
Posted Jul 14, 2010 by Monna Enny
 

Comment

6 thanks

Only one draw back, I feel compelled to wash the smoke smell from my hair after an episode. Season 4 where are you?BMW Accessories
Posted Jul 14, 2010 by Jim
 

Comment

7 lol

yeah, bring on another season - I need a fix!
michigan mortgage rates
Posted Jul 15, 2010 by jim jones
 

Comment

8 Thank you

Adding static variables to hold root user and group id. Deprecated _isRoot and moved it to a static function. Added tests
baby clothes
Posted Jul 17, 2010 by James smilth
 

Comment

9 thank you

I hope you find this component useful. If you like the component, find a bug, or have a feature request please post a comment.

Thanks,
Porno izle
Posted Jul 17, 2010 by ahmet
 

Comment

10 Excellent

This is a great program. I am going to check out the latest release and get the plug in.

Youtube MP3,Youtube to MP3 online,Convert Youtube to Mp3

Posted Jul 17, 2010 by Mike Thomas
 

Comment

11 Excellent.

"Your Post is very useful, I am truly happy to post my note on this blog It helped me with.ocean of awareness so I really consider you will do much better in the future. logo design
Posted Jul 19, 2010 by summer bell
 

Comment

12 d

I must say that this one is really unique one and hope that in future this one is going to be very useful.

Lets see.
Convert Miles To Inches
Posted Jul 19, 2010 by Mike
 

Comment

13 Impressive

it is very helpful to create the application which provide the simple facility like web services Ex: product info,price info etc.
enclosed trailers
Posted Jul 21, 2010 by badil
 

Comment

14 ed

Because a small minority of us have seen the beleivable way to improve that after awhile that it starts to look like the solution this morning. vehicle transport Yes, you can be talked about school.
Posted Jul 22, 2010 by dan kaylee
 

Comment

15 Cake plugin

I think it's great you're reviving the old girl!
Seth - Contractor Marketing
Posted Jul 24, 2010 by Seth Larrabee
   

Comment

17 Code

Great code and plug-in. Very helpful.
cheap contact lenses
Posted Jul 29, 2010 by Susanne
 

Comment

18 CakePhp

Thanks for the introduction. It was indeed useful.
resize partition with free partition software | convert ntfs to fat32
Posted Jul 30, 2010 by jackam
 

Comment

19 Complication

I don,t understand about the blog because lot of software described in complicated way.
online fax
Posted Jul 31, 2010 by fernando torrus
 

Comment

20 burmeh yaza lida fx15 biber hapı ile formda girin

Posted Jul 31, 2010 by Fatih
 

Comment

21 hi.........

this is a very useful blog for the upcoming businesses .Hydraulic jacks the points that are listed are grea .Hydraulic jacks For any business goal setting and developing a plan are very essential and are the basis for the success.i will be applying these tips in my business .Hydraulic jack thank you.
Posted Jul 31, 2010 by jini