Skip to content

Commit a9eeffb

Browse files
committed
[IMP] gmail: show warning if the Odoo database needs a newer addin
Purpose ======= Now that we have two versions of the addin, we show a toast message if the database needs the next addin version. Task-4727609
1 parent 7db1a31 commit a9eeffb

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

gmail/appsscript.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"https://*.odoo.com/web/login",
3535
"https://*.odoo.com/mail_plugin/auth",
3636
"https://*.odoo.com/mail_plugin/auth/access_token",
37+
"https://*.odoo.com/mail_plugin/auth/check_version",
3738
"https://odoo.com/mail_plugin/get_translations",
3839
"https://odoo.com/mail_plugin/partner/get",
3940
"https://odoo.com/mail_plugin/log_mail_content",
@@ -49,6 +50,7 @@
4950
"https://odoo.com/web/login",
5051
"https://odoo.com/mail_plugin/auth",
5152
"https://odoo.com/mail_plugin/auth/access_token",
53+
"https://odoo.com/mail_plugin/auth/check_version",
5254
"https://iap-services.odoo.com/iap/mail_extension/enrich"
5355
]
5456
}

gmail/src/const.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const ODOO_AUTH_URLS: Record<string, string> = {
2323
LOGIN: "/web/login",
2424
AUTH_CODE: "/mail_plugin/auth",
2525
CODE_VALIDATION: "/mail_plugin/auth/access_token",
26+
CHECK_VERSION: "/mail_plugin/auth/check_version",
2627
SCOPE: "outlook",
2728
FRIENDLY_NAME: "Gmail",
2829
};

gmail/src/services/odoo_auth.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,33 +132,27 @@ export const resetAccessToken = () => {
132132
};
133133

134134
/**
135-
* Make an HTTP request to "/mail_plugin/auth/access_token" (cors="*") on the Odoo
136-
* database to verify that the server is reachable and that the mail plugin module is
137-
* installed.
135+
* Make an HTTP request to the Odoo database to verify that the server
136+
* is reachable and that the mail plugin module is installed.
138137
*
139-
* Returns True if the Odoo database is reachable and if the "mail_plugin" module
140-
* is installed, false otherwise.
138+
* Returns the version of the addin that is supported if it's reachable, null otherwise.
141139
*/
142-
export const isOdooDatabaseReachable = (odooUrl: string): boolean => {
140+
export const getSupportedAddinVersion = (odooUrl: string): number | null => {
143141
if (!odooUrl || !odooUrl.length) {
144-
return false;
142+
return null;
145143
}
146144

147-
const response = postJsonRpc(
148-
odooUrl + ODOO_AUTH_URLS.CODE_VALIDATION,
149-
{ auth_code: null },
150-
{},
151-
{ returnRawResponse: true },
152-
);
145+
const response = postJsonRpc(odooUrl + ODOO_AUTH_URLS.CHECK_VERSION, {}, {}, { returnRawResponse: true });
153146
if (!response) {
154-
return false;
147+
return null;
155148
}
156149

157150
const responseCode = response.getResponseCode();
158151

159152
if (responseCode > 299 || responseCode < 200) {
160-
return false;
153+
return null;
161154
}
162155

163-
return true;
156+
const textResponse = response.getContentText("UTF-8");
157+
return parseInt(JSON.parse(textResponse).result);
164158
};

gmail/src/views/login.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { formatUrl, repeat } from "../utils/format";
22
import { notify, createKeyValueWidget } from "./helpers";
33
import { State } from "../models/state";
44
import { IMAGES_LOGIN } from "./icons";
5-
import { isOdooDatabaseReachable } from "../services/odoo_auth";
5+
import { getSupportedAddinVersion } from "../services/odoo_auth";
66
import { _t, clearTranslationCache } from "../services/translation";
77
import { setOdooServerUrl } from "src/services/app_properties";
88

@@ -21,9 +21,15 @@ function onNextLogin(event) {
2121

2222
setOdooServerUrl(validatedUrl);
2323

24-
if (!isOdooDatabaseReachable(validatedUrl)) {
24+
const version = getSupportedAddinVersion(validatedUrl);
25+
26+
if (!version) {
27+
return notify("Could not connect to your database.");
28+
}
29+
30+
if (version !== 1) {
2531
return notify(
26-
"Could not connect to your database. Make sure the module is installed in Odoo (Settings > General Settings > Integrations > Mail Plugins)",
32+
"This addin version required Odoo 19.0 or an older version, please install a newer addin version.",
2733
);
2834
}
2935

0 commit comments

Comments
 (0)