Started with acl
This commit is contained in:
parent
f21f1599bc
commit
6b9366db54
3 changed files with 86 additions and 53 deletions
70
application/Acl.php
Normal file
70
application/Acl.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
class Acl extends Zend_Acl
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// Add roles
|
||||
$this->loadRoles();
|
||||
|
||||
// Add resources
|
||||
$this->loadResources();
|
||||
|
||||
// Set accessrights
|
||||
$this->loadAccess();
|
||||
}
|
||||
|
||||
|
||||
protected function loadRoles()
|
||||
{
|
||||
|
||||
$this->addRole(new Zend_Acl_Role('visitor'));
|
||||
$this->addRole(new Zend_Acl_Role('member'), 'visitor');
|
||||
$this->addRole(new Zend_Acl_Role('team'), 'member');
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function loadResources()
|
||||
{
|
||||
$this->add(new Zend_Acl_Resource('blog'));
|
||||
$this->add(new Zend_Acl_Resource('profile'));
|
||||
$this->add(new Zend_Acl_Resource('admin'));
|
||||
}
|
||||
|
||||
|
||||
protected function loadAccess()
|
||||
{
|
||||
// Set default rules
|
||||
$this->_setDefaultAccess();
|
||||
|
||||
// Blog
|
||||
$this->allow('member', 'blog', 'comment');
|
||||
|
||||
// Profile
|
||||
$this->deny('visitor','profile','read');
|
||||
|
||||
// Admin
|
||||
$this->allow('team', 'admin', array('read', 'write', 'delete'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function _setDefaultAccess()
|
||||
{
|
||||
$defaults = array(
|
||||
'visitor' => array('read'),
|
||||
'member' => array('read'),
|
||||
'team' => array('read','write', 'delete')
|
||||
);
|
||||
|
||||
foreach ($defaults as $role => $privileges) {
|
||||
|
||||
foreach ($this->getResources() as $resource) {
|
||||
|
||||
$this->allow($role,$resource,$privileges);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
require_once APPLICATION_PATH . '/Acl.php';
|
||||
|
||||
/**
|
||||
* Bootstrap this shit
|
||||
*/
|
||||
|
|
@ -278,6 +281,19 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
|||
return $defaultNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load accessrights
|
||||
*/
|
||||
protected function _initAcl()
|
||||
{
|
||||
$acl = new Acl();
|
||||
|
||||
Zend_Registry::set('Zend_Acl', $acl);
|
||||
|
||||
return $acl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is just a temporary.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Fiktiv_Acl extends Zend_Acl
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// Add roles
|
||||
$this->loadRoles();
|
||||
|
||||
// Add resources
|
||||
$this->loadResources();
|
||||
|
||||
// Set accessrights
|
||||
$this->loadAccess();
|
||||
}
|
||||
|
||||
|
||||
protected function loadRoles()
|
||||
{
|
||||
// "Public" roles
|
||||
$this->addRole(new Zend_Acl_Role('visitor'));
|
||||
$this->addRole(new Zend_Acl_Role('member'), 'visitor');
|
||||
|
||||
// Blog roles
|
||||
$this->addRole(new Zend_Acl_Role('blogWriter'), 'member');
|
||||
$this->addRole(new Zend_Acl_Role('blogManager'), 'blogWriter');
|
||||
|
||||
// "Projects" roles (for future use)
|
||||
$this->addRole(new Zend_Acl_Role('projectUser'), 'member');
|
||||
$this->addRole(new Zend_Acl_Role('projectManager'), 'projectUser');
|
||||
|
||||
// ...
|
||||
$this->addRole(new Zend_Acl_Role('team'), array('blogManager', 'projectManager'));
|
||||
}
|
||||
|
||||
|
||||
protected function loadResources()
|
||||
{
|
||||
$this->add(new Zend_Acl_Resource('blog'));
|
||||
}
|
||||
|
||||
|
||||
protected function loadAccess()
|
||||
{
|
||||
// Blog
|
||||
$this->allow('visitor', 'blog', 'readBlog');
|
||||
$this->allow('visitor', 'blog', 'readComment');
|
||||
|
||||
$this->allow('blogWriter', 'blog', 'writeBlog');
|
||||
$this->allow('member', 'blog', 'writeComment');
|
||||
|
||||
}
|
||||
}
|
||||
Reference in a new issue