fix: only validate oauth if tokens are set
* also brough back oauth authorization message
This commit is contained in:
parent
f50be4bbf5
commit
6bed904bf7
3 changed files with 25 additions and 2 deletions
|
|
@ -74,6 +74,7 @@ function oauth_access(frm) {
|
|||
method: "initiate_web_application_flow",
|
||||
args: {
|
||||
success_uri: window.location.pathname,
|
||||
user: frm.doc.connected_user,
|
||||
},
|
||||
callback: function (r) {
|
||||
window.open(r.message, "_self");
|
||||
|
|
@ -147,6 +148,7 @@ frappe.ui.form.on("Email Account", {
|
|||
frm.refresh_field("imap_folder");
|
||||
}
|
||||
set_default_max_attachment_size(frm);
|
||||
frm.events.show_oauth_authorization_message(frm);
|
||||
},
|
||||
|
||||
refresh: function (frm) {
|
||||
|
|
@ -180,6 +182,27 @@ frappe.ui.form.on("Email Account", {
|
|||
oauth_access(frm);
|
||||
},
|
||||
|
||||
show_oauth_authorization_message(frm) {
|
||||
if (frm.doc.auth_method === "OAuth") {
|
||||
frappe.call({
|
||||
method: "frappe.integrations.doctype.connected_app.connected_app.check_active_token",
|
||||
args: {
|
||||
connected_app: frm.doc.connected_app,
|
||||
connected_user: frm.doc.connected_user,
|
||||
},
|
||||
callback: (r) => {
|
||||
if (!r.message) {
|
||||
let msg = __(
|
||||
'OAuth has been enabled but not authorised. Please use "Authorise API Access" button to do the same.'
|
||||
);
|
||||
frm.dashboard.clear_headline();
|
||||
frm.dashboard.set_headline_alert(msg, "yellow");
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
domain: frappe.utils.debounce((frm) => {
|
||||
if (frm.doc.domain) {
|
||||
frappe.call({
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ class EmailAccount(Document):
|
|||
return
|
||||
|
||||
use_oauth = self.auth_method == "OAuth"
|
||||
validate_oauth = use_oauth and not (self.is_new() and not self.get_oauth_token())
|
||||
self.use_starttls = cint(self.use_imap and self.use_starttls and not self.use_ssl)
|
||||
|
||||
if use_oauth:
|
||||
|
|
@ -90,7 +91,7 @@ class EmailAccount(Document):
|
|||
self.password = None
|
||||
|
||||
if not frappe.local.flags.in_install and not self.awaiting_password:
|
||||
if use_oauth or self.password or self.smtp_server in ("127.0.0.1", "localhost"):
|
||||
if validate_oauth or self.password or self.smtp_server in ("127.0.0.1", "localhost"):
|
||||
if self.enable_incoming:
|
||||
self.get_incoming_server()
|
||||
self.no_failed = 0
|
||||
|
|
|
|||
|
|
@ -112,7 +112,6 @@ class ConnectedApp(Document):
|
|||
token = oauth_session.refresh_token(
|
||||
body=f"redirect_uri={self.redirect_uri}",
|
||||
token_url=self.token_uri,
|
||||
refresh_token=token_cache.get_password("refresh_token"),
|
||||
)
|
||||
except Exception:
|
||||
self.log_error("Token Refresh Error")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue