From 0000fe5159053b7d45aaea7584e79658b4668cba Mon Sep 17 00:00:00 2001 From: AntonyAntonio Date: Tue, 13 Dec 2016 02:03:35 -0300 Subject: [PATCH 1/3] Guillermo - path edit-settings[skip ci] --- server/controllers/system.php | 2 + server/controllers/system/edit-settings.php | 78 +++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 server/controllers/system/edit-settings.php diff --git a/server/controllers/system.php b/server/controllers/system.php index 9dd1c3bf..a6a35f37 100644 --- a/server/controllers/system.php +++ b/server/controllers/system.php @@ -1,6 +1,7 @@ setGroupPath('/system'); $systemControllerGroup->addController(new InitSettingsController); $systemControllerGroup->addController(new GetSettingsController); +$systemControllerGroup->addController(new EditSettingsController); $systemControllerGroup->addController(new AddDepartmentController); $systemControllerGroup->addController(new EditDepartmentController); $systemControllerGroup->addController(new DeleteDepartmentController); diff --git a/server/controllers/system/edit-settings.php b/server/controllers/system/edit-settings.php new file mode 100644 index 00000000..65d624a1 --- /dev/null +++ b/server/controllers/system/edit-settings.php @@ -0,0 +1,78 @@ + 'staff_3', + 'requestData' => [ + 'name' => [ + 'validation' => DataValidator::length(4), + 'error' => ERRORS::INVALID_SETTING + ], + ] + ]; + } + + public function handler() { + $this->setting = Setting::getSetting(Controller::request('name')); + $this->editInformation(); + + Response::respondSuccess(); + } + public function editInformation() { + + if(Controller::request('manteniance-mode')) { + $this->setting->manteniance_mode = Controller::request('manteniance-mode'); + } + + if(Controller::request('system-title')) { + $this->setting->system_title = Controller::request('system-title'); + } + + if(Controller::request('timezone')) { + $this->setting->timezone = Controller::request('timezone'); + } + + if(Controller::request('layout')) { + $this->setting->layout = Controller::request('layout'); + } + + if(Controller::request('smtp-server')) { + $this->setting->smtp_server = Controller::request('smtp-server'); + } + + if(Controller::request('smtp-email')) { + $this->setting->smtp_email = Controller::request('smtp-email'); + } + + if(Controller::request('smtp-password')) { + $this->setting->smtp_password = Controller::request('smtp-password'); + } + + if(Controller::request('smtp-port')) { + $this->setting->smtp_port = Controller::request('smtp-port'); + } + + if(Controller::request('default-language')) { + $this->setting->default_language = Controller::request('default-language'); + } + if(Controller::request('recaptcha-public')) { + $this->setting->recaptcha_public = Controller::request('recaptcha-public'); + } + if(Controller::request('recaptcha-private')) { + $this->setting->sharedDepartmentList = Controller::request('recaptcha-private'); + } + if(Controller::request('allow-attachments')) { + $this->setting->allow_attachments = Controller::request('allow-attachments'); + } + if(Controller::request('max-size')) { + $this->setting->max_size = Controller::request('max-size'); + } + $this->setting->store(); + } +} \ No newline at end of file From da2373e013d0170eafc63adf56d93e4990203cf0 Mon Sep 17 00:00:00 2001 From: AntonyAntonio Date: Wed, 14 Dec 2016 22:27:31 -0300 Subject: [PATCH 2/3] Guillermo - path edit-settings[skip ci] --- server/controllers/system/edit-settings.php | 86 ++++++--------------- 1 file changed, 24 insertions(+), 62 deletions(-) diff --git a/server/controllers/system/edit-settings.php b/server/controllers/system/edit-settings.php index 65d624a1..8d30587a 100644 --- a/server/controllers/system/edit-settings.php +++ b/server/controllers/system/edit-settings.php @@ -4,75 +4,37 @@ use Respect\Validation\Validator as DataValidator; class EditSettingsController extends Controller { const PATH = '/edit-settings'; - private $setting; - public function validations() { - return[ + return [ 'permission' => 'staff_3', - 'requestData' => [ - 'name' => [ - 'validation' => DataValidator::length(4), - 'error' => ERRORS::INVALID_SETTING - ], - ] + 'requestData' => [] ]; } public function handler() { - $this->setting = Setting::getSetting(Controller::request('name')); - $this->editInformation(); + $settings = [ + 'manteniance-mode', + 'system-title', + 'timezone', + 'layout', + 'smtp-server', + 'smtp-email', + 'smtp-password', + 'smtp-port', + 'default-language', + 'recaptcha-public', + 'recaptcha-private', + 'allow-attachments', + 'max-size' + ]; + foreach($settings as $setting) { + if(Controller::request($setting)) { + $settingInstance = Setting::getSetting($setting); + $settingInstance->value = Controller::request($setting); + $settingInstance->store(); + } + } Response::respondSuccess(); } - public function editInformation() { - - if(Controller::request('manteniance-mode')) { - $this->setting->manteniance_mode = Controller::request('manteniance-mode'); - } - - if(Controller::request('system-title')) { - $this->setting->system_title = Controller::request('system-title'); - } - - if(Controller::request('timezone')) { - $this->setting->timezone = Controller::request('timezone'); - } - - if(Controller::request('layout')) { - $this->setting->layout = Controller::request('layout'); - } - - if(Controller::request('smtp-server')) { - $this->setting->smtp_server = Controller::request('smtp-server'); - } - - if(Controller::request('smtp-email')) { - $this->setting->smtp_email = Controller::request('smtp-email'); - } - - if(Controller::request('smtp-password')) { - $this->setting->smtp_password = Controller::request('smtp-password'); - } - - if(Controller::request('smtp-port')) { - $this->setting->smtp_port = Controller::request('smtp-port'); - } - - if(Controller::request('default-language')) { - $this->setting->default_language = Controller::request('default-language'); - } - if(Controller::request('recaptcha-public')) { - $this->setting->recaptcha_public = Controller::request('recaptcha-public'); - } - if(Controller::request('recaptcha-private')) { - $this->setting->sharedDepartmentList = Controller::request('recaptcha-private'); - } - if(Controller::request('allow-attachments')) { - $this->setting->allow_attachments = Controller::request('allow-attachments'); - } - if(Controller::request('max-size')) { - $this->setting->max_size = Controller::request('max-size'); - } - $this->setting->store(); - } } \ No newline at end of file From 83edf85f3dbbe2c099ec757c529318544fc4f030 Mon Sep 17 00:00:00 2001 From: AntonyAntonio Date: Mon, 19 Dec 2016 23:17:35 -0300 Subject: [PATCH 3/3] Guillermo - path edit-settings tests[skip ci] --- server/controllers/system/edit-settings.php | 21 ++++---- server/controllers/system/init-settings.php | 2 +- tests/init.rb | 1 + tests/system/edit-settings.rb | 57 +++++++++++++++++++++ 4 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 tests/system/edit-settings.rb diff --git a/server/controllers/system/edit-settings.php b/server/controllers/system/edit-settings.php index 8d30587a..526d83ea 100644 --- a/server/controllers/system/edit-settings.php +++ b/server/controllers/system/edit-settings.php @@ -13,19 +13,20 @@ class EditSettingsController extends Controller { public function handler() { $settings = [ - 'manteniance-mode', - 'system-title', - 'timezone', - 'layout', - 'smtp-server', - 'smtp-email', - 'smtp-password', - 'smtp-port', - 'default-language', + 'language', 'recaptcha-public', 'recaptcha-private', + 'no-reply-email', + 'smtp-host', + 'smtp-port', + 'smtp-user', + 'smtp-pass', + 'time-zone', + 'maintenance-mode', + 'layout', 'allow-attachments', - 'max-size' + 'max-size', + 'system-title' ]; foreach($settings as $setting) { diff --git a/server/controllers/system/init-settings.php b/server/controllers/system/init-settings.php index aaf52287..03797874 100644 --- a/server/controllers/system/init-settings.php +++ b/server/controllers/system/init-settings.php @@ -38,7 +38,7 @@ class InitSettingsController extends Controller { 'layout' => 'boxed', 'allow-attachments' => 0, 'max-size' => 0, - + 'system-title' => 'Support Center' ]); } diff --git a/tests/init.rb b/tests/init.rb index 39acfcba..48ea0c17 100644 --- a/tests/init.rb +++ b/tests/init.rb @@ -11,6 +11,7 @@ require './scripts.rb' # TESTS require './system/init-settings.rb' require './system/get-settings.rb' +require './system/edit-settings.rb' require './user/signup.rb' require './user/login.rb' require './user/send-recover-password.rb' diff --git a/tests/system/edit-settings.rb b/tests/system/edit-settings.rb new file mode 100644 index 00000000..beb96aa1 --- /dev/null +++ b/tests/system/edit-settings.rb @@ -0,0 +1,57 @@ +describe'system/edit-settings' do + request('/user/logout') + Scripts.login($staff[:email], $staff[:password], true) + + it 'should edit settings' do + result= request('/system/edit-settings', { + "csrf_userid" => $csrf_userid, + "csrf_token" => $csrf_token, + "maintenance-mode" => 1, + "time-zone" => -3, + "layout" => 'full-width', + "allow-attachments" => 1, + "max-size" => 2, + "language" => 'es', + "no-reply-email" => 'testemail@hotmail.com', + "smtp-host" => 'www.opensupports.com', + "smtp-port" => 18, + "smtp-user" => 'admin', + "smtp-pass" => 'pass1234', + }) + puts result['message'] + + (result['status']).should.equal('success') + + row = $database.getRow('setting', 'maintenance-mode', 'name') + (row['value']).should.equal('1') + + row = $database.getRow('setting', 'time-zone', 'name') + (row['value']).should.equal('-3') + + row = $database.getRow('setting', 'layout', 'name') + (row['value']).should.equal('full-width') + + row = $database.getRow('setting', 'max-size', 'name') + (row['value']).should.equal('2') + + row = $database.getRow('setting', 'language', 'name') + (row['value']).should.equal('es') + + row = $database.getRow('setting', 'no-reply-email', 'name') + (row['value']).should.equal('testemail@hotmail.com') + + row = $database.getRow('setting', 'smtp-host', 'name') + (row['value']).should.equal('www.opensupports.com') + + row = $database.getRow('setting', 'smtp-port', 'name') + (row['value']).should.equal('18') + + row = $database.getRow('setting', 'smtp-user', 'name') + (row['value']).should.equal('admin') + + row = $database.getRow('setting', 'smtp-pass', 'name') + (row['value']).should.equal('pass1234') + + request('/user/logout') + end +end \ No newline at end of file