Refactoring: added controlled middleware and changed response class
This commit is contained in:
@@ -8,50 +8,8 @@ namespace Kanboard\Controller;
|
||||
* @package controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Config extends Base
|
||||
class Config extends BaseController
|
||||
{
|
||||
/**
|
||||
* Common method between pages
|
||||
*
|
||||
* @access private
|
||||
* @param string $redirect Action to redirect after saving the form
|
||||
*/
|
||||
private function common($redirect)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$values = $this->request->getValues();
|
||||
|
||||
switch ($redirect) {
|
||||
case 'application':
|
||||
$values += array('password_reset' => 0);
|
||||
break;
|
||||
case 'project':
|
||||
$values += array(
|
||||
'subtask_restriction' => 0,
|
||||
'subtask_time_tracking' => 0,
|
||||
'cfd_include_closed_tasks' => 0,
|
||||
'disable_private_project' => 0,
|
||||
);
|
||||
break;
|
||||
case 'integrations':
|
||||
$values += array('integration_gravatar' => 0);
|
||||
break;
|
||||
case 'calendar':
|
||||
$values += array('calendar_user_subtasks_time_tracking' => 0);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->config->save($values)) {
|
||||
$this->language->loadCurrentLanguage();
|
||||
$this->flash->success(t('Settings saved successfully.'));
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to save your settings.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('config', $redirect));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the about page
|
||||
*
|
||||
@@ -67,6 +25,45 @@ class Config extends Base
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
$redirect = $this->request->getStringParam('redirect', 'application');
|
||||
|
||||
switch ($redirect) {
|
||||
case 'application':
|
||||
$values += array('password_reset' => 0);
|
||||
break;
|
||||
case 'project':
|
||||
$values += array(
|
||||
'subtask_restriction' => 0,
|
||||
'subtask_time_tracking' => 0,
|
||||
'cfd_include_closed_tasks' => 0,
|
||||
'disable_private_project' => 0,
|
||||
);
|
||||
break;
|
||||
case 'integrations':
|
||||
$values += array('integration_gravatar' => 0);
|
||||
break;
|
||||
case 'calendar':
|
||||
$values += array('calendar_user_subtasks_time_tracking' => 0);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->config->save($values)) {
|
||||
$this->language->loadCurrentLanguage();
|
||||
$this->flash->success(t('Settings saved successfully.'));
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to save your settings.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('config', $redirect));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the plugin page
|
||||
*
|
||||
@@ -87,8 +84,6 @@ class Config extends Base
|
||||
*/
|
||||
public function application()
|
||||
{
|
||||
$this->common('application');
|
||||
|
||||
$this->response->html($this->helper->layout->config('config/application', array(
|
||||
'languages' => $this->language->getLanguages(),
|
||||
'timezones' => $this->timezone->getTimezones(),
|
||||
@@ -106,8 +101,6 @@ class Config extends Base
|
||||
*/
|
||||
public function project()
|
||||
{
|
||||
$this->common('project');
|
||||
|
||||
$this->response->html($this->helper->layout->config('config/project', array(
|
||||
'colors' => $this->color->getList(),
|
||||
'default_columns' => implode(', ', $this->board->getDefaultColumns()),
|
||||
@@ -122,8 +115,6 @@ class Config extends Base
|
||||
*/
|
||||
public function board()
|
||||
{
|
||||
$this->common('board');
|
||||
|
||||
$this->response->html($this->helper->layout->config('config/board', array(
|
||||
'title' => t('Settings').' > '.t('Board settings'),
|
||||
)));
|
||||
@@ -136,8 +127,6 @@ class Config extends Base
|
||||
*/
|
||||
public function calendar()
|
||||
{
|
||||
$this->common('calendar');
|
||||
|
||||
$this->response->html($this->helper->layout->config('config/calendar', array(
|
||||
'title' => t('Settings').' > '.t('Calendar settings'),
|
||||
)));
|
||||
@@ -150,8 +139,6 @@ class Config extends Base
|
||||
*/
|
||||
public function integrations()
|
||||
{
|
||||
$this->common('integrations');
|
||||
|
||||
$this->response->html($this->helper->layout->config('config/integrations', array(
|
||||
'title' => t('Settings').' > '.t('Integrations'),
|
||||
)));
|
||||
@@ -164,8 +151,6 @@ class Config extends Base
|
||||
*/
|
||||
public function webhook()
|
||||
{
|
||||
$this->common('webhook');
|
||||
|
||||
$this->response->html($this->helper->layout->config('config/webhook', array(
|
||||
'title' => t('Settings').' > '.t('Webhook settings'),
|
||||
)));
|
||||
@@ -191,7 +176,7 @@ class Config extends Base
|
||||
public function downloadDb()
|
||||
{
|
||||
$this->checkCSRFParam();
|
||||
$this->response->forceDownload('db.sqlite.gz');
|
||||
$this->response->withDownload('db.sqlite.gz');
|
||||
$this->response->binary($this->config->downloadDatabase());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user