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..526d83ea --- /dev/null +++ b/server/controllers/system/edit-settings.php @@ -0,0 +1,41 @@ + 'staff_3', + 'requestData' => [] + ]; + } + + public function handler() { + $settings = [ + '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', + 'system-title' + ]; + + foreach($settings as $setting) { + if(Controller::request($setting)) { + $settingInstance = Setting::getSetting($setting); + $settingInstance->value = Controller::request($setting); + $settingInstance->store(); + } + } + Response::respondSuccess(); + } +} \ No newline at end of file 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