-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding permisions behavior for row level acl
- Loading branch information
1 parent
b354c86
commit c5f6119
Showing
9 changed files
with
669 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2009,2010 Joshua M. McNeese, Curtis J. Beeson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Permissionable Plugin for CakePHP 1.3 | ||
* | ||
* @author Joshua McNeese <jmcneese@gmail.com> | ||
* @author Joe Beeson <jbeeson@gmail.com> | ||
* @license Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php | ||
* @copyright Copyright (c) 2009,2010 Joshua M. McNeese, Curtis J. Beeson | ||
*/ | ||
|
||
/* Summary */ | ||
Provides row level permissions to a CakePHP application that mimic the | ||
UNIX filesystem methods by providing owner, group and other permission | ||
levels. | ||
|
||
/* Usage */ | ||
Attach the behavior to any model that should be controlled. Make | ||
sure that you use the plugin path for the model. | ||
|
||
/* Example */ | ||
class User extends AppModel { | ||
public $actsAs = array('Permissionable.Permissionable'); | ||
} | ||
|
||
/* Requirements */ | ||
PHP5 | ||
CakePHP 1.3.0 | ||
An understanding of UNIX permissions and bitwise operations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/** | ||
* PermissionSchema | ||
* | ||
* Sets user info for PermissionableBehavior | ||
* | ||
* @package permissionable | ||
* @subpackage permissionable.config.schema | ||
* @uses CakeSchema | ||
* @author Joshua McNeese <jmcneese@gmail.com> | ||
* @license Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php | ||
* @copyright Copyright (c) 2009,2010 Joshua M. McNeese, Curtis J. Beeson | ||
*/ | ||
final class PermissionSchema extends CakeSchema { | ||
|
||
public $name = 'Permission'; | ||
|
||
public $permissions = array( | ||
'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), | ||
'model' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 32, 'key' => 'index'), | ||
'foreign_id' => array('type' => 'integer', 'null' => false, 'default' => NULL), | ||
'uid' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'index'), | ||
'gid' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'index'), | ||
'perms' => array('type' => 'integer', 'null' => false, 'default' => '000', 'length' => 3), | ||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'polymorphic_idx' => array('column' => array('model', 'foreign_id'), 'unique' => 0), 'uid_idx' => array('column' => 'uid', 'unique' => 0), 'gid_idx' => array('column' => 'gid', 'unique' => 0)), | ||
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_unicode_ci', 'engine' => 'InnoDB') | ||
); | ||
|
||
} | ||
|
||
?> |
12 changes: 12 additions & 0 deletions
12
extensions/permissionable/config/schema/permissions-uuid.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE `permissions` ( | ||
`id` char(36) NOT NULL, | ||
`model` varchar(32) NOT NULL, | ||
`foreign_id` char(36) NOT NULL, | ||
`uid` char(36) NOT NULL, | ||
`gid` char(36) NOT NULL, | ||
`perms` int(3) unsigned zerofill NOT NULL DEFAULT '000', | ||
PRIMARY KEY (`id`), | ||
KEY `polymorphic_idx` (`model`,`foreign_id`), | ||
KEY `uid_idx` (`uid`), | ||
KEY `gid_idx` (`gid`) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE `permissions` ( | ||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, | ||
`model` varchar(32) NOT NULL, | ||
`foreign_id` int(11) unsigned NOT NULL, | ||
`uid` int(11) unsigned NOT NULL, | ||
`gid` int(11) unsigned NOT NULL, | ||
`perms` int(3) unsigned zerofill NOT NULL DEFAULT '000', | ||
PRIMARY KEY (`id`), | ||
KEY `polymorphic_idx` (`model`,`foreign_id`), | ||
KEY `uid_idx` (`uid`), | ||
KEY `gid_idx` (`gid`) | ||
); |
39 changes: 39 additions & 0 deletions
39
extensions/permissionable/controllers/components/permissionable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* PermissionableComponent | ||
* | ||
* Sets user info for PermissionableBehavior | ||
* | ||
* @package permissionable | ||
* @subpackage permissionable.controllers.components | ||
* @see PermissionableBehavior | ||
* @uses Component | ||
* @author Joshua McNeese <jmcneese@gmail.com> | ||
* @license Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php | ||
* @copyright Copyright (c) 2009,2010 Joshua M. McNeese, Curtis J. Beeson | ||
*/ | ||
final class PermissionableComponent extends Component { | ||
|
||
/** | ||
* @author Joshua McNeese <jmcneese@gmail.com> | ||
* @param object $controller | ||
* @return void | ||
*/ | ||
public function initialize(&$controller) { | ||
|
||
App::import('Lib', 'Permissionable.Permissionable'); | ||
|
||
/** | ||
* set user info here, with: | ||
* | ||
* Permissionable::setUserId(2); | ||
* Permissionable::setGroupId(2); | ||
* Permissionable::setGroupIds(array(3,4)); | ||
*/ | ||
|
||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
/** | ||
* Permissionable | ||
* | ||
* Provides static class app-wide for Permissionable info getting/setting | ||
* | ||
* @package permissionable | ||
* @subpackage permissionable.libs | ||
* @author Joshua McNeese <jmcneese@gmail.com> | ||
*/ | ||
final class Permissionable { | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
public static $user_id = 0; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
public static $group_id = 0; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
public static $group_ids = 0; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
private function __construct() {} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public static function getUserId() { | ||
|
||
return Permissionable::$user_id; | ||
|
||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public static function getGroupId() { | ||
|
||
return Permissionable::$group_id; | ||
|
||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public static function getGroupIds() { | ||
|
||
return Permissionable::$group_ids; | ||
|
||
} | ||
|
||
/** | ||
* @param mixed $user_id | ||
* @return mixed | ||
*/ | ||
public static function setUserId($user_id = null) { | ||
|
||
Permissionable::$user_id = $user_id; | ||
|
||
} | ||
|
||
/** | ||
* @param mixed $group_id | ||
* @return mixed | ||
*/ | ||
public static function setGroupId($group_id = null) { | ||
|
||
Permissionable::$group_id = $group_id; | ||
|
||
} | ||
|
||
/** | ||
* @param mixed $group_ids | ||
* @return mixed | ||
*/ | ||
public static function setGroupIds($group_ids = null) { | ||
|
||
Permissionable::$group_ids = $group_ids; | ||
|
||
} | ||
|
||
} | ||
|
||
?> |
Oops, something went wrong.