[evolution-data-server] I#29 - Changed user name not propagated to collection child sources



commit 165a79d76df7576fc677c520fd024ec63c48b2ae
Author: Milan Crha <mcrha redhat com>
Date:   Thu Sep 13 10:10:49 2018 +0200

    I#29 - Changed user name not propagated to collection child sources
    
    Closes https://gitlab.gnome.org/GNOME/evolution-data-server/issues/29

 src/libedataserverui/e-credentials-prompter.c | 85 +++++++++++++++++++++++++--
 1 file changed, 79 insertions(+), 6 deletions(-)
---
diff --git a/src/libedataserverui/e-credentials-prompter.c b/src/libedataserverui/e-credentials-prompter.c
index f8c94aaf6..d05695df2 100644
--- a/src/libedataserverui/e-credentials-prompter.c
+++ b/src/libedataserverui/e-credentials-prompter.c
@@ -496,16 +496,69 @@ credentials_prompter_source_write_cb (GObject *source_object,
                                      GAsyncResult *result,
                                      gpointer user_data)
 {
+       ESource *source = E_SOURCE (source_object);
        GError *error = NULL;
 
-       if (!e_source_write_finish (E_SOURCE (source_object), result, &error) &&
+       if (!e_source_write_finish (source, result, &error) &&
            !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-               g_warning ("%s: Failed to write source changes: %s", G_STRFUNC, error ? error->message : 
"Unknown error");
+               g_warning ("%s: Failed to write source '%s' (%s) changes: %s", G_STRFUNC,
+                       e_source_get_uid (source),
+                       e_source_get_display_name (source),
+                       error ? error->message : "Unknown error");
        }
 
        g_clear_error (&error);
 }
 
+static void
+credentials_prompter_update_username_for_children (ESourceRegistry *registry,
+                                                  ESource *collection_source,
+                                                  gboolean allow_source_save,
+                                                  const gchar *old_username,
+                                                  const gchar *new_username,
+                                                  GCancellable *cancellable)
+{
+       GList *sources, *link;
+       const gchar *parent_uid;
+
+       g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
+       g_return_if_fail (E_IS_SOURCE (collection_source));
+
+       parent_uid = e_source_get_uid (collection_source);
+       if (!parent_uid || !*parent_uid)
+               return;
+
+       sources = e_source_registry_list_sources (registry, NULL);
+
+       for (link = sources; link; link = g_list_next (link)) {
+               ESource *child = link->data;
+
+               if (g_strcmp0 (e_source_get_parent (child), parent_uid) == 0 &&
+                   e_source_get_writable (child) &&
+                   e_util_can_use_collection_as_credential_source (collection_source, child)) {
+                       ESourceAuthentication *auth_extension;
+                       gchar *child_username;
+
+                       auth_extension = e_source_get_extension (child, E_SOURCE_EXTENSION_AUTHENTICATION);
+                       child_username = e_source_authentication_dup_user (auth_extension);
+
+                       if (!child_username || !*child_username || !old_username || !*old_username ||
+                           g_strcmp0 (child_username, old_username) == 0) {
+                               e_source_authentication_set_user (auth_extension, new_username);
+
+                               if (allow_source_save) {
+                                       e_source_write (child, cancellable,
+                                               credentials_prompter_source_write_cb, NULL);
+                               }
+                       }
+
+                       g_free (child_username);
+               }
+       }
+
+       g_list_free_full (sources, g_object_unref);
+}
+
 static void
 e_credentials_prompter_prompt_finish_for_source (ECredentialsPrompter *prompter,
                                                 ProcessPromptData *ppd,
@@ -533,10 +586,30 @@ e_credentials_prompter_prompt_finish_for_source (ECredentialsPrompter *prompter,
                        const gchar *username;
 
                        username = e_named_parameters_get (credentials, E_SOURCE_CREDENTIAL_USERNAME);
-                       if (username && *username &&
-                           g_strcmp0 (username, e_source_authentication_get_user (auth_extension)) != 0) {
-                               e_source_authentication_set_user (auth_extension, username);
-                               changed = TRUE;
+                       if (username && *username) {
+                               gchar *old_username;
+
+                               old_username = e_source_authentication_dup_user (auth_extension);
+
+                               if (g_strcmp0 (username, old_username) != 0) {
+                                       /* Sync the changed user name to the child sources of the collection 
as well */
+                                       if (e_source_has_extension (ppd->cred_source, 
E_SOURCE_EXTENSION_COLLECTION)) {
+                                               credentials_prompter_update_username_for_children (
+                                                       e_credentials_prompter_get_registry (prompter),
+                                                       ppd->cred_source,
+                                                       ppd->allow_source_save,
+                                                       old_username,
+                                                       username,
+                                                       prompter->priv->cancellable);
+                                       }
+
+                                       /* Update the collection source as the last, due to tests for the old
+                                          username in the 
credentials_prompter_update_username_for_children(). */
+                                       e_source_authentication_set_user (auth_extension, username);
+                                       changed = TRUE;
+                               }
+
+                               g_free (old_username);
                        }
                }
        }


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