Merge branch 'master' into OS175-registration-with-verification-token

Conflicts:
	tests/system/edit-settings.rb
This commit is contained in:
AntonyAntonio 2016-12-26 00:27:50 -03:00
commit 4e92a0d7a0
14 changed files with 118 additions and 2 deletions

View File

@ -36,6 +36,25 @@ class EditSettingsController extends Controller {
$settingInstance->store();
}
}
if(Controller::request('allowedLanguages') || Controller::request('supportedLanguages')) {
$this->handleLanguages();
}
Response::respondSuccess();
}
public function handleLanguages() {
$allowed = json_decode(Controller::request('allowedLanguages'));
$supported = json_decode(Controller::request('supportedLanguages'));
foreach(Language::LANGUAGES as $languageCode) {
$language = Language::getDataStore($languageCode, 'code');
$language->allowed = in_array($languageCode, $allowed);
$language->supported = in_array($languageCode, $supported);
$language->store();
}
}
}

View File

@ -19,7 +19,9 @@ class GetSettingsController extends Controller {
'layout' => Setting::getSetting('layout')->getValue(),
'allow-attachments' => Setting::getSetting('allow-attachments')->getValue(),
'max-size' => Setting::getSetting('max-size')->getValue(),
'departments' => Department::getDepartmentNames()
'departments' => Department::getDepartmentNames(),
'supportedLanguages' => Language::getSupportedLanguages(),
'allowedLanguages' => Language::getAllowedLanguages()
]);
}
}

View File

@ -14,6 +14,7 @@ class InitSettingsController extends Controller {
if (Setting::isTableEmpty()) {
$this->storeGlobalSettings();
$this->storeMailTemplates();
$this->storeLanguages();
$this->storeMockedDepartments();
$this->createMockedStaff();
@ -73,6 +74,18 @@ class InitSettingsController extends Controller {
$setting->store();
}
}
private function storeLanguages() {
foreach(Language::LANGUAGES as $languageCode) {
$language = new Language();
$language->setProperties([
'code' => $languageCode,
'allowed' => 1,
'supported' => ($languageCode === 'en')
]);
$language->store();
}
}
private function storeMockedDepartments() {
$departments = [

View File

@ -26,6 +26,10 @@ class CreateController extends Controller {
'departmentId' => [
'validation' => DataValidator::dataStoreId('department'),
'error' => ERRORS::INVALID_DEPARTMENT
],
'language' => [
'validation' => DataValidator::in(Language::getSupportedLanguages()),
'error' => ERRORS::INVALID_LANGUAGE
]
]
];

View File

@ -0,0 +1,47 @@
<?php
use RedBeanPHP\Facade as RedBean;
class Language extends DataStore {
const TABLE = 'language';
const LANGUAGES = [
'en',
'es',
'de',
'fr',
'pr',
'jp',
'ru',
'cn',
'in',
'tr'
];
public static function getProps() {
return [
'code',
'allowed',
'supported'
];
}
public static function getSupportedLanguages() {
$array = [];
foreach(Language::LANGUAGES as $languageCode) {
if (self::getDataStore($languageCode,'code')->supported) {
array_push($array, $languageCode);
}
}
return $array;
}
public static function getAllowedLanguages() {
$array = [];
foreach(Language::LANGUAGES as $languageCode) {
if (self::getDataStore($languageCode,'code')->allowed) {
array_push($array, $languageCode);
}
}
return $array;
}
}

View File

@ -19,7 +19,8 @@ class Ticket extends DataStore {
'author',
'owner',
'ownTicketeventList',
'unreadStaff'
'unreadStaff',
'language'
);
}

View File

@ -37,6 +37,7 @@ class Scripts
title: 'Winter is coming',
content: 'The north remembers',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})

View File

@ -7,6 +7,7 @@ describe 'Retrieve all tickets' do
title: title,
content: 'The north remembers',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})

View File

@ -7,6 +7,7 @@ describe 'system/delete-department' do
title: 'Transferible ticket 1',
content: 'The north remembers',
departmentId: 4,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
@ -14,6 +15,7 @@ describe 'system/delete-department' do
title: 'Transferible ticket 2',
content: 'The north remembers',
departmentId: 4,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
@ -21,6 +23,7 @@ describe 'system/delete-department' do
title: 'Transferible ticket 3',
content: 'The north remembers',
departmentId: 4,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})

View File

@ -7,5 +7,16 @@ describe '/system/get-settings' do
(result['data']['departments'][0]['name']).should.equal('Tech Support')
(result['data']['departments'][1]['name']).should.equal('Suggestions')
(result['data']['departments'][2]['name']).should.equal('Sales and Subscriptions')
(result['data']['allowedLanguages'][0]).should.equal('en')
(result['data']['allowedLanguages'][1]).should.equal('es')
(result['data']['allowedLanguages'][2]).should.equal('de')
(result['data']['allowedLanguages'][3]).should.equal('fr')
(result['data']['allowedLanguages'][4]).should.equal('pr')
(result['data']['allowedLanguages'][5]).should.equal('jp')
(result['data']['allowedLanguages'][6]).should.equal('ru')
(result['data']['allowedLanguages'][7]).should.equal('cn')
(result['data']['allowedLanguages'][8]).should.equal('in')
(result['data']['allowedLanguages'][9]).should.equal('tr')
(result['data']['supportedLanguages'][0]).should.equal('en')
end
end

View File

@ -7,6 +7,7 @@ describe '/ticket/create' do
result = request('/ticket/create', {
title: 'GG',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: 'INVALID_TOKEN'
})
@ -20,6 +21,7 @@ describe '/ticket/create' do
result = request('/ticket/create', {
title: 'GG',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
@ -35,6 +37,7 @@ describe '/ticket/create' do
result = request('/ticket/create',{
title: long_text,
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
@ -48,6 +51,7 @@ describe '/ticket/create' do
title: 'Winter is coming',
content: 'Test',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
@ -64,6 +68,7 @@ describe '/ticket/create' do
title: 'Winter is coming',
content: long_text,
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
@ -78,6 +83,7 @@ describe '/ticket/create' do
title: 'Winter is coming',
content: 'The north remembers',
departmentId: 30,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
@ -92,6 +98,7 @@ describe '/ticket/create' do
title: 'Winter is coming',
content: 'The north remembers',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
@ -116,6 +123,7 @@ describe '/ticket/create' do
title: 'Winter is coming1',
content: 'The north remembers',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
@ -123,6 +131,7 @@ describe '/ticket/create' do
title: 'Winter is coming2',
content: 'The north remembers',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
@ -130,6 +139,7 @@ describe '/ticket/create' do
title: 'Winter is coming3',
content: 'The north remembers',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})

View File

@ -8,6 +8,7 @@ describe 'Ticket Events' do
title: 'Ticket with many events',
content: 'This is a ticket with many events',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})

View File

@ -11,6 +11,7 @@ describe '/ticket/get/' do
title: 'Should we pay?',
content: 'A Lannister always pays his debts.',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})

View File

@ -7,6 +7,8 @@ describe '/user/get' do
title: 'Should we pay?',
content: 'A Lannister always pays his debts.',
departmentId: 1,
language: 'en',
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})