dolibarr
dolibarr copied to clipboard
Bug: Preserve user language for automatic events when using REST API
Bug
When using the REST API to create, validate, classify orders, invoices and other Dolibarr objects and the Events module is activated, the automatically inserted events description are in English regardless of the user langage defined for the API key used to make the requests.
Environment
- Version: 7.x, 8.x, 9.x, 10.x, dev
- OS: GNU/Linux
- Web server: Apache2
- PHP: 7.3
- Database: MySQL/MariaDB
Expected and actual behavior
Expected : The automatically inserted events descriptions should preserve the user language defined in the user settings. Actual : The automatically inserted events descriptions are in English regardless of the user language defined for the API key used to make the requests.
Steps to reproduce the behavior
- create a user and set its language to French
- get the newly created user API key
- enable the REST API module, Thirdparties module, Orders module, Events module
- create an order using the REST API
- validate the order using the REST API
- classify the order as delivered using the REST API
- classify the order as invoiced using the REST API
- go to the newly created order in Dolibarr
- note that events description are written in English
- click on Classer 'Non facturée' then on Classer 'Facturée'
- note that the newly added automatic event description is written in French (as intended)
Attached files
Investigating into this, it seems that the API takes only into account the main app setting about language.
I tried to add
$langs=new Translate("", $conf);
if ($langs->getDefaultLang() != self::$user->conf->MAIN_LANG_DEFAULT)
{
DolibarrApi::$lang = self::$user->conf->MAIN_LANG_DEFAULT;
}
at the end of the __isAllowed()
function into api_access.class.php
without luck.
We can also use the default language of self::$user But it will remain the same language for all api call (the on of self::$user)
We can also use the default language of self::$user But it will remain the same language for all api call (the on of self::$user)
I think this would be better.
@github-actions Do not close :)
This issue is stale because it has been open 1 year with no activity. If this is a bug, please comment to confirm it is still present on latest stable version. if this is a feature request, please comment to notify the request is still relevant and not yet covered by latest stable version. This issue may be closed automatically by stale bot in 10 days (you should still be able to re-open it if required).
This issue is stale because it has been open 1 year with no activity. If this is a bug, please comment to confirm it is still present on latest stable version. if this is a feature request, please comment to notify the request is still relevant and not yet covered by latest stable version. This issue may be closed automatically by stale bot in 10 days (you should still be able to re-open it if required).
Functional in v16.0.2 with swagger