Updates to Module administration
This commit is contained in:
@@ -22,25 +22,110 @@ class Controller_Admin_Module extends Controller_Module {
|
||||
protected function _methods($class) {
|
||||
// Get a list of methods this module has
|
||||
$ch = 'Controller_%s';
|
||||
$methods = array();
|
||||
$methods = $secure_actions = $auth_required = array();
|
||||
|
||||
// List of classes where all our methods are, including this one.
|
||||
$classes = URL::$method_directory;
|
||||
array_unshift($classes,'');
|
||||
|
||||
foreach ($classes as $c) {
|
||||
$cn = Kohana::classname('Controller_'.$c ? $c.'_'.$class : $class);
|
||||
$x = URL::dir($c);
|
||||
$cn = Kohana::classname('Controller_'.($x ? $x.'_'.$class : $class));
|
||||
|
||||
if (class_exists($cn)) {
|
||||
$r = new ReflectionClass($cn);
|
||||
|
||||
foreach ($r->getMethods() as $method)
|
||||
if (preg_match('/^Controller_(.*_)?'.$class.'$/i',$method->class) AND ! preg_match('/^_/',$method->name))
|
||||
array_push($methods,str_replace('action_',($c ? $c.'_' : $c),$method->name));
|
||||
$rdp = $r->getDefaultProperties();
|
||||
$secure_actions[$cn] = $rdp['secure_actions'];
|
||||
$auth_required[$cn] = $rdp['auth_required'];
|
||||
|
||||
foreach ($r->getMethods() as $method) {
|
||||
if (preg_match('/^action_/',$method->name))
|
||||
array_push($methods,str_replace('action_',strtolower(($x ? $x.'_' : $x)),$method->name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $methods;
|
||||
return array('methods'=>$methods,'secure_actions'=>$secure_actions,'auth_required'=>$auth_required);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a Module Configuration
|
||||
*/
|
||||
public function action_edit() {
|
||||
$id = $this->request->param('id');
|
||||
$mo = ORM::factory('Module',$id);
|
||||
|
||||
$methods = array();
|
||||
|
||||
if (! $mo->loaded()) {
|
||||
SystemMessage::factory()
|
||||
->title(_('Invalid Module ID'))
|
||||
->type('error')
|
||||
->body(sprintf(_('Module with ID %s doesnt appear to exist?'),$id));
|
||||
|
||||
HTTP::redirect(URL::link('admin','module/list'));
|
||||
}
|
||||
|
||||
$mm = $this->_methods($mo->name);
|
||||
$methods['exist'] = array();
|
||||
foreach ($mo->module_method->find_all() as $mmo) {
|
||||
if (in_array($mmo->name,$mm['methods'])) {
|
||||
$k = array_search($mmo->name,$mm['methods']);
|
||||
unset($mm['methods'][$k]);
|
||||
|
||||
$mmo->status('INDB');
|
||||
} else
|
||||
$mmo->status('ORPHAN');
|
||||
|
||||
if (! empty($mm['secure_actions'][$mmo->controller()][$mmo->method()]))
|
||||
unset($mm['secure_actions'][$mmo->controller()][$mmo->method()]);
|
||||
|
||||
array_push($methods['exist'],$mmo);
|
||||
}
|
||||
|
||||
$methods['missing'] = array();
|
||||
foreach ($mm['methods'] as $k=>$method) {
|
||||
$mmo = ORM::factory('Module_Method');
|
||||
$mmo->module_id = $mo->id;
|
||||
$mmo->name = $method;
|
||||
|
||||
if (! empty($mm['auth_required'][$mmo->controller()]) AND $mm['auth_required'][$mmo->controller()])
|
||||
$mmo->status('MISSING');
|
||||
|
||||
array_push($methods['missing'],$mmo);
|
||||
}
|
||||
|
||||
Block::factory()
|
||||
->title(sprintf('%s: %s ',_('Defined Module Methods For'),$mo->display('name')))
|
||||
->title_icon('icon-cog')
|
||||
->body(Table::factory()
|
||||
->data($methods['exist'])
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'name'=>'Name',
|
||||
'notes'=>'Notes',
|
||||
'menu_display'=>'Menu',
|
||||
'status()'=>'Status',
|
||||
))
|
||||
->prepend(array(
|
||||
'id'=>array('url'=>URL::link('admin','module_method/edit/')),
|
||||
))
|
||||
);
|
||||
|
||||
Block::factory()
|
||||
->title(sprintf('%s: %s ',_('Missing Module Methods For'),$mo->display('name')))
|
||||
->title_icon('icon-exclamation-sign')
|
||||
->body(Table::factory()
|
||||
->data($methods['missing'])
|
||||
->columns(array(
|
||||
'name'=>'Name',
|
||||
'status()'=>'Status',
|
||||
))
|
||||
->prepend(array(
|
||||
'name'=>array('url'=>URL::link('admin','module_method/add/'.$mo->id.'/')),
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,82 +134,23 @@ class Controller_Admin_Module extends Controller_Module {
|
||||
public function action_list() {
|
||||
$mo = ORM::factory('Module');
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Defined Modules'),
|
||||
'body'=>Table::display(
|
||||
$mo->find_all(),
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>URL::link('admin','module/edit/')),
|
||||
'name'=>array('label'=>'Name'),
|
||||
'status'=>array('label'=>'Active'),
|
||||
),
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'list',
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a Module Configuration
|
||||
*
|
||||
* @todo Highlight those methods that have security, but the class does not have auth_required set to YES or the method isnt defined in secure_actions
|
||||
*/
|
||||
public function action_edit() {
|
||||
$mid = $this->request->param('id');
|
||||
$mo = ORM::factory('Module',$mid);
|
||||
|
||||
if (! $mo->loaded()) {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Invalid Module ID'),
|
||||
'type'=>'error',
|
||||
'body'=>sprintf(_('Module with ID %s doesnt appear to exist?'),$mid),
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$output = '';
|
||||
$methods = $this->_methods($mo->name);
|
||||
|
||||
// Show methods defined in the DB already.
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s ',_('Defined Module Methods For'),$mo->display('name')),
|
||||
'body'=>Table::display(
|
||||
$mo->module_method->find_all(),
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>URL::link('admin','module_method/edit/')),
|
||||
'name'=>array('label'=>'Name'),
|
||||
'notes'=>array('label'=>'Notes'),
|
||||
'menu_display'=>array('label'=>'Menu'),
|
||||
),
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'list',
|
||||
)),
|
||||
));
|
||||
|
||||
// Show new methods NOT defined in the DB already.
|
||||
foreach ($mo->module_method->find_all() as $meo)
|
||||
if (($method = array_search($meo->name,$methods)) !== false)
|
||||
unset($methods[$method]);
|
||||
|
||||
if (count($methods))
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s ',_('Undefined Module Methods For'),$mo->display('name')),
|
||||
'body'=>Table::display(
|
||||
$methods,
|
||||
25,
|
||||
array(
|
||||
'__VALUE__'=>array('label'=>'Name','url'=>URL::link('admin','module_method/add/'.$mo->id)),
|
||||
),
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'list',
|
||||
)),
|
||||
));
|
||||
Block::factory()
|
||||
->title('Defined Modules')
|
||||
->title_icon('icon-cog')
|
||||
->body(Table::factory()
|
||||
->data($mo->find_all())
|
||||
->jssort(TRUE)
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'name'=>'Name',
|
||||
'notes'=>'Notes',
|
||||
'status(TRUE)'=>'Active',
|
||||
'external(TRUE)'=>'External',
|
||||
))
|
||||
->prepend(array(
|
||||
'id'=>array('url'=>URL::link('admin','module/edit/')),
|
||||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user