dolibarr icon indicating copy to clipboard operation
dolibarr copied to clipboard

Bug: Preserve user language for automatic events when using REST API

Open jtraulle opened this issue 5 years ago • 6 comments

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

events

jtraulle avatar Aug 15 '19 12:08 jtraulle

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.

jtraulle avatar Aug 15 '19 19:08 jtraulle

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)

eldy avatar Aug 27 '19 15:08 eldy

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.

jtraulle avatar Aug 31 '19 12:08 jtraulle

@github-actions Do not close :)

jtraulle avatar Sep 07 '20 06:09 jtraulle

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).

github-actions[bot] avatar Sep 07 '21 21:09 github-actions[bot]

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).

github-actions[bot] avatar Sep 18 '22 21:09 github-actions[bot]

Functional in v16.0.2 with swagger

Screenshot (11)

inoveaconseil avatar Nov 25 '22 21:11 inoveaconseil