Commit 165a79d7 authored by Milan Crha's avatar Milan Crha

I#29 - Changed user name not propagated to collection child sources

Closes GNOME/evolution-data-server#29
parent 3f4ac87c
......@@ -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);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment