Created
February 13, 2011 04:49
-
-
Save jaredhoyt/824458 to your computer and use it in GitHub Desktop.
Example Permissionable usage
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
<?php | |
class Account extends AppModel { | |
var $actsAs = array('Permissionable'); | |
var $hasMany = array( | |
'User' => array('dependent' => true) | |
); | |
function permissions($user) { | |
if ($user['Role']['accounts'] != 'owner') { | |
return false; | |
} | |
# Get list of accounts assigned to | |
$accounts = $this->AccountsContact->find('list', array( | |
'fields' => array('id', 'account_id'), | |
'conditions' => array('AccountsContact.contact_id' => $user['id']) | |
)); | |
# Retrieve master accounts | |
$accounts = array_merge($accounts, $this->find('list', array( | |
'permissions' => false, | |
'fields' => array('id'), | |
'conditions' => array('Account.master' => true) | |
))); | |
return array($this->alias . '.id' =>array_merge($accounts, array($user['account_id']))); | |
} | |
} |
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
<?php | |
class User extends AppModel { | |
var $actsAs = array('Acl' => array('requester'), 'Permissionable'); | |
var $belongsTo = array('Account'); | |
function permissions($user) { | |
if ($user['Role']['accounts'] != 'owner') { | |
return false; | |
} | |
$accounts = $this->Account->getPermissions(); | |
return array($this->alias . '.account_id' => $accounts['Account.id']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment