[evolution-data-server/gnome-3-30] I#29 - Changed user name not propagated to collection child sources ][
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/gnome-3-30] I#29 - Changed user name not propagated to collection child sources ][
- Date: Mon, 17 Sep 2018 16:37:44 +0000 (UTC)
commit ec9373bf9081e53264952e97ed3cce9616d5cce6
Author: Milan Crha <mcrha redhat com>
Date: Mon Sep 17 18:35:56 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/libedataserver/e-data-server-util.c | 41 ++++++-----
src/libedataserverui/e-credentials-prompter.c | 100 ++++++++++++++++++--------
2 files changed, 93 insertions(+), 48 deletions(-)
---
diff --git a/src/libedataserver/e-data-server-util.c b/src/libedataserver/e-data-server-util.c
index 7fee9b4d4..a1771d1c4 100644
--- a/src/libedataserver/e-data-server-util.c
+++ b/src/libedataserver/e-data-server-util.c
@@ -3201,11 +3201,24 @@ e_util_can_use_collection_as_credential_source (ESource *collection_source,
host_collection = e_source_authentication_dup_host (auth_collection);
if (host_source && host_collection && g_ascii_strcasecmp (host_source,
host_collection) == 0) {
+ can_use_collection = TRUE;
+ } else {
+ /* Only one of them is filled, then use the collection; otherwise
+ both are filled and they do not match, thus do not use collection. */
+ can_use_collection = (host_collection && *host_collection && (!host_source ||
!*host_source)) ||
+ (host_source && *host_source && (!host_collection ||
!*host_collection));
+ }
+
+ g_free (host_source);
+ g_free (host_collection);
+
+ if (can_use_collection) {
gchar *username_source, *username_collection;
username_source = e_source_authentication_dup_user (auth_source);
username_collection = e_source_authentication_dup_user (auth_collection);
+ /* Check user name similarly as host name */
if (username_source && username_collection && g_ascii_strcasecmp
(username_source, username_collection) == 0) {
can_use_collection = TRUE;
} else {
@@ -3214,29 +3227,21 @@ e_util_can_use_collection_as_credential_source (ESource *collection_source,
g_free (username_source);
g_free (username_collection);
- } else {
- /* Only one of them is filled, then use the collection; otherwise
- both are filled and they do not match, thus do not use collection. */
- can_use_collection = (host_collection && *host_collection && (!host_source ||
!*host_source)) ||
- (host_source && *host_source && (!host_collection ||
!*host_collection));
+ }
- if (can_use_collection) {
- gchar *method_source, *method_collection;
+ if (can_use_collection) {
+ gchar *method_source, *method_collection;
- /* Also check the method; if different, then rather not use the
collection */
- method_source = e_source_authentication_dup_method (auth_source);
- method_collection = e_source_authentication_dup_method
(auth_collection);
+ /* Also check the method; if different, then rather not use the collection */
+ method_source = e_source_authentication_dup_method (auth_source);
+ method_collection = e_source_authentication_dup_method (auth_collection);
- can_use_collection = !method_source || !method_collection ||
- g_ascii_strcasecmp (method_source, method_collection) == 0;
+ can_use_collection = !method_source || !method_collection ||
+ g_ascii_strcasecmp (method_source, method_collection) == 0;
- g_free (method_source);
- g_free (method_collection);
- }
+ g_free (method_source);
+ g_free (method_collection);
}
-
- g_free (host_source);
- g_free (host_collection);
}
}
diff --git a/src/libedataserverui/e-credentials-prompter.c b/src/libedataserverui/e-credentials-prompter.c
index d05695df2..437f2edcf 100644
--- a/src/libedataserverui/e-credentials-prompter.c
+++ b/src/libedataserverui/e-credentials-prompter.c
@@ -520,6 +520,8 @@ credentials_prompter_update_username_for_children (ESourceRegistry *registry,
{
GList *sources, *link;
const gchar *parent_uid;
+ gchar *collection_host;
+ gboolean username_changed;
g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
g_return_if_fail (E_IS_SOURCE (collection_source));
@@ -528,22 +530,26 @@ credentials_prompter_update_username_for_children (ESourceRegistry *registry,
if (!parent_uid || !*parent_uid)
return;
+ collection_host = e_source_authentication_dup_host (e_source_get_extension (collection_source,
E_SOURCE_EXTENSION_AUTHENTICATION));
+ username_changed = g_strcmp0 (old_username, new_username) != 0;
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)) {
+ e_source_get_writable (child) && e_source_has_extension (child,
E_SOURCE_EXTENSION_AUTHENTICATION)) {
ESourceAuthentication *auth_extension;
- gchar *child_username;
+ gchar *child_username, *child_host;
auth_extension = e_source_get_extension (child, E_SOURCE_EXTENSION_AUTHENTICATION);
child_username = e_source_authentication_dup_user (auth_extension);
+ child_host = e_source_authentication_dup_host (auth_extension);
- if (!child_username || !*child_username || !old_username || !*old_username ||
- g_strcmp0 (child_username, old_username) == 0) {
+ if ((!child_host || !*child_host || !collection_host || !*collection_host ||
+ g_ascii_strcasecmp (child_host, collection_host) == 0) &&
+ (!child_username || !*child_username || !old_username || !*old_username ||
+ (username_changed && g_strcmp0 (child_username, old_username) == 0))) {
e_source_authentication_set_user (auth_extension, new_username);
if (allow_source_save) {
@@ -553,10 +559,12 @@ credentials_prompter_update_username_for_children (ESourceRegistry *registry,
}
g_free (child_username);
+ g_free (child_host);
}
}
g_list_free_full (sources, g_object_unref);
+ g_free (collection_host);
}
static void
@@ -564,6 +572,7 @@ e_credentials_prompter_prompt_finish_for_source (ECredentialsPrompter *prompter,
ProcessPromptData *ppd,
const ENamedParameters *credentials)
{
+ ESource *cred_source;
gboolean changed = FALSE;
g_return_if_fail (E_IS_CREDENTIALS_PROMPTER (prompter));
@@ -572,17 +581,15 @@ e_credentials_prompter_prompt_finish_for_source (ECredentialsPrompter *prompter,
if (!credentials)
return;
- if (e_source_has_extension (ppd->cred_source, E_SOURCE_EXTENSION_AUTHENTICATION)) {
- ESourceAuthentication *auth_extension = e_source_get_extension (ppd->cred_source,
E_SOURCE_EXTENSION_AUTHENTICATION);
+ cred_source = ppd->cred_source;
- if (e_source_credentials_provider_can_store (e_credentials_prompter_get_provider (prompter),
ppd->cred_source)) {
- e_source_credentials_provider_store (e_credentials_prompter_get_provider (prompter),
ppd->cred_source, credentials,
- e_source_authentication_get_remember_password (auth_extension),
- prompter->priv->cancellable,
- credentials_prompter_store_credentials_cb, NULL);
- }
+ if (e_source_has_extension (cred_source, E_SOURCE_EXTENSION_AUTHENTICATION)) {
+ ESourceAuthentication *auth_extension = e_source_get_extension (cred_source,
E_SOURCE_EXTENSION_AUTHENTICATION);
+ gboolean could_use_collection;
- if (e_source_get_writable (ppd->cred_source)) {
+ could_use_collection = e_source_has_extension (cred_source, E_SOURCE_EXTENSION_COLLECTION);
+
+ if (e_source_get_writable (cred_source)) {
const gchar *username;
username = e_named_parameters_get (credentials, E_SOURCE_CREDENTIAL_USERNAME);
@@ -591,32 +598,65 @@ e_credentials_prompter_prompt_finish_for_source (ECredentialsPrompter *prompter,
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);
- }
+ /* Sync the changed user name to the child sources of the collection as well
*/
+ if (ppd->auth_source == cred_source && e_source_has_extension (cred_source,
E_SOURCE_EXTENSION_COLLECTION)) {
+ credentials_prompter_update_username_for_children (
+ e_credentials_prompter_get_registry (prompter),
+ 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;
+ if (g_strcmp0 (username, old_username) != 0) {
+ e_source_authentication_set_user (auth_extension, username);
+ changed = TRUE;
+ }
+ } else if (g_strcmp0 (username, old_username) != 0) {
+ if (ppd->auth_source != cred_source &&
+ e_source_has_extension (cred_source,
E_SOURCE_EXTENSION_COLLECTION)) {
+ auth_extension = e_source_get_extension (ppd->auth_source,
E_SOURCE_EXTENSION_AUTHENTICATION);
+ e_source_authentication_set_user (auth_extension, username);
+
+ if (ppd->allow_source_save && e_source_get_writable
(ppd->auth_source)) {
+ e_source_write (ppd->auth_source,
prompter->priv->cancellable,
+ credentials_prompter_source_write_cb, NULL);
+ }
+ } else {
+ e_source_authentication_set_user (auth_extension, username);
+ changed = TRUE;
+ }
}
g_free (old_username);
}
}
+
+ if (could_use_collection && !e_util_can_use_collection_as_credential_source (cred_source,
ppd->auth_source)) {
+ /* Copy also the remember-password flag */
+ e_source_authentication_set_remember_password (e_source_get_extension
(ppd->auth_source, E_SOURCE_EXTENSION_AUTHENTICATION),
+ e_credentials_prompter_eval_remember_password (cred_source));
+
+ cred_source = ppd->auth_source;
+ }
+ }
+
+ if (e_source_has_extension (cred_source, E_SOURCE_EXTENSION_AUTHENTICATION)) {
+ ESourceAuthentication *auth_extension = e_source_get_extension (cred_source,
E_SOURCE_EXTENSION_AUTHENTICATION);
+
+ if (e_source_credentials_provider_can_store (e_credentials_prompter_get_provider (prompter),
cred_source)) {
+ e_source_credentials_provider_store (e_credentials_prompter_get_provider (prompter),
cred_source, credentials,
+ e_source_authentication_get_remember_password (auth_extension),
+ prompter->priv->cancellable,
+ credentials_prompter_store_credentials_cb, NULL);
+ }
}
- if (ppd->allow_source_save && e_source_get_writable (ppd->cred_source) &&
- (changed || (ppd->remember_password ? 1 : 0) != (e_credentials_prompter_eval_remember_password
(ppd->cred_source) ? 1 : 0))) {
- e_source_write (ppd->cred_source, prompter->priv->cancellable,
+ if (ppd->allow_source_save && e_source_get_writable (cred_source) &&
+ (changed || (ppd->remember_password ? 1 : 0) != (e_credentials_prompter_eval_remember_password
(cred_source) ? 1 : 0))) {
+ e_source_write (cred_source, prompter->priv->cancellable,
credentials_prompter_source_write_cb, NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]