From 397246aa4b3e27ac3817a2cc7c3172591ae10573 Mon Sep 17 00:00:00 2001 From: AntonyAntonio Date: Tue, 10 Jan 2017 16:04:25 -0300 Subject: [PATCH] Guillermo - paths enable/disable registration[skip ci] --- server/controllers/system/get-settings.php | 4 +- server/controllers/user/signup.php | 4 ++ tests/init.rb | 2 + tests/system/disable-registration.rb | 43 ++++++++++++++++++++++ tests/system/enable-registration.rb | 33 +++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 tests/system/disable-registration.rb create mode 100644 tests/system/enable-registration.rb diff --git a/server/controllers/system/get-settings.php b/server/controllers/system/get-settings.php index 566110f3..666f0fe8 100644 --- a/server/controllers/system/get-settings.php +++ b/server/controllers/system/get-settings.php @@ -28,9 +28,10 @@ class GetSettingsController extends Controller { 'smtp-port' => Setting::getSetting('smtp-port')->getValue(), 'smtp-host' => Setting::getSetting('smtp-port')->getValue(), 'smtp-user' => Setting::getSetting('smtp-port')->getValue(), + 'registration' => Setting::getSetting('registration')->getValue(), 'departments' => Department::getDepartmentNames(), 'supportedLanguages' => Language::getSupportedLanguages(), - 'allowedLanguages' => Language::getAllowedLanguages() + 'allowedLanguages' => Language::getAllowedLanguages(), ]; } else { $settingsList = [ @@ -42,6 +43,7 @@ class GetSettingsController extends Controller { 'allow-attachments' => Setting::getSetting('allow-attachments')->getValue(), 'max-size' => Setting::getSetting('max-size')->getValue(), 'title' => Setting::getSetting('title')->getValue(), + 'registration' => Setting::getSetting('registration')->getValue(), 'departments' => Department::getDepartmentNames(), 'supportedLanguages' => Language::getSupportedLanguages(), 'allowedLanguages' => Language::getAllowedLanguages() diff --git a/server/controllers/user/signup.php b/server/controllers/user/signup.php index b6ec4d23..72f5e334 100644 --- a/server/controllers/user/signup.php +++ b/server/controllers/user/signup.php @@ -50,6 +50,10 @@ class SignUpController extends Controller { Response::respondError(ERRORS::ALREADY_BANNED); return; } + if (!Setting::getSetting('registration')->value) { + Response::respondError(ERRORS::NO_PERMISSION); + return; + } $userId = $this->createNewUserAndRetrieveId(); $this->sendRegistrationMail(); diff --git a/tests/init.rb b/tests/init.rb index 3eb51877..bb1cdbaa 100644 --- a/tests/init.rb +++ b/tests/init.rb @@ -51,3 +51,5 @@ require './staff/last-events.rb' require './system/get-mail-templates.rb' require './system/edit-mail-template.rb' require './system/recover-mail-template.rb' +require './system/disable-registration.rb' +require './system/enable-registration.rb' diff --git a/tests/system/disable-registration.rb b/tests/system/disable-registration.rb new file mode 100644 index 00000000..13e4c06c --- /dev/null +++ b/tests/system/disable-registration.rb @@ -0,0 +1,43 @@ +describe'/system/disable-registration' do + request('/user/logout') + Scripts.login($staff[:email], $staff[:password], true) + + it 'should not disable registration if password is not correct' do + result= request('/system/disable-registration', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + password: 'hello' + }) + + (result['status']).should.equal('fail') + + row = $database.getRow('setting', 'registration', 'name') + + (row['value']).should.equal('1') + end + + it 'should disable registration' do + result= request('/system/disable-registration', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + password: $staff[:password] + }) + + (result['status']).should.equal('success') + + row = $database.getRow('setting', 'registration', 'name') + + (row['value']).should.equal('0') + end + + it 'should not create user in database if registration is false' do + response = request('/user/signup', { + :name => 'ponzio', + :email => 'jc@ponziolandia.com', + :password => 'tequila' + }) + + (response['status']).should.equal('fail') + + end +end diff --git a/tests/system/enable-registration.rb b/tests/system/enable-registration.rb new file mode 100644 index 00000000..6c87768f --- /dev/null +++ b/tests/system/enable-registration.rb @@ -0,0 +1,33 @@ +describe'/system/enable-registration' do + request('/user/logout') + Scripts.login($staff[:email], $staff[:password], true) + + it 'should not enable registration if password is not correct' do + result= request('/system/enable-registration', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + password: 'hello' + }) + + (result['status']).should.equal('fail') + + row = $database.getRow('setting', 'registration', 'name') + + (row['value']).should.equal('0') + end + + it 'should enable registration' do + result= request('/system/enable-registration', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + password: $staff[:password] + }) + + (result['status']).should.equal('success') + + row = $database.getRow('setting', 'registration', 'name') + + (row['value']).should.equal('1') + end + +end