[gnome-system-tools/gnome-2-28] Don't try to commit if previous attempt has failed (users-admin)



commit 22ec5a20c4c509abca84ef92d96f52f56d6d721a
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Thu Sep 3 22:01:20 2009 +0200

    Don't try to commit if previous attempt has failed (users-admin)
    
    When creating/modifying an user, we were commit in 3 places: once to create the main group (if required), once to create the user, and once to add it to its main group.  Merge group changes into set_main_group() to remove one error. Check that the main group exists before trying to commit user. This way, we avoid showing several warnings in case of error, and don't commit partial dta (group without its user).

 src/users/callbacks.c     |   13 +++++++++++--
 src/users/user-settings.c |   15 ++++++++++++---
 2 files changed, 23 insertions(+), 5 deletions(-)
---
diff --git a/src/users/callbacks.c b/src/users/callbacks.c
index 5f1f262..e30ce14 100644
--- a/src/users/callbacks.c
+++ b/src/users/callbacks.c
@@ -294,14 +294,19 @@ on_user_new_clicked (GtkButton *button, gpointer user_data)
 	if (response == GTK_RESPONSE_OK) {
 		user = user_settings_dialog_get_data (dialog);
 
+		if (!user) /* Means an error has already occurred and been displayed, stop here */
+			return;
+
 		config = OOBS_USERS_CONFIG (GST_USERS_TOOL (tool)->users_config);
 		users_list = oobs_users_config_get_users (config);
 		oobs_list_append (users_list, &list_iter);
 		oobs_list_set (users_list, &list_iter, user);
 
 		users_table_add_user (user, &list_iter);
-		gst_tool_commit (tool, GST_USERS_TOOL (tool)->users_config);
-		gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
+
+		/* Avoid committing group changes if the user has not been created */
+		if (gst_tool_commit (tool, GST_USERS_TOOL (tool)->users_config) == OOBS_RESULT_OK)
+			gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
 	}
 }
 
@@ -339,6 +344,10 @@ on_user_settings_clicked (GtkButton *button, gpointer user_data)
 		gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
 								  &filter_iter, &iter);
 		user = user_settings_dialog_get_data (dialog);
+
+		if (!user) /* Means an error has already occurred and been displayed, stop here */
+			return;
+
 		users_table_set_user (user, list_iter, &filter_iter);
 
 		if (gst_dialog_is_authenticated (tool->main_dialog)) {
diff --git a/src/users/user-settings.c b/src/users/user-settings.c
index 92c1b3f..2c5b65c 100644
--- a/src/users/user-settings.c
+++ b/src/users/user-settings.c
@@ -225,9 +225,12 @@ get_main_group (const gchar *name)
 			oobs_list_set (groups_list, &list_iter, group);
 
 			groups_table_add_group (group, &list_iter);
-			gst_tool_commit (tool, OOBS_OBJECT (config));
-
-			return group;
+			if (gst_tool_commit (tool, OOBS_OBJECT (config)) == OOBS_RESULT_OK)
+				return group;
+			else
+			/* Don't go beyond that point, something bad is happening,
+			 * gst_tool_commit () must already have displayed an error */
+				return NULL;
 		}
 		else /* Group exists, use it */
 			return group;
@@ -818,6 +821,12 @@ user_settings_dialog_get_data (GtkWidget *dialog)
 
 	/* set main group */
 	group = get_main_group (oobs_user_get_login_name (user));
+
+	/* If NULL, group could not be found or created, which means
+	 * we won't be able to create the new user anyway, so stop here */
+	if (!group)
+		return NULL;
+
 	oobs_group_add_user (group, user);
 	oobs_user_set_main_group (user, group);
 	g_object_unref (group);



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