[gnome-system-tools] Improve main group handling



commit b4145a78f19568dd55dccb43de7af70fb302d8cd
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Tue Jan 5 16:49:24 2010 +0100

    Improve main group handling
    
    When creating users, let the backends create the main group as the system sees fit. This makes things simpler, allowing to remove set_main_group(), replaced by a much simpler logic in on_user_edit_advanced().

 src/users/user-settings.c |  100 +++++++++++----------------------------------
 1 files changed, 24 insertions(+), 76 deletions(-)
---
diff --git a/src/users/user-settings.c b/src/users/user-settings.c
index 5020777..3eb788d 100644
--- a/src/users/user-settings.c
+++ b/src/users/user-settings.c
@@ -201,17 +201,15 @@ select_main_group (OobsUser *user)
 
 	combo = gst_dialog_get_widget (tool->main_dialog, "user_settings_group");
 
-	if (!user) {
+	main_group = oobs_user_get_main_group (user);
+
+	if (!main_group) {
 		gtk_combo_box_set_active (GTK_COMBO_BOX (combo), -1);
 		return;
 	}
 
-	main_group = oobs_user_get_main_group (user);
 	found = FALSE;
 
-	if (!main_group)
-		main_group = oobs_users_config_get_default_group (OOBS_USERS_CONFIG (GST_USERS_TOOL (tool)->users_config));
-
 	model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
 	valid = gtk_tree_model_get_iter_first (model, &iter);
 
@@ -233,68 +231,6 @@ select_main_group (OobsUser *user)
 		gtk_combo_box_set_active (GTK_COMBO_BOX (combo), -1);
 }
 
-static gboolean
-set_main_group (OobsUser *user)
-{
-	GtkWidget *combo;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-	OobsGroup *group;
-	OobsGroupsConfig *config;
-	OobsList *groups_list;
-	OobsListIter list_iter;
-	const gchar *name;
-	gboolean is_group_new = FALSE;
-
-
-	name = oobs_user_get_login_name (user);
-	combo = gst_dialog_get_widget (tool->main_dialog, "user_settings_group");
-	model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
-
-	if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
-		config = OOBS_GROUPS_CONFIG (GST_USERS_TOOL (tool)->groups_config);
-		group =	oobs_groups_config_get_from_name (config, name);
-
-		/* Most standard case when creating user:
-		 * no group using the login already exists, so create it */
-		if (group == NULL) {
-			is_group_new = TRUE;
-			group = oobs_group_new (name);
-			oobs_group_set_gid (group,
-			                    oobs_groups_config_find_free_gid (config, 0, 0));
-
-			/* FIXME: this should be in a generic function */
-			groups_list = oobs_groups_config_get_groups (config);
-			oobs_list_append (groups_list, &list_iter);
-			oobs_list_set (groups_list, &list_iter, group);
-		}
-		/* Else group exists, use it */
-	}
-	else { /* Group has been chosen in the list, use it */
-		gtk_tree_model_get (model, &iter,
-				    COL_GROUP_OBJECT, &group,
-				    -1);
-	}
-
-	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)
-			groups_table_add_group (group);
-
-		/* This will be committed with the user himself */
-		oobs_user_set_main_group (user, group);
-
-		g_object_unref (group);
-		return TRUE;
-	}
-
-	/* Something bad is happening, don't try to create the user.
-	 * gst_tool_commit () must already have displayed an error. */
-	return FALSE;
-}
-
 /* Retrieve the NO_PASSWD_LOGIN_GROUP.
  * Don't forget to unref the returned group when done. */
 static OobsGroup *
@@ -1002,7 +938,9 @@ on_user_new (GtkButton *button, gpointer user_data)
 	if (response != GTK_RESPONSE_OK)
 		return;
 
-	/* create user with base data entered by the user */
+	/* Create user with base data entered by the user.
+	   Main group will be automatically managed by the backends,
+	   following the system configuration. */
 	login = gtk_combo_box_get_active_text (GTK_COMBO_BOX (user_login));
 	fullname = gtk_entry_get_text (GTK_ENTRY (user_name));
 	user = oobs_user_new (login);
@@ -1010,14 +948,6 @@ on_user_new (GtkButton *button, gpointer user_data)
 
 	g_return_if_fail (user != NULL);
 
-	/* If FALSE, group could not be found or created, which means
-	 * we won't be able to create the new user anyway, so stop here.
-	 * Error dialog has already been shown when trying to commit changes. */
-	if (!set_main_group (user)) {
-		g_object_unref (user);
-		return;
-	}
-
 	/* fill settings with values from default profile */
 	profile = gst_user_profiles_get_default_profile (GST_USERS_TOOL (tool)->profiles);
 	gst_user_profiles_apply (GST_USERS_TOOL (tool)->profiles, profile, user, TRUE);
@@ -1303,7 +1233,10 @@ on_edit_user_advanced (GtkButton *button, gpointer user_data)
 	GtkWidget *name_label;
 	GtkWidget *uid_notice;
 	GtkWidget *widget;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
 	OobsUser *user;
+	OobsGroup *main_group;
 	int response;
 
 	TestBattery battery[] = {
@@ -1393,6 +1326,21 @@ on_edit_user_advanced (GtkButton *button, gpointer user_data)
 
 	privileges_table_save (user);
 
+	/* Get main group */
+	widget = gst_dialog_get_widget (tool->main_dialog, "user_settings_group");
+	model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
+
+	if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter) != -1) {
+		gtk_tree_model_get (model, &iter,
+				    COL_GROUP_OBJECT, &main_group,
+				    -1);
+		oobs_user_set_main_group (user, main_group);
+		g_object_unref (main_group);
+	}
+	else
+		oobs_user_set_main_group (user, NULL);
+
+
 	if (gst_tool_commit (tool, OOBS_OBJECT (user)) == OOBS_RESULT_OK)
 		gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
 



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