thingsboard / thingsboard

Open-source IoT Platform - Device management, data collection, processing and visualization.
https://thingsboard.io
Apache License 2.0
17.5k stars 5.18k forks source link

Report are not generated in the user language #11970

Open GregAscolab opened 2 days ago

GregAscolab commented 2 days ago

Describe the bug Report are not generated in the user language.

When using the generate report rule node, and setting the userId by script, from msg.originatorId (for example).

"useCurrentUserCredentials": false,
"userId": msg.originatorId

The report is generated and I can send it by email.

But in my case I sent an email per customer user. So each user generate its own report to be sent (according user rights/visibility). But the user language preference is not apply when generating report.

image

Add reportConfig Node :

var newMsg = msg;

var dashboardId = "ef776a20-9087-11ef-bb05-3f7cd9782d8e";

newMsg.reportConfig = {
    "baseUrl": "https://mds.ascolab.fr",
    "useDashboardTimewindow": true,
    "timewindow": {
        "selectedTab": 1,
        "history": {
            "historyType": 0,
            "interval": 1000,
            "timewindowMs": 86400000
        }
    },
    "namePattern": "report-%d{yyyy-MM-dd_HH:mm:ss}",
    "type": "pdf",
    "timezone": "Europe/Paris",
    "useCurrentUserCredentials": false,
    "userId": msg.originatorId,
    "dashboardId": dashboardId,
    "state": ""
};

newMsg.sendEmail = true;

return {
    msg: newMsg,
    metadata: metadata,
    msgType: "generateReport"
};

msg.originatorId is the user Id.

Your Server Environment

Your Client Environment

To Reproduce Steps to reproduce the behavior:

  1. Create a rule chain include a script node that create "reportConfig" information in a message, using a userId.
  2. Connect it to generateReport node
  3. Send report by email
  4. Check report in the email, or in generated files.

(Maybe same problem using "scheduler" ?)

Expected behavior User's language preference must be apply when generating report.


Disclaimer

We appreciate your contribution whether it is a bug report, feature request, or pull request with improvement (hopefully). Please comply with the Community ethics policy, and do not expect us to answer your requests immediately. Also, do not treat GitHub issues as a support channel.

mykhailokornieiev commented 2 days ago

Hi. I was unable to reproduce this behavior via Scheduler (it uses Generate Report rule node anyway) My tenant user uses English and customer user uses Ukrainian: image image Try to restore default Generate Report rule chain logic and check the correct message in debug. Also, are you sure that this customer uses translation configured in Account -> Profile and not browser settings?

GregAscolab commented 2 days ago

I try with scheduler... something strange...

1/ Click on "Generate Test Report" in scheduler dialog box : The message is not routed as "generateReport" message type, but updateValue... So generation of the report is done... magically internally ??? ;-) There is no rule chain to manage it, but I get a pdf report : Always in english, no user language, whatever my tenant user language is.

2/ When scheduler fire it's event :

My scheduler config : image

Generate Report Node debug :
image

image

image === a6254680-92a3-11ef-9285-db91bf15ba2b

Received email : image

Dashboard from g.pub account in French, on web site : image

g.pub user settings : image

I don't understand...

mykhailokornieiev commented 1 day ago

Plaese clarify the next: Do you use customer user or sub-customer user credentials? Is it some standard widgets with default translations? Do you use custom translation, maybe in {i18n} format?

GregAscolab commented 1 day ago

Informations :

Do you use customer user or sub-customer user credentials?

I want report generated by customer user (g.pub) No sub-customer users for the moment, but can be in futur. image

Is it some standard widgets with default translations? Do you use custom translation, maybe in {i18n} format?

Yes and no, standard alarm table widget. But I also use i18n translation from "standard translation" and from added "custom translation".

image image

And lot of custom i18n in cell content :
image

mykhailokornieiev commented 1 day ago

Still can't reproduce under specified conditions

var map = {
    "CRITICAL": "{i18n:custom.severity.critical}",
    "MAJOR": "{i18n:custom.severity.major}"
};
return map[value] ? map[value] : value;
{
  "custom": {
    "severity": {
      "critical": "Custom Critical Severity",
      "major": "Custom Major Severity"
    },
    "title": {
        "alarmTitle": "Custom Alarm Title"
    }
  }
}

image

GregAscolab commented 1 day ago

Hum...

I checked my "g.pub" user...

Something strange : In user account parameters, the language is set to "French". But I cannot change it !

I can select a new language, but there is no "SAVE" button. So I get warning popup message : "You didn't save changes..."

It seems to be my problem !

image

image

When I use my tenant user to generate the report : the report language change according my tenant user language settings !

Good...

  1. It seems that my "customers user" don't have the right to change language. Which right it is ?
  2. So there is something mixed up : In a way or another, the language has been set to the user (when creating the new user?), because logging as g.pub make the site in French.
    But report engine seems to check if user has the right to change is language.
mykhailokornieiev commented 19 hours ago

It seems that my "customers user" don't have the right to change language. Which right it is ?

This is "Profile" permission.

So there is something mixed up : In a way or another, the language has been set to the user (when creating the new user?), because logging as g.pub make the site in French. But report engine seems to check if user has the right to change is language.

I was able to reproduce your behavior and it is not a bug.

  1. Create a user without "profile" permissions
  2. If you log in as this user from a browser where the browser language is, for example, French, the system will automatically select the browser language.
  3. tb-web-report is a headless browser with default language settings, that is, it uses English. That is why, since you have never chosen a language for the user, the language of the browser is chosen You can avoid this behavior as soon as you change the language manually.