[IMP] gmail: remove the enrichment feature from the addon#52
Conversation
e679c10 to
2da20fd
Compare
173c0ec to
d710a18
Compare
e259ed2 to
89e1fb5
Compare
6a4bfa2 to
4610569
Compare
df57832 to
8784f69
Compare
36c5354 to
9d9c14a
Compare
9d9c14a to
6e15be2
Compare
7407ba1 to
1a8cfd2
Compare
0c8e3ce to
243823e
Compare
4c8a33e to
b0f1f54
Compare
e78683b to
fe52487
Compare
tde-banana-odoo
left a comment
There was a problem hiding this comment.
Zboing, thanks for your work, quite a big PR and nice work done here !
Added some questions and while going through, in addition to what we already discussed. Should be quick to answer / update, so we can probably close this soonish :) :) .
Thanks again, addin people are going to be happy !
|
|
||
| constructor( | ||
| id: number, | ||
| email: string, |
There was a problem hiding this comment.
Are we sure we always receive a normalized email ? As we search for exact email ( _getUserFromEmail ), asking to be sure we won't run into formatted email issues as we had in standard odoo ^^
There was a problem hiding this comment.
Globally, question is: do we always deal with normalized emails for users ? Their gmail email probably, but asking to be sure.
There was a problem hiding this comment.
I think yes, or at least, the google api should always return the same value
(as we use that information to login the user, I wouldn't be confident to do some post-processing on the value I receive from the api, as it could result in authentication bypass...)
| "res.partner": [], | ||
| "crm.lead": [], | ||
| "helpdesk.ticket": [], | ||
| "project.task": [], |
There was a problem hiding this comment.
Wild question: wouldn't we support applicants at some point ?
There was a problem hiding this comment.
I don't know 🙂 might be a cool idea
| const body = _formatEmailBody(_t, rawBody, error); | ||
|
|
||
| const response = await postJsonRpc( | ||
| user.odooUrl + URLS.LOG_EMAIL, |
There was a problem hiding this comment.
Same global remarks for recipients: seems we don't keep recipients ? Especially we can now store raw emails on message model (incoming_email_to and incoming_email_cc) for that purpose, allowing to avoid creating useless partners.
There was a problem hiding this comment.
good idea 🙂
Note that in discuss, the "reply to" button just reply to the email_from when there's no "reply-to" header, but I guess it should be for an other task
| } catch { | ||
| return ERROR_PAGE.replace( | ||
| "__ERROR_MESSAGE__", | ||
| "The token exchange failed. Maybe your token has expired or your database can not be reached by the Google server." + |
There was a problem hiding this comment.
Will that be translated ?
There was a problem hiding this comment.
no, it is before the odoo authentication, so we cannot do a request to know which language the user has on his settings
(same for the buttons on the login page, they will be always in English)
|
Also feels like the PR message is a bit centered on IAP while the changes are a bit broader ^^ |
Purpose ======= Because we cannot close the popup in which the user login like before, we now show the rainbow man when we have received the access token during the login flow. Task-4727609
Purpose ======= Before the subject, email from, etc were added in the body of the email when we log it in a record. Now, those values are properly written in the fields of the `mail.message`, and so we need to send them to the Odoo endpoint. Parse all the contacts in the email TO, CC,... to prepare the following commit. Before, if we wait some time before logging the email on a record, an error could be raised because the token we received to get the information expired. To solve that issue, we parse and save then in the state when the addin is loaded. Task-4727609
Purpose ======= Then enrichment feature of the addon made it slow and hard to use in practice, so we simplify it, and we keep only the core feature, which is logging the email on the records and viewing information about the contact. If a conversation contains many contacts, before it took the first one. We can now choose the contact we want to open. Allow searching any records, not only partners. We fixed some UI issues than were introduced by update of the Gmail API. Task-4727609
fe52487 to
8d6b2e1
Compare
Purpose ======= The current addin is slow, because of how appscript work (Google host a web server, with our app running, that server restart at each call, the language itself is synchronous...). In alternative way of creating addin, is to host the application ourselves. It's faster because we can keep the server alive, and we can make the HTTP calls in parallel (to the Gmail API and to the Odoo database). > https://developers.google.com/workspace/add-ons/guides/alternate-runtimes We choose to use node with express, because it's asynchronous, and we will make a lot of request (to the Odoo database, to the Gmail API, etc). Also, most of the code can be re-used (the core logic). The main changes compared to appscript are - we need to store the user settings ourselves (and we use psql for that) - so the translations and the email logging state is moved to the user (it's considered as "User Settings / Information"). - to build the view, our endpoints need to return JSON, so we created some helper classes similar to the one use by appscript (no official library exists for that at the moment, for typescript) The application has been kept as similar as the one using appscript as possible (the execution of action, with the state of the current page is sent in the response). Task-4727609
Purpose ======= Now that all users will share the same process on the server, we want to prevent the state from being modified by using JWT token. Task-4727609
Purpose ======= When we used appscript, we didn't have a web server to store the image (and to do the processing to translate text inside the SVG), and so we base 64 encoded them. Now that we moved the HTTP addin, we have a web server, and we can serve the files (and translate them on the fly), so that the images are cached by the browser, and we don't download them each time we view a new card. When Gmail shows images, it doesn't add our URL in the dom, instead it fetches the image, and store it in `googleusercontent.com`. But, it won't fetch the images if they come from a ngrok domain name, so now, we need a "real" domain name for development. Task-4727609
8d6b2e1 to
7b988ea
Compare
| const userEmail = user.email.toLowerCase(); | ||
| const contacts = [ | ||
| ...this._emailSplitTuple(headers["to"] || "", userEmail), | ||
| ...this._emailSplitTuple(headers["from"] || "", userEmail), |
There was a problem hiding this comment.
it's in case you open an email you sent, vs an email you received (otherwise you will see your own partner)
(it's more a "list of users in the email headers", but a bit long 😅)
| } catch { | ||
| return ERROR_PAGE.replace( | ||
| "__ERROR_MESSAGE__", | ||
| "The token exchange failed. Maybe your token has expired or your database can not be reached by the Google server." + |
There was a problem hiding this comment.
no, it is before the odoo authentication, so we cannot do a request to know which language the user has on his settings
(same for the buttons on the login page, they will be always in English)
| const body = _formatEmailBody(_t, rawBody, error); | ||
|
|
||
| const response = await postJsonRpc( | ||
| user.odooUrl + URLS.LOG_EMAIL, |
There was a problem hiding this comment.
good idea 🙂
Note that in discuss, the "reply to" button just reply to the email_from when there's no "reply-to" header, but I guess it should be for an other task
Remove the enrichment feature
Then enrichment feature of the addon made it slow and hard to use in
practice, so we simplify it, and we keep only the core feature, which
is logging the email on the records and viewing information about the
contact.
Move from appscript to HTTP addin
The current addin is slow, because of how appscript work (Google host
a web server, with our app running, that server restart at each call,
the language itself is synchronous...).
In alternative way of creating addin, is to host the application ourselves.
It's faster because we can keep the server alive, and we can make the
HTTP calls in parallel (to the Gmail API and to the Odoo database).
UI
If a conversation contains many contacts, before it took the first
one. We can now choose the contact we want to open.
Allow searching any records, not only partners.
We fixed some UI issues than were introduced by
update of the Gmail API.
Technical
Serve image file instead of encoding in base 64 (now that we use HTTP addin).
Prevent state modification with JWT (the process of the server is now share among the users).
Task-4727609