Improve settings page and move some config parameters to the database
This commit is contained in:
@@ -5,7 +5,6 @@ namespace Controller;
|
||||
use Core\Tool;
|
||||
use Core\Registry;
|
||||
use Core\Security;
|
||||
use Core\Translator;
|
||||
use Model\LastLogin;
|
||||
|
||||
/**
|
||||
@@ -123,12 +122,8 @@ abstract class Base
|
||||
$this->response->hsts();
|
||||
}
|
||||
|
||||
// Load translations
|
||||
$language = $this->config->get('language', 'en_US');
|
||||
if ($language !== 'en_US') Translator::load($language);
|
||||
|
||||
// Set timezone
|
||||
date_default_timezone_set($this->config->get('timezone', 'UTC'));
|
||||
$this->config->setupTranslations();
|
||||
$this->config->setupTimezone();
|
||||
|
||||
// Authentication
|
||||
if (! $this->authentication->isAuthenticated($controller, $action)) {
|
||||
|
||||
@@ -177,8 +177,8 @@ class Board extends Base
|
||||
'categories' => $this->category->getList($project['id'], false),
|
||||
'title' => $project['name'],
|
||||
'no_layout' => true,
|
||||
'auto_refresh' => true,
|
||||
'not_editable' => true,
|
||||
'board_public_refresh_interval' => $this->config->get('board_public_refresh_interval'),
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -238,6 +238,8 @@ class Board extends Base
|
||||
'menu' => 'boards',
|
||||
'title' => $projects[$project['id']],
|
||||
'board_selector' => $board_selector,
|
||||
'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'),
|
||||
'board_highlight_period' => $this->config->get('board_highlight_period'),
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -407,6 +409,8 @@ class Board extends Base
|
||||
'current_project_id' => $project_id,
|
||||
'board' => $this->board->get($project_id),
|
||||
'categories' => $this->category->getList($project_id, false),
|
||||
'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'),
|
||||
'board_highlight_period' => $this->config->get('board_highlight_period'),
|
||||
)),
|
||||
201
|
||||
);
|
||||
@@ -443,6 +447,8 @@ class Board extends Base
|
||||
'current_project_id' => $project_id,
|
||||
'board' => $this->board->get($project_id),
|
||||
'categories' => $this->category->getList($project_id, false),
|
||||
'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'),
|
||||
'board_highlight_period' => $this->config->get('board_highlight_period'),
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,55 +11,114 @@ namespace Controller;
|
||||
class Config extends Base
|
||||
{
|
||||
/**
|
||||
* Display the settings page
|
||||
* Common layout for config views
|
||||
*
|
||||
* @access private
|
||||
* @param string $template Template name
|
||||
* @param array $params Template parameters
|
||||
* @return string
|
||||
*/
|
||||
private function layout($template, array $params)
|
||||
{
|
||||
$params['values'] = $this->config->getAll();
|
||||
$params['errors'] = array();
|
||||
$params['menu'] = 'config';
|
||||
$params['config_content_for_layout'] = $this->template->load($template, $params);
|
||||
|
||||
return $this->template->layout('config_layout', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
if ($this->config->save($values)) {
|
||||
$this->config->reload();
|
||||
$this->session->flash(t('Settings saved successfully.'));
|
||||
}
|
||||
else {
|
||||
$this->session->flashError(t('Unable to save your settings.'));
|
||||
}
|
||||
|
||||
$this->response->redirect('?controller=config&action='.$redirect);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the about page
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->response->html($this->template->layout('config_index', array(
|
||||
$this->response->html($this->layout('config_about', array(
|
||||
'db_size' => $this->config->getDatabaseSize(),
|
||||
'title' => t('About'),
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the application settings page
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function application()
|
||||
{
|
||||
$this->common('application');
|
||||
|
||||
$this->response->html($this->layout('config_application', array(
|
||||
'title' => t('Application settings'),
|
||||
'languages' => $this->config->getLanguages(),
|
||||
'values' => $this->config->getAll(),
|
||||
'errors' => array(),
|
||||
'menu' => 'config',
|
||||
'title' => t('Settings'),
|
||||
'timezones' => $this->config->getTimezones(),
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the board settings page
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function board()
|
||||
{
|
||||
$this->common('board');
|
||||
|
||||
$this->response->html($this->layout('config_board', array(
|
||||
'title' => t('Board settings'),
|
||||
'default_columns' => implode(', ', $this->board->getDefaultColumns()),
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and save settings
|
||||
* Display the webhook settings page
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function save()
|
||||
public function webhook()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->config->validateModification($values);
|
||||
$this->common('webhook');
|
||||
|
||||
if ($valid) {
|
||||
$this->response->html($this->layout('config_webhook', array(
|
||||
'title' => t('Webhook settings'),
|
||||
)));
|
||||
}
|
||||
|
||||
if ($this->config->save($values)) {
|
||||
$this->config->reload();
|
||||
$this->session->flash(t('Settings saved successfully.'));
|
||||
} else {
|
||||
$this->session->flashError(t('Unable to save your settings.'));
|
||||
}
|
||||
|
||||
$this->response->redirect('?controller=config');
|
||||
}
|
||||
|
||||
$this->response->html($this->template->layout('config_index', array(
|
||||
'db_size' => $this->config->getDatabaseSize(),
|
||||
'languages' => $this->config->getLanguages(),
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'menu' => 'config',
|
||||
'title' => t('Settings'),
|
||||
'timezones' => $this->config->getTimezones(),
|
||||
'default_columns' => implode(', ', $this->board->getDefaultColumns()),
|
||||
/**
|
||||
* Display the api settings page
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function api()
|
||||
{
|
||||
$this->response->html($this->layout('config_api', array(
|
||||
'title' => t('API'),
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -89,15 +148,18 @@ class Config extends Base
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate all application tokens
|
||||
* Regenerate webhook token
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function tokens()
|
||||
public function token()
|
||||
{
|
||||
$type = $this->request->getStringParam('type');
|
||||
|
||||
$this->checkCSRFParam();
|
||||
$this->config->regenerateTokens();
|
||||
$this->session->flash(t('All tokens have been regenerated.'));
|
||||
$this->response->redirect('?controller=config');
|
||||
$this->config->regenerateToken($type.'_token');
|
||||
|
||||
$this->session->flash(t('Token regenerated.'));
|
||||
$this->response->redirect('?controller=config&action='.$type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class User extends Base
|
||||
}
|
||||
|
||||
/**
|
||||
* Common layout for project views
|
||||
* Common layout for user views
|
||||
*
|
||||
* @access private
|
||||
* @param string $template Template name
|
||||
|
||||
@@ -17,7 +17,7 @@ class Webhook extends Base
|
||||
*/
|
||||
public function task()
|
||||
{
|
||||
if ($this->config->get('webhooks_token') !== $this->request->getStringParam('token')) {
|
||||
if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) {
|
||||
$this->response->text('Not Authorized', 401);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class Webhook extends Base
|
||||
*/
|
||||
public function github()
|
||||
{
|
||||
if ($this->config->get('webhooks_token') !== $this->request->getStringParam('token')) {
|
||||
if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) {
|
||||
$this->response->text('Not Authorized', 401);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user