mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
Merged in OS-132-add-supported-lenguages (pull request #101)
OS-132 add supported lenguages
This commit is contained in:
commit
bac7ea444e
@ -36,6 +36,25 @@ class EditSettingsController extends Controller {
|
|||||||
$settingInstance->store();
|
$settingInstance->store();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Controller::request('allowedLanguages') || Controller::request('supportedLanguages')) {
|
||||||
|
$this->handleLanguages();
|
||||||
|
}
|
||||||
Response::respondSuccess();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -19,7 +19,9 @@ class GetSettingsController extends Controller {
|
|||||||
'layout' => Setting::getSetting('layout')->getValue(),
|
'layout' => Setting::getSetting('layout')->getValue(),
|
||||||
'allow-attachments' => Setting::getSetting('allow-attachments')->getValue(),
|
'allow-attachments' => Setting::getSetting('allow-attachments')->getValue(),
|
||||||
'max-size' => Setting::getSetting('max-size')->getValue(),
|
'max-size' => Setting::getSetting('max-size')->getValue(),
|
||||||
'departments' => Department::getDepartmentNames()
|
'departments' => Department::getDepartmentNames(),
|
||||||
|
'supportedLanguages' => Language::getSupportedLanguages(),
|
||||||
|
'allowedLanguages' => Language::getAllowedLanguages()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,6 +14,7 @@ class InitSettingsController extends Controller {
|
|||||||
if (Setting::isTableEmpty()) {
|
if (Setting::isTableEmpty()) {
|
||||||
$this->storeGlobalSettings();
|
$this->storeGlobalSettings();
|
||||||
$this->storeMailTemplates();
|
$this->storeMailTemplates();
|
||||||
|
$this->storeLanguages();
|
||||||
$this->storeMockedDepartments();
|
$this->storeMockedDepartments();
|
||||||
$this->createMockedStaff();
|
$this->createMockedStaff();
|
||||||
|
|
||||||
@ -73,6 +74,18 @@ class InitSettingsController extends Controller {
|
|||||||
$setting->store();
|
$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() {
|
private function storeMockedDepartments() {
|
||||||
$departments = [
|
$departments = [
|
||||||
|
@ -26,6 +26,10 @@ class CreateController extends Controller {
|
|||||||
'departmentId' => [
|
'departmentId' => [
|
||||||
'validation' => DataValidator::dataStoreId('department'),
|
'validation' => DataValidator::dataStoreId('department'),
|
||||||
'error' => ERRORS::INVALID_DEPARTMENT
|
'error' => ERRORS::INVALID_DEPARTMENT
|
||||||
|
],
|
||||||
|
'language' => [
|
||||||
|
'validation' => DataValidator::in(Language::getSupportedLanguages()),
|
||||||
|
'error' => ERRORS::INVALID_LANGUAGE
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
47
server/models/Language.php
Normal file
47
server/models/Language.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -19,7 +19,8 @@ class Ticket extends DataStore {
|
|||||||
'author',
|
'author',
|
||||||
'owner',
|
'owner',
|
||||||
'ownTicketeventList',
|
'ownTicketeventList',
|
||||||
'unreadStaff'
|
'unreadStaff',
|
||||||
|
'language'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ class Scripts
|
|||||||
title: 'Winter is coming',
|
title: 'Winter is coming',
|
||||||
content: 'The north remembers',
|
content: 'The north remembers',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
|
@ -7,6 +7,7 @@ describe 'Retrieve all tickets' do
|
|||||||
title: title,
|
title: title,
|
||||||
content: 'The north remembers',
|
content: 'The north remembers',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
|
@ -7,6 +7,7 @@ describe 'system/delete-department' do
|
|||||||
title: 'Transferible ticket 1',
|
title: 'Transferible ticket 1',
|
||||||
content: 'The north remembers',
|
content: 'The north remembers',
|
||||||
departmentId: 4,
|
departmentId: 4,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
@ -14,6 +15,7 @@ describe 'system/delete-department' do
|
|||||||
title: 'Transferible ticket 2',
|
title: 'Transferible ticket 2',
|
||||||
content: 'The north remembers',
|
content: 'The north remembers',
|
||||||
departmentId: 4,
|
departmentId: 4,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
@ -21,6 +23,7 @@ describe 'system/delete-department' do
|
|||||||
title: 'Transferible ticket 3',
|
title: 'Transferible ticket 3',
|
||||||
content: 'The north remembers',
|
content: 'The north remembers',
|
||||||
departmentId: 4,
|
departmentId: 4,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
|
@ -18,7 +18,6 @@ describe'system/edit-settings' do
|
|||||||
"smtp-user" => 'admin',
|
"smtp-user" => 'admin',
|
||||||
"smtp-pass" => 'pass1234',
|
"smtp-pass" => 'pass1234',
|
||||||
})
|
})
|
||||||
puts result['message']
|
|
||||||
|
|
||||||
(result['status']).should.equal('success')
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
@ -52,6 +51,48 @@ describe'system/edit-settings' do
|
|||||||
row = $database.getRow('setting', 'smtp-pass', 'name')
|
row = $database.getRow('setting', 'smtp-pass', 'name')
|
||||||
(row['value']).should.equal('pass1234')
|
(row['value']).should.equal('pass1234')
|
||||||
|
|
||||||
|
request('/user/logout')
|
||||||
|
end
|
||||||
|
it 'should change allowed and supported languages' do
|
||||||
|
request('/user/logout')
|
||||||
|
Scripts.login($staff[:email], $staff[:password], true)
|
||||||
|
|
||||||
|
result= request('/system/edit-settings', {
|
||||||
|
"csrf_userid" => $csrf_userid,
|
||||||
|
"csrf_token" => $csrf_token,
|
||||||
|
"supportedLanguages" => '["en", "pr", "jp", "ru"]',
|
||||||
|
"allowedLanguages" => '["en","pr", "jp", "ru", "de"]'
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
|
row = $database.getRow('language', 'en', 'code')
|
||||||
|
(row['supported']).should.equal('1')
|
||||||
|
|
||||||
|
row = $database.getRow('language', 'pr', 'code')
|
||||||
|
(row['supported']).should.equal('1')
|
||||||
|
|
||||||
|
row = $database.getRow('language', 'jp', 'code')
|
||||||
|
(row['supported']).should.equal('1')
|
||||||
|
|
||||||
|
row = $database.getRow('language', 'ru', 'code')
|
||||||
|
(row['supported']).should.equal('1')
|
||||||
|
|
||||||
|
row = $database.getRow('language', 'en', 'code')
|
||||||
|
(row['allowed']).should.equal('1')
|
||||||
|
|
||||||
|
row = $database.getRow('language', 'pr', 'code')
|
||||||
|
(row['allowed']).should.equal('1')
|
||||||
|
|
||||||
|
row = $database.getRow('language', 'jp', 'code')
|
||||||
|
(row['allowed']).should.equal('1')
|
||||||
|
|
||||||
|
row = $database.getRow('language', 'ru', 'code')
|
||||||
|
(row['allowed']).should.equal('1')
|
||||||
|
|
||||||
|
row = $database.getRow('language', 'de', 'code')
|
||||||
|
(row['allowed']).should.equal('1')
|
||||||
|
|
||||||
request('/user/logout')
|
request('/user/logout')
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -7,5 +7,16 @@ describe '/system/get-settings' do
|
|||||||
(result['data']['departments'][0]['name']).should.equal('Tech Support')
|
(result['data']['departments'][0]['name']).should.equal('Tech Support')
|
||||||
(result['data']['departments'][1]['name']).should.equal('Suggestions')
|
(result['data']['departments'][1]['name']).should.equal('Suggestions')
|
||||||
(result['data']['departments'][2]['name']).should.equal('Sales and Subscriptions')
|
(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
|
||||||
end
|
end
|
@ -7,6 +7,7 @@ describe '/ticket/create' do
|
|||||||
result = request('/ticket/create', {
|
result = request('/ticket/create', {
|
||||||
title: 'GG',
|
title: 'GG',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: 'INVALID_TOKEN'
|
csrf_token: 'INVALID_TOKEN'
|
||||||
})
|
})
|
||||||
@ -20,6 +21,7 @@ describe '/ticket/create' do
|
|||||||
result = request('/ticket/create', {
|
result = request('/ticket/create', {
|
||||||
title: 'GG',
|
title: 'GG',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
@ -35,6 +37,7 @@ describe '/ticket/create' do
|
|||||||
result = request('/ticket/create',{
|
result = request('/ticket/create',{
|
||||||
title: long_text,
|
title: long_text,
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
@ -48,6 +51,7 @@ describe '/ticket/create' do
|
|||||||
title: 'Winter is coming',
|
title: 'Winter is coming',
|
||||||
content: 'Test',
|
content: 'Test',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
@ -64,6 +68,7 @@ describe '/ticket/create' do
|
|||||||
title: 'Winter is coming',
|
title: 'Winter is coming',
|
||||||
content: long_text,
|
content: long_text,
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
@ -78,6 +83,7 @@ describe '/ticket/create' do
|
|||||||
title: 'Winter is coming',
|
title: 'Winter is coming',
|
||||||
content: 'The north remembers',
|
content: 'The north remembers',
|
||||||
departmentId: 30,
|
departmentId: 30,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
@ -92,6 +98,7 @@ describe '/ticket/create' do
|
|||||||
title: 'Winter is coming',
|
title: 'Winter is coming',
|
||||||
content: 'The north remembers',
|
content: 'The north remembers',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
@ -116,6 +123,7 @@ describe '/ticket/create' do
|
|||||||
title: 'Winter is coming1',
|
title: 'Winter is coming1',
|
||||||
content: 'The north remembers',
|
content: 'The north remembers',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
@ -123,6 +131,7 @@ describe '/ticket/create' do
|
|||||||
title: 'Winter is coming2',
|
title: 'Winter is coming2',
|
||||||
content: 'The north remembers',
|
content: 'The north remembers',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
@ -130,6 +139,7 @@ describe '/ticket/create' do
|
|||||||
title: 'Winter is coming3',
|
title: 'Winter is coming3',
|
||||||
content: 'The north remembers',
|
content: 'The north remembers',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
|
@ -8,6 +8,7 @@ describe 'Ticket Events' do
|
|||||||
title: 'Ticket with many events',
|
title: 'Ticket with many events',
|
||||||
content: 'This is a ticket with many events',
|
content: 'This is a ticket with many events',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
|
@ -11,6 +11,7 @@ describe '/ticket/get/' do
|
|||||||
title: 'Should we pay?',
|
title: 'Should we pay?',
|
||||||
content: 'A Lannister always pays his debts.',
|
content: 'A Lannister always pays his debts.',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
|
@ -7,6 +7,8 @@ describe '/user/get' do
|
|||||||
title: 'Should we pay?',
|
title: 'Should we pay?',
|
||||||
content: 'A Lannister always pays his debts.',
|
content: 'A Lannister always pays his debts.',
|
||||||
departmentId: 1,
|
departmentId: 1,
|
||||||
|
language: 'en',
|
||||||
|
language: 'en',
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
csrf_token: $csrf_token
|
csrf_token: $csrf_token
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user