Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gmail/appsscript.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"https://*.odoo.com/web/login",
"https://*.odoo.com/mail_plugin/auth",
"https://*.odoo.com/mail_plugin/auth/access_token",
"https://*.odoo.com/mail_plugin/auth/check_version",
"https://odoo.com/mail_plugin/get_translations",
"https://odoo.com/mail_plugin/partner/get",
"https://odoo.com/mail_plugin/log_mail_content",
Expand All @@ -49,6 +50,7 @@
"https://odoo.com/web/login",
"https://odoo.com/mail_plugin/auth",
"https://odoo.com/mail_plugin/auth/access_token",
"https://odoo.com/mail_plugin/auth/check_version",
"https://iap-services.odoo.com/iap/mail_extension/enrich"
]
}
1 change: 1 addition & 0 deletions gmail/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const ODOO_AUTH_URLS: Record<string, string> = {
LOGIN: "/web/login",
AUTH_CODE: "/mail_plugin/auth",
CODE_VALIDATION: "/mail_plugin/auth/access_token",
CHECK_VERSION: "/mail_plugin/auth/check_version",
SCOPE: "outlook",
FRIENDLY_NAME: "Gmail",
};
26 changes: 10 additions & 16 deletions gmail/src/services/odoo_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,33 +132,27 @@ export const resetAccessToken = () => {
};

/**
* Make an HTTP request to "/mail_plugin/auth/access_token" (cors="*") on the Odoo
* database to verify that the server is reachable and that the mail plugin module is
* installed.
* Make an HTTP request to the Odoo database to verify that the server
* is reachable and that the mail plugin module is installed.
*
* Returns True if the Odoo database is reachable and if the "mail_plugin" module
* is installed, false otherwise.
* Returns the version of the addin that is supported if it's reachable, null otherwise.
*/
export const isOdooDatabaseReachable = (odooUrl: string): boolean => {
export const getSupportedAddinVersion = (odooUrl: string): number | null => {
if (!odooUrl || !odooUrl.length) {
return false;
return null;
}

const response = postJsonRpc(
odooUrl + ODOO_AUTH_URLS.CODE_VALIDATION,
{ auth_code: null },
{},
{ returnRawResponse: true },
);
const response = postJsonRpc(odooUrl + ODOO_AUTH_URLS.CHECK_VERSION, {}, {}, { returnRawResponse: true });
if (!response) {
return false;
return null;
}

const responseCode = response.getResponseCode();

if (responseCode > 299 || responseCode < 200) {
return false;
return null;
}

return true;
const textResponse = response.getContentText("UTF-8");
return parseInt(JSON.parse(textResponse).result);
};
12 changes: 9 additions & 3 deletions gmail/src/views/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { formatUrl, repeat } from "../utils/format";
import { notify, createKeyValueWidget } from "./helpers";
import { State } from "../models/state";
import { IMAGES_LOGIN } from "./icons";
import { isOdooDatabaseReachable } from "../services/odoo_auth";
import { getSupportedAddinVersion } from "../services/odoo_auth";
import { _t, clearTranslationCache } from "../services/translation";
import { setOdooServerUrl } from "src/services/app_properties";

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

setOdooServerUrl(validatedUrl);

if (!isOdooDatabaseReachable(validatedUrl)) {
const version = getSupportedAddinVersion(validatedUrl);

if (!version) {
return notify("Could not connect to your database.");
}

if (version !== 1) {
return notify(
"Could not connect to your database. Make sure the module is installed in Odoo (Settings > General Settings > Integrations > Mail Plugins)",
"This addin version required Odoo 19.0 or an older version, please install a newer addin version.",
);
}

Expand Down