[geary/geary-0.13] Merge branch 'wip/fix-not-prompting-for-missing-password' into 'master'



commit 5bc5f255eac7745b0885523aa647537101acb40b
Author: Michael Gratton <mike vee net>
Date:   Sun Feb 24 04:59:01 2019 +0000

    Merge branch 'wip/fix-not-prompting-for-missing-password' into 'master'
    
    Fix GOA accounts losing their credentials when updated
    
    Closes #250
    
    See merge request GNOME/geary!129
    
    (cherry picked from commit c0c0856d0cfd963a4a3addb69702dae30a92cd2e)
    
    e286e9de Throw errors when IMAP or SMTP services have incomplete creds
    81bc2e5f Make GoaMediator::prompt_token a no-op
    938baa0a Ensure GOA accounts have their creds updated after the account itself is
    5e6e4f2e Tidy up and add some debug logging to GOA signal hadlers

 src/client/accounts/accounts-manager.vala    | 60 ++++++++++++++++------------
 src/client/application/goa-mediator.vala     |  9 +----
 src/engine/imap/api/imap-client-service.vala |  6 +--
 src/engine/smtp/smtp-client-service.vala     |  2 +-
 4 files changed, 39 insertions(+), 38 deletions(-)
---
diff --git a/src/client/accounts/accounts-manager.vala b/src/client/accounts/accounts-manager.vala
index 426cb28a..3908b2b1 100644
--- a/src/client/accounts/accounts-manager.vala
+++ b/src/client/accounts/accounts-manager.vala
@@ -828,6 +828,31 @@ public class Accounts.Manager : GLib.Object {
         }
     }
 
+    private async void update_goa_account(Geary.AccountInformation account,
+                                          GLib.Cancellable? cancellable) {
+        GoaMediator mediator = (GoaMediator) account.mediator;
+        try {
+            yield mediator.update(account, cancellable);
+
+            // Update will clear the creds, so make sure they get
+            // refreshed
+            yield account.load_outgoing_credentials(cancellable);
+            yield account.load_incoming_credentials(cancellable);
+        } catch (GLib.Error err) {
+            report_problem(
+                new Geary.AccountProblemReport(
+                    Geary.ProblemType.GENERIC_ERROR,
+                    account,
+                    err
+                ));
+        }
+
+        // XXX need to notify the engine that creds may have changed
+
+        set_available(account, mediator.is_available);
+    }
+
+
     private async void open_goa_settings(string action,
                                          string? param,
                                          GLib.Cancellable? cancellable)
@@ -882,37 +907,20 @@ public class Accounts.Manager : GLib.Object {
     }
 
     private void on_goa_account_added(Goa.Object account) {
+        debug("GOA account added: %s", account.get_account().id);
         // XXX get a cancellable for this.
         this.create_goa_account.begin(account, null);
     }
 
     private void on_goa_account_changed(Goa.Object account) {
-        string id = to_geary_id(account);
-        AccountState? state = this.accounts.get(id);
-
+        debug("GOA account changed: %s", account.get_account().id);
+        AccountState? state = this.accounts.get(to_geary_id(account));
+        // XXX get a cancellable to these
         if (state != null) {
             // We already know about this account, so check that it is
             // still valid. If not, the account should be disabled,
             // not deleted, since it may be re-enabled at some point.
-            GoaMediator mediator = (GoaMediator) state.account.mediator;
-            mediator.update.begin(
-                state.account,
-                null, // XXX Get a cancellable to this somehow
-                (obj, res) => {
-                    try {
-                        mediator.update.end(res);
-                    } catch (GLib.Error err) {
-                        report_problem(
-                            new Geary.AccountProblemReport(
-                                Geary.ProblemType.GENERIC_ERROR,
-                                state.account,
-                                err
-                            ));
-                    }
-
-                    set_available(state.account, mediator.is_available);
-                }
-            );
+            this.update_goa_account.begin(state.account, null);
         } else {
             // We haven't created an account for this GOA account
             // before, so try doing so now.
@@ -923,11 +931,11 @@ public class Accounts.Manager : GLib.Object {
     }
 
     private void on_goa_account_removed(Goa.Object account) {
-        AccountState? state = this.accounts.get(
-            to_geary_id(account)
-        );
-
+        debug("GOA account removed: %s", account.get_account().id);
+        AccountState? state = this.accounts.get(to_geary_id(account));
         if (state != null) {
+            // Just disabled it for now in case the GOA daemon as just
+            // shutting down.
             set_available(state.account, false);
         }
     }
diff --git a/src/client/application/goa-mediator.vala b/src/client/application/goa-mediator.vala
index 5495db5e..09a87c44 100644
--- a/src/client/application/goa-mediator.vala
+++ b/src/client/application/goa-mediator.vala
@@ -107,15 +107,10 @@ public class GoaMediator : Geary.CredentialsMediator, Object {
                                            Geary.ServiceInformation service,
                                            GLib.Cancellable? cancellable)
         throws GLib.Error {
-        // Prompt GOA to update the creds. This might involve some
-        // user interaction.
-        yield update(account, cancellable);
-
-        // XXX now open a dialog that says "Click here to change your
-        // GOA password" or "GOA credentials need renewing" or
+        // XXX Open a dialog that says "Click here to change your GOA
+        // password" or "GOA credentials need renewing" or
         // something. Connect to the GOA service and wait until we
         // hear that needs attention is no longer true.
-
         return this.is_available;
     }
 
diff --git a/src/engine/imap/api/imap-client-service.vala b/src/engine/imap/api/imap-client-service.vala
index 398ff8dd..fa99d478 100644
--- a/src/engine/imap/api/imap-client-service.vala
+++ b/src/engine/imap/api/imap-client-service.vala
@@ -387,16 +387,14 @@ internal class Geary.Imap.ClientService : Geary.ClientService {
         debug("[%s] Opening new session", this.account.id);
         Credentials? login = this.configuration.credentials;
         if (login != null && !login.is_complete()) {
-            notify_authentication_failed();
+            throw new ImapError.UNAUTHENTICATED("Token not loaded");
         }
 
         ClientSession new_session = new ClientSession(remote);
         yield new_session.connect_async(cancellable);
 
         try {
-            yield new_session.initiate_session_async(
-                this.configuration.credentials, cancellable
-            );
+            yield new_session.initiate_session_async(login, cancellable);
         } catch (Error err) {
             // need to disconnect before throwing error ... don't
             // honor Cancellable here, it's important to disconnect
diff --git a/src/engine/smtp/smtp-client-service.vala b/src/engine/smtp/smtp-client-service.vala
index 7ce305fd..e949338a 100644
--- a/src/engine/smtp/smtp-client-service.vala
+++ b/src/engine/smtp/smtp-client-service.vala
@@ -238,7 +238,7 @@ internal class Geary.Smtp.ClientService : Geary.ClientService {
         throws Error {
         Credentials? login = this.account.get_outgoing_credentials();
         if (login != null && !login.is_complete()) {
-            notify_authentication_failed();
+            throw new SmtpError.AUTHENTICATION_FAILED("Token not loaded");
         }
 
         Smtp.ClientSession smtp = new Geary.Smtp.ClientSession(this.remote);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]