Skip to content

Instantly share code, notes, and snippets.

@jaredhoyt
Created February 13, 2011 04:49
Show Gist options
  • Save jaredhoyt/824458 to your computer and use it in GitHub Desktop.
Save jaredhoyt/824458 to your computer and use it in GitHub Desktop.
Example Permissionable usage
<?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'])));
}
}
<?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