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/')),
|
||||
))
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -18,120 +18,95 @@ class Controller_Admin_Module_Method extends Controller_Admin_Module {
|
||||
$method = $this->request->param('sid');
|
||||
|
||||
$mo = ORM::factory('Module',$id);
|
||||
$mmo = ORM::factory('Module_Method');
|
||||
$mm = $this->_methods($mo->name);
|
||||
|
||||
if (! $mo->loaded() OR ! in_array($method,$this->_methods($mo->name)))
|
||||
throw new Kohana_Exception('Method (:method) does not exist in :class',array(':method'=>$method,':class'=>$mo->name));
|
||||
if (! $mo->loaded() OR ! in_array($method,$mm['methods']))
|
||||
HTTP::redirect(URL::link('admin','module/list'));
|
||||
|
||||
$mmo->name = $method;
|
||||
$mmo->module_id = $mo->id;
|
||||
$mmo->values($_POST);
|
||||
if ($_POST) {
|
||||
$mmo = $mo->module_method;
|
||||
$mmo->name = $method;
|
||||
$mmo->module_id = $mo->id;
|
||||
$mmo->values($_POST);
|
||||
|
||||
$output = '';
|
||||
if (! $mmo->check() OR ! $mmo->save())
|
||||
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($_POST)));
|
||||
|
||||
if ($_POST AND $mmo->values($_POST)->check()) {
|
||||
$mmo->save();
|
||||
SystemMessage::factory()
|
||||
->title('Record added')
|
||||
->type('success')
|
||||
->body(_('Method record has been added.'));
|
||||
|
||||
if ($mmo->saved()) {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Method Added'),
|
||||
'type'=>'info',
|
||||
'body'=>sprintf(_('Method %s defined to database'),$mmo->name),
|
||||
));
|
||||
|
||||
HTTP::redirect(URL::link('admin','/module/edit/'.$mo->id));
|
||||
|
||||
} else {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Method Not Saved'),
|
||||
'type'=>'error',
|
||||
'body'=>sprintf(_('Unable to define Method %s to database?'),$mmo->name),
|
||||
));
|
||||
}
|
||||
HTTP::redirect(URL::link('admin','/module/edit/'.$mo->id));
|
||||
}
|
||||
|
||||
$output .= View::factory('module/admin/method_add')
|
||||
->set('module',$mo)
|
||||
->set('method',$mmo);
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf(_('Add Method (%s) to Database for (%s)'),strtoupper($mmo->name),strtoupper($mo->name)),
|
||||
'body'=>$output,
|
||||
));
|
||||
Block::factory()
|
||||
->title(sprintf(_('Add Method (%s) to Database for (%s)'),strtoupper($method),strtoupper($mo->name)))
|
||||
->title_icon('icon-plus-sign')
|
||||
->type('form-horizontal')
|
||||
->body(View::factory('module/method/admin/add')
|
||||
->set('name',$method)
|
||||
->set('o',$mo)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a Module Configuration
|
||||
*
|
||||
* @param int $mid Module ID
|
||||
*/
|
||||
public function action_edit() {
|
||||
$mid = $this->request->param('id');
|
||||
$mmo = ORM::factory('Module_Method',$mid);
|
||||
$id = $this->request->param('id');
|
||||
$mmo = ORM::factory('Module_Method',$id);
|
||||
|
||||
if (! $mmo->loaded()) {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Invalid Method ID'),
|
||||
'type'=>'error',
|
||||
'body'=>sprintf(_('Method with ID %s doesnt appear to exist?'),$mid),
|
||||
));
|
||||
SystemMessage::factory()
|
||||
->title(_('Invalid Method ID'))
|
||||
->type('error')
|
||||
->body(sprintf(_('Method with ID %s doesnt appear to exist?'),$id));
|
||||
|
||||
return;
|
||||
HTTP::redirect(URL::link('admin','module/list'));
|
||||
}
|
||||
|
||||
$output = '';
|
||||
|
||||
// The groups that can run this method.
|
||||
$groups = ORM::factory('Group');
|
||||
|
||||
if ($_POST) {
|
||||
foreach ($groups->find_all() as $go) {
|
||||
$mmo->values($_POST);
|
||||
|
||||
if (! $mmo->check() OR ! $mmo->save())
|
||||
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($_POST)));
|
||||
|
||||
foreach (ORM::factory('Group')->find_all() as $go) {
|
||||
// If the group was defined and no longer
|
||||
if ($mmo->has('group',$go) AND (! isset($_POST['groups']) OR ! in_array($go->id,$_POST['groups']))) {
|
||||
$gm = ORM::factory('Group_Method',array('method_id'=>$mmo->id,'group_id'=>$go->id));
|
||||
$gmo = ORM::factory('Group_Method',array('method_id'=>$mmo->id,'group_id'=>$go->id));
|
||||
|
||||
if (! $gm->delete())
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Unable to DELETE Group Method'),
|
||||
'type'=>'error',
|
||||
'body'=>sprintf(_('Unable to delete Group Method for method %s and group %s'),$mmo->name,$go->name),
|
||||
));
|
||||
if (! $gmo->delete())
|
||||
SystemMessage::factory()
|
||||
->title(_('Unable to DELETE Group Method'))
|
||||
->type('error')
|
||||
->body(sprintf(_('Unable to delete Group Method for method %s and group %s'),$mmo->name,$go->name));
|
||||
|
||||
// If the group was not defined and now is
|
||||
} elseif (! $mmo->has('group',$go) AND isset($_POST['groups']) AND in_array($go->id,$_POST['groups'])) {
|
||||
$gm = ORM::factory('Group_Method')
|
||||
$gmo = ORM::factory('Group_Method')
|
||||
->values(array(
|
||||
'method_id'=>$mmo->id,
|
||||
'group_id'=>$go->id,
|
||||
));
|
||||
|
||||
if (! $gm->check() OR ! $gm->save())
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Unable to SAVE Group Method'),
|
||||
'type'=>'error',
|
||||
'body'=>sprintf(_('Unable to save Group Method for method %s and group %s'),$mmo->name,$go->name),
|
||||
));
|
||||
if (! $gmo->check() OR ! $gmo->save())
|
||||
SystemMessage::factory()
|
||||
->title(_('Unable to SAVE Group Method'))
|
||||
->type('error')
|
||||
->body(sprintf(_('Unable to save Group Method for method %s and group %s'),$mmo->name,$go->name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output .= Form::open();
|
||||
|
||||
$output .= View::factory('module/admin/method_detail_head');
|
||||
foreach ($groups->find_all() as $go) {
|
||||
$output .= View::factory('module/admin/method_detail_body')
|
||||
->set('group',$go)
|
||||
->set('defined',$mmo->has('group',$go));
|
||||
}
|
||||
$output .= View::factory('module/admin/method_detail_foot');
|
||||
|
||||
$output .= '<div>'.Form::submit('submit',_('Update'),array('class'=>'form_button')).'</div>';
|
||||
$output .= Form::close();
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf(_('%s->%s Method'),strtoupper($mmo->module->name),strtoupper($mmo->name)),
|
||||
'body'=>$output,
|
||||
));
|
||||
Block::factory()
|
||||
->title(sprintf(_('Configure access to method (%s::%s)'),$mmo->controller(),$mmo->method()))
|
||||
->title_icon('icon-plus-sign')
|
||||
->type('form')
|
||||
->body(View::factory('module/method/admin/edit')
|
||||
->set('o',$mmo)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -90,7 +90,6 @@ class Controller_Reseller_Account extends Controller_Account {
|
||||
->span(6)
|
||||
->body(Table::factory()
|
||||
->data($ao->service->list_active())
|
||||
->jssort('service')
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'service_name()'=>'Service',
|
||||
|
@@ -22,7 +22,6 @@ class Controller_User_Welcome extends Controller_Welcome {
|
||||
->span(6)
|
||||
->body(Table::factory()
|
||||
->data($this->ao->service->list_active())
|
||||
->jssort('service')
|
||||
->columns(array(
|
||||
'id'=>'ID',
|
||||
'service_name()'=>'Service',
|
||||
|
Reference in New Issue
Block a user