[gnome-system-tools/gnome-2-28] Don't commit group changes when not required (self user changes)



commit 8ce7bc501b91775e6907871a0a7b19a29134c4d4
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Sun Sep 6 15:36:01 2009 +0200

    Don't commit group changes when not required (self user changes)
    
    It's useless since modifying the self user should not lead to changing any group. This required to get .set rights, which are reserved to administrators, thus raising an error after succeeding to modify self. Also always check that we actually need to commit changes (new group, add user to group) before doing so.

 src/users/callbacks.c     |    1 -
 src/users/user-settings.c |   31 +++++++++++++++++++------------
 2 files changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/src/users/callbacks.c b/src/users/callbacks.c
index 0e1d63c..3b0fee4 100644
--- a/src/users/callbacks.c
+++ b/src/users/callbacks.c
@@ -363,7 +363,6 @@ on_user_settings_clicked (GtkButton *button, gpointer user_data)
 			/* change self, only if it is the modified user */
 			if (user == oobs_self_config_get_user (OOBS_SELF_CONFIG (object)) &&
 			    gst_tool_commit (tool, GST_USERS_TOOL (tool)->self_config) == OOBS_RESULT_OK) {
-				gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
 				users_table_set_user (user, list_iter, &filter_iter);
 			}
 #endif
diff --git a/src/users/user-settings.c b/src/users/user-settings.c
index 74c6ae2..c037aa1 100644
--- a/src/users/user-settings.c
+++ b/src/users/user-settings.c
@@ -44,6 +44,10 @@
 
 extern GstTool *tool;
 
+static gboolean is_user_in_group (OobsUser  *user,
+				  OobsGroup *group);
+
+
 static gboolean
 check_user_delete (OobsUser *user)
 {
@@ -236,23 +240,26 @@ set_main_group (OobsUser *user)
 				    -1);
 	}
 
-	oobs_group_add_user (group, user);
+	if (!is_user_in_group (user, group))
+		oobs_group_add_user (group, user);
 
 	/* Try to commit before doing anything, to avoid displaying wrong data */
-	if (gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config) == OOBS_RESULT_OK) {
-		if (is_group_new)
+	if (is_group_new) {
+		if (gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config) == OOBS_RESULT_OK)
 			groups_table_add_group (group, &list_iter);
-
-		/* This will be committed with the user himself */
-		oobs_user_set_main_group (user, group);
-
-		g_object_unref (group);
-		return TRUE;
+		else {
+			/* Something bad is happening, don't try to create the user.
+			 * gst_tool_commit () must already have displayed an error. */
+			g_object_unref (group);
+			return FALSE;
+		}
 	}
 
-	/* Something bad is happening, don't try to create the user.
-	 * gst_tool_commit () must already have displayed an error. */
-	return FALSE;
+	/* This will be committed with the user himself */
+	oobs_user_set_main_group (user, group);
+
+	g_object_unref (group);
+	return TRUE;
 }
 
 /* Retrieve the NO_PASSWD_LOGIN_GROUP.



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