fixed locale check

This commit is contained in:
Denis Duliçi 2023-11-06 17:56:14 +03:00
parent 08f22cc24b
commit b95723d576
8 changed files with 56 additions and 53 deletions

View File

@ -99,7 +99,7 @@ abstract class SettingController extends Controller
}
if ($real_key == 'default.locale') {
if (!in_array($value, config('language.allowed'))) {
if (! in_array($value, config('language.allowed'))) {
continue;
}
@ -109,7 +109,7 @@ abstract class SettingController extends Controller
if ($real_key == 'default.currency') {
$currencies = Currency::enabled()->pluck('code')->toArray();
if (!in_array($value, $currencies)) {
if (! in_array($value, $currencies)) {
continue;
}
@ -149,39 +149,25 @@ abstract class SettingController extends Controller
return response()->json($response);
}
protected function oneCompany($real_key, $value)
protected function oneCompany($real_key, $value): void
{
switch ($real_key) {
case 'company.name':
Installer::updateEnv(['MAIL_FROM_NAME' => '"' . $value . '"']);
break;
case 'company.email':
Installer::updateEnv(['MAIL_FROM_ADDRESS' => '"' . $value . '"']);
break;
case 'default.locale':
Installer::updateEnv(['APP_LOCALE' => '"' . $value . '"']);
break;
case 'schedule.time':
Installer::updateEnv(['APP_SCHEDULE_TIME' => '"' . $value . '"']);
break;
case 'email.protocol':
Installer::updateEnv(['MAIL_MAILER' => '"' . $value . '"']);
break;
case 'email.smtp_host':
Installer::updateEnv(['MAIL_HOST' => '"' . $value . '"']);
break;
case 'email.smtp_port':
Installer::updateEnv(['MAIL_PORT' => '"' . $value . '"']);
break;
case 'email.smtp_username':
Installer::updateEnv(['MAIL_USERNAME' => '"' . $value . '"']);
break;
case 'email.smtp_password':
Installer::updateEnv(['MAIL_PASSWORD' => '"' . $value . '"']);
break;
case 'email.smtp_encryption':
Installer::updateEnv(['MAIL_ENCRYPTION' => '"' . $value . '"']);
break;
$key = match($real_key) {
'default.locale' => 'APP_LOCALE',
'schedule.time' => 'APP_SCHEDULE_TIME',
'company.name' => 'MAIL_FROM_NAME',
'company.email' => 'MAIL_FROM_ADDRESS',
'email.protocol' => 'MAIL_MAILER',
'email.smtp_host' => 'MAIL_HOST',
'email.smtp_port' => 'MAIL_PORT',
'email.smtp_username' => 'MAIL_USERNAME',
'email.smtp_password' => 'MAIL_PASSWORD',
'email.smtp_encryption' => 'MAIL_ENCRYPTION',
};
if (empty($key)) {
return;
}
Installer::updateEnv([$key => '"' . $value . '"']);
}
}

View File

@ -76,19 +76,12 @@ class Companies extends Controller
continue;
}
switch ($key) {
case 'api_key':
$real_key = 'apps.' . $key;
break;
case 'financial_start':
$real_key = 'localisation.' . $key;
break;
case 'country':
$real_key = 'company.' . $key;
break;
default:
$real_key = 'company.' . $key;
}
$real_key = match($key) {
'api_key' => 'apps.api_key',
'financial_start' => 'localisation.financial_start',
'locale' => 'default.locale',
default => 'company.' . $key,
};
// change dropzone middleware already uploaded file
if (in_array($real_key, $uploaded_file_keys)) {
@ -112,6 +105,14 @@ class Companies extends Controller
}
}
if ($real_key == 'default.locale') {
if (! in_array($value, config('language.allowed'))) {
continue;
}
user()->setAttribute('locale', $value)->save();
}
setting()->set($real_key, $value);
}

View File

@ -26,7 +26,7 @@ class DisableModule extends Job
public function __construct($alias, $company_id, $locale = null)
{
$this->alias = $alias;
$this->company_id = $company_id;
$this->company_id = (int) $company_id;
$this->locale = $locale ?: company($company_id)->locale;
}
@ -58,5 +58,9 @@ class DisableModule extends Job
if (! $this->moduleExists($this->alias)) {
throw new \Exception("Module [{$this->alias}] not found.");
}
if (! in_array($this->locale, config('language.allowed'))) {
throw new \Exception("Unknown locale: {$this->locale}");
}
}
}

View File

@ -20,7 +20,7 @@ class DownloadModule extends Job
public function __construct($alias, $company_id)
{
$this->alias = $alias;
$this->company_id = $company_id;
$this->company_id = (int) $company_id;
}
/**

View File

@ -26,7 +26,7 @@ class EnableModule extends Job
public function __construct($alias, $company_id, $locale = null)
{
$this->alias = $alias;
$this->company_id = $company_id;
$this->company_id = (int) $company_id;
$this->locale = $locale ?: company($company_id)->locale;
}
@ -56,5 +56,9 @@ class EnableModule extends Job
if (! $this->moduleExists($this->alias)) {
throw new \Exception("Module [{$this->alias}] not found.");
}
if (! in_array($this->locale, config('language.allowed'))) {
throw new \Exception("Unknown locale: {$this->locale}");
}
}
}

View File

@ -37,7 +37,7 @@ class FinishUpdate extends Job
$this->alias = $alias;
$this->new = $new;
$this->old = $old;
$this->company_id = $company_id;
$this->company_id = (int) $company_id;
}
public function handle(): void

View File

@ -26,7 +26,7 @@ class InstallModule extends Job
public function __construct($alias, $company_id, $locale = null)
{
$this->alias = $alias;
$this->company_id = $company_id;
$this->company_id = (int) $company_id;
$this->locale = $locale ?: company($company_id)->locale;
}
@ -58,5 +58,9 @@ class InstallModule extends Job
if (! $this->moduleExists($this->alias)) {
throw new \Exception("Module [{$this->alias}] not found.");
}
if (! in_array($this->locale, config('language.allowed'))) {
throw new \Exception("Unknown locale: {$this->locale}");
}
}
}

View File

@ -26,7 +26,7 @@ class UninstallModule extends Job
public function __construct($alias, $company_id, $locale = null)
{
$this->alias = $alias;
$this->company_id = $company_id;
$this->company_id = (int) $company_id;
$this->locale = $locale ?: company($company_id)->locale;
}
@ -58,5 +58,9 @@ class UninstallModule extends Job
if (! $this->moduleExists($this->alias)) {
throw new \Exception("Module [{$this->alias}] not found.");
}
if (! in_array($this->locale, config('language.allowed'))) {
throw new \Exception("Unknown locale: {$this->locale}");
}
}
}