Enhancements to group handling
This commit is contained in:
@@ -67,12 +67,11 @@ class Auth_OSB extends Auth_ORM {
|
||||
foreach ($gmo->find_all() as $gm) {
|
||||
$roles .= ($roles ? '|' : '').$gm->group->name;
|
||||
|
||||
$ro = ORM::factory('group', array('name' => $gm->group->name));
|
||||
|
||||
// $ro->id == 0 means all users.
|
||||
if ($ro->id == 0 OR $user->has('group', $ro)) {
|
||||
// $gm->group->id == 0 means all users.
|
||||
if ($gm->group->id == 0 OR $user->has_any('group',$gm->group->list_childgrps(TRUE))) {
|
||||
$status = TRUE;
|
||||
$roles = '';
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -66,18 +66,14 @@ class Model_Account extends Model_Auth_UserDefault {
|
||||
* Get the groups that an account belongs to
|
||||
*/
|
||||
public function groups() {
|
||||
return $this->group->find_all()->as_array();
|
||||
return $this->group->find_all();
|
||||
}
|
||||
|
||||
public function admin() {
|
||||
// @todo Define admins in the config file or DB
|
||||
$admins = array('Root');
|
||||
|
||||
foreach ($this->groups() as $go)
|
||||
if (in_array($go->name,$admins))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
return $this->has($admins);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -12,6 +12,7 @@ class Model_Group extends Model_Auth_RoleDefault {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'account'=>array('through'=>'account_group'),
|
||||
'module_method'=>array('through'=>'group_method','far_key'=>'method_id'),
|
||||
);
|
||||
|
||||
protected $_sorting = array(
|
||||
@@ -36,6 +37,10 @@ class Model_Group extends Model_Auth_RoleDefault {
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* This function will, given a group, list all of the children that
|
||||
* are also related to this group, in the group heirarchy.
|
||||
*/
|
||||
public function list_childgrps($incParent=FALSE) {
|
||||
$return = array();
|
||||
|
||||
@@ -53,5 +58,27 @@ class Model_Group extends Model_Auth_RoleDefault {
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will, given a group, list all of the parent that
|
||||
* are also related to this group, in the group heirarchy.
|
||||
*/
|
||||
public function list_parentgrps($incParent=FALSE) {
|
||||
$return = array();
|
||||
|
||||
if (! $this->loaded())
|
||||
return $return;
|
||||
|
||||
foreach (ORM::factory('group')->where('status','=',1)->and_where('id','=',$this->parent_id)->find_all() as $go) {
|
||||
array_push($return,$go);
|
||||
|
||||
$return = array_merge($return,$go->list_parentgrps());
|
||||
}
|
||||
|
||||
if ($incParent)
|
||||
array_push($return,$this);
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user