[gnome-system-tools] Use new oobs_object_authenticate() in users-admin



commit f7e4acaee6351783e8bd5b392db9fa7fb5c8075b
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Sun Jan 17 12:35:20 2010 +0100

    Use new oobs_object_authenticate() in users-admin
    
    New wrapper gst_tool_authenticate() is used to ask for authentication before showing edit dialogs. This way, we don't pretend the user will be able to commit changes when he may not. Password edit dialog uses a more complex schema that will come later. This requires liboobs 2.29.3.
    
    Remove actions_set_sensitive(): we no longer grey out widgets since unlock button is gone. Don't check that dialog is authenticated when double-clicking on the groups table.

 configure.in              |    2 +-
 src/common/gst-tool.c     |   37 +++++++++++++++++++++++++++++++++
 src/common/gst-tool.h     |    3 ++
 src/users/callbacks.c     |   50 ++++++++++++++------------------------------
 src/users/user-settings.c |   42 ++++++++++++++++++++++++++++++++-----
 5 files changed, 93 insertions(+), 41 deletions(-)
---
diff --git a/configure.in b/configure.in
index bd2229f..0a5c471 100644
--- a/configure.in
+++ b/configure.in
@@ -29,7 +29,7 @@ dnl glib-genmarshal
 AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
 
 STB_REQUIRED=2.8
-LIBOOBS_REQUIRED=2.29.2
+LIBOOBS_REQUIRED=2.29.3
 GTK_REQUIRED=2.16
 GLIB_REQUIRED=2.15.2
 GCONF_REQUIRED=2.2.0
diff --git a/src/common/gst-tool.c b/src/common/gst-tool.c
index 645b205..9622748 100644
--- a/src/common/gst-tool.c
+++ b/src/common/gst-tool.c
@@ -658,3 +658,40 @@ gst_tool_add_configuration_object (GstTool    *tool,
 	g_signal_connect (object, "committed",
 			  G_CALLBACK (configuration_object_committed), tool);
 }
+
+/*
+ * Wrapper around oobs_object_authenticate() to show an error dialog if needed.
+ */
+gboolean
+gst_tool_authenticate (GstTool    *tool,
+                       OobsObject *object)
+{
+	gboolean result;
+	GError *error = NULL;
+
+        result = oobs_object_authenticate (object, &error);
+
+	/* Don't show an error if the user manually cancelled authentication */
+	if (error && error->code != OOBS_ERROR_AUTHENTICATION_CANCELLED) {
+		GtkWidget *dialog;
+
+		dialog = gtk_message_dialog_new (GTK_WINDOW (tool->main_dialog),
+		                                 GTK_DIALOG_MODAL,
+		                                 GTK_MESSAGE_ERROR,
+		                                 GTK_BUTTONS_CLOSE,
+		                                 "%s",
+		                                 _("You are not allowed to modify the system configuration."));
+		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+		                                          _("An error occurred while checking for authorizations: %s\n"
+		                                            "You may report this as a bug."),
+		                                          error->message);
+		gtk_dialog_run (GTK_DIALOG (dialog));
+
+		gtk_widget_destroy (dialog);
+	}
+
+	if (error)
+		g_error_free (error);
+
+	return result;
+}
diff --git a/src/common/gst-tool.h b/src/common/gst-tool.h
index 56aa0f5..a18fdab 100644
--- a/src/common/gst-tool.h
+++ b/src/common/gst-tool.h
@@ -120,6 +120,9 @@ void         gst_tool_update_async    (GstTool             *tool);
 void         gst_tool_add_configuration_object (GstTool    *tool,
 						OobsObject *object);
 
+gboolean     gst_tool_authenticate    (GstTool *tool,
+				       OobsObject *object);
+
 
 G_END_DECLS
 
diff --git a/src/users/callbacks.c b/src/users/callbacks.c
index 25d2261..27962e2 100644
--- a/src/users/callbacks.c
+++ b/src/users/callbacks.c
@@ -40,35 +40,6 @@ extern GstTool *tool;
 
 /* Common stuff to users and groups tables */
 
-static void
-actions_set_sensitive (gint table, gint count)
-{
-	switch (table) {
-	case TABLE_USERS:
-		gst_dialog_try_set_sensitive (tool->main_dialog,
-					      gst_dialog_get_widget (tool->main_dialog, "user_new"),
-					      TRUE);
-		gst_dialog_try_set_sensitive (tool->main_dialog,
-					      gst_dialog_get_widget (tool->main_dialog, "user_delete"),
-					      (count > 0));
-		break;
-	case TABLE_GROUPS:
-		gst_dialog_try_set_sensitive (tool->main_dialog,
-					      gst_dialog_get_widget (tool->main_dialog, "group_new"),
-					      TRUE);
-		gst_dialog_try_set_sensitive (tool->main_dialog,
-					      gst_dialog_get_widget (tool->main_dialog, "group_delete"),
-					      (count > 0));
-		gst_dialog_try_set_sensitive (tool->main_dialog,
-					      gst_dialog_get_widget (tool->main_dialog, "group_settings"),
-					      (count == 1));
-		break;
-	default:
-		g_assert_not_reached ();
-		return;
-	}
-}
-
 void
 on_table_selection_changed (GtkTreeSelection *selection, gpointer data)
 {
@@ -86,8 +57,6 @@ on_table_selection_changed (GtkTreeSelection *selection, gpointer data)
 	if (!user)
 		return;
 
-	actions_set_sensitive (table, count);
-
 	/* Show the settings for the selected user */
 	user_settings_show (user);
 
@@ -159,8 +128,7 @@ on_table_button_press (GtkTreeView *treeview, GdkEventButton *event, gpointer da
 	}
 
 	if (cont != 0 && (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS)
-	    && (table == TABLE_GROUPS)
-	    && gst_dialog_is_authenticated (tool->main_dialog))
+	    && (table == TABLE_GROUPS))
 		on_group_settings_clicked (NULL, NULL);
 
 	return FALSE;
@@ -227,6 +195,10 @@ on_group_new_clicked (GtkButton *button, gpointer user_data)
 	OobsResult result;
 	gint response;
 
+	/* Before going further, check for authorizations, authenticating if needed */
+	if (!gst_tool_authenticate (tool, GST_USERS_TOOL (tool)->groups_config))
+		return;
+
 	group = oobs_group_new (NULL);
 	parent_dialog = gst_dialog_get_widget (tool->main_dialog, "groups_dialog");
 	dialog = group_settings_dialog_new (group);
@@ -269,13 +241,19 @@ on_group_settings_clicked (GtkButton *button, gpointer user_data)
 	gtk_tree_model_get (model, &iter,
 			    COL_GROUP_OBJECT, &group,
 			    -1);
+	
 	dialog = group_settings_dialog_new (group);
 	parent_dialog = gst_dialog_get_widget (tool->main_dialog, "groups_dialog");
 
 	gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent_dialog));
 	response = group_settings_dialog_run (dialog, group);
 
-	if (response == GTK_RESPONSE_OK) {
+	/* This is the only dialog we show without authentication, because it's the only
+	 * way to get some informations. Committing without authorization could leave
+	 * changes in queue in case of failure, which would get committed with
+	 * the first successful commit later! */
+	if (response == GTK_RESPONSE_OK
+	    && gst_tool_authenticate (tool, OOBS_OBJECT (group))) {
 		group_settings_dialog_get_data (group);
 		groups_table_set_group (group, &iter);
 		gst_tool_commit (tool, GST_USERS_TOOL (tool)->groups_config);
@@ -293,6 +271,10 @@ on_group_delete_clicked (GtkButton *button, gpointer user_data)
 
 	list = elem = table_get_row_references (TABLE_GROUPS, &model);
 
+	/* Before going further, check for authorizations, authenticating if needed */
+	if (!gst_tool_authenticate (tool, GST_USERS_TOOL (tool)->groups_config))
+		return;
+
 	while (elem) {
 		path = gtk_tree_row_reference_get_path (elem->data);
 		group_delete (model, path);
diff --git a/src/users/user-settings.c b/src/users/user-settings.c
index dbaccbb..f9ab4cb 100644
--- a/src/users/user-settings.c
+++ b/src/users/user-settings.c
@@ -921,6 +921,10 @@ on_user_new (GtkButton *button, gpointer user_data)
 	OobsUsersConfig *users_config;
 	OobsResult result;
 
+	/* Before going further, check for authorizations, authenticating if needed */
+	if (!gst_tool_authenticate (tool, GST_USERS_TOOL (tool)->users_config))
+		return;
+
 	user_new_dialog = gst_dialog_get_widget (tool->main_dialog, "user_new_dialog");
 	user_name = gst_dialog_get_widget (tool->main_dialog, "user_new_name");
 	user_login = gst_dialog_get_widget (tool->main_dialog, "user_new_login");
@@ -1036,13 +1040,27 @@ on_edit_user_name (GtkButton *button, gpointer user_data)
 	GtkWidget *name_label;
 	OobsUser *user;
 	const char *fullname;
+	gboolean is_self;
+
+	user = users_table_get_current ();
+
+	/* Before going further, check for authorizations, authenticating if needed */
+	is_self = oobs_self_config_is_user_self (OOBS_SELF_CONFIG (GST_USERS_TOOL (tool)->self_config),
+	                                         user);
+
+	/* Authenticate as self when changing self user, as admin for all other users */
+	if (is_self) {
+		if (!gst_tool_authenticate (tool, GST_USERS_TOOL (tool)->self_config))
+			return;
+	}
+	else if (!gst_tool_authenticate (tool, OOBS_OBJECT (user)))
+		return;
 
 	user_name_dialog = gst_dialog_get_widget (tool->main_dialog, "user_name_dialog");
 	user_name_entry = gst_dialog_get_widget (tool->main_dialog, "user_name_entry");
 	face_image = gst_dialog_get_widget (tool->main_dialog, "user_name_face");
 	name_label = gst_dialog_get_widget (tool->main_dialog, "user_name_name");
 
-	user = users_table_get_current ();
 	fullname = oobs_user_get_full_name (user);
 	gtk_entry_set_text (GTK_ENTRY (user_name_entry), fullname);
 	gtk_editable_select_region (GTK_EDITABLE (user_name_entry), 0, -1);
@@ -1056,7 +1074,11 @@ on_edit_user_name (GtkButton *button, gpointer user_data)
 
 		fullname = gtk_entry_get_text (GTK_ENTRY (user_name_entry));
 		oobs_user_set_full_name (user, fullname);
-		gst_tool_commit (tool, OOBS_OBJECT (user));
+
+		if (is_self)
+			gst_tool_commit (tool, GST_USERS_TOOL (tool)->self_config);
+		else
+			gst_tool_commit (tool, OOBS_OBJECT (user));
 	}
 
 	g_object_unref (user);
@@ -1185,6 +1207,12 @@ on_edit_user_profile (GtkButton *button, gpointer user_data)
 	OobsUser *user;
 	GstUserProfile *profile;
 
+	user = users_table_get_current ();
+
+	/* Before going further, check for authorizations, authenticating if needed */
+	if (!gst_tool_authenticate (tool, OOBS_OBJECT (user)))
+		return;
+
 	user_profile_dialog = gst_dialog_get_widget (tool->main_dialog, "user_profile_dialog");
 	face_image = gst_dialog_get_widget (tool->main_dialog, "user_profile_face");
 	name_label = gst_dialog_get_widget (tool->main_dialog, "user_profile_name");
@@ -1192,8 +1220,6 @@ on_edit_user_profile (GtkButton *button, gpointer user_data)
 	custom_radio = gst_dialog_get_widget (tool->main_dialog, "user_profile_custom");
 	custom_label = gst_dialog_get_widget (tool->main_dialog, "user_profile_custom_label");
 
-	user = users_table_get_current ();
-
 	/* select the profile that matches the user settings, if any */
 	profile = gst_user_profiles_get_for_user (GST_USERS_TOOL (tool)->profiles,
 	                                          user, FALSE);
@@ -1262,12 +1288,16 @@ on_edit_user_advanced (GtkButton *button, gpointer user_data)
 		NULL
 	};
 
+	user = users_table_get_current ();
+
+	/* Before going further, check for authorizations, authenticating if needed */
+	if (!gst_tool_authenticate (tool, OOBS_OBJECT (user)))
+		return;
+
 	user_advanced_dialog = gst_dialog_get_widget (tool->main_dialog, "user_advanced_dialog");
 	face_image = gst_dialog_get_widget (tool->main_dialog, "user_advanced_face");
 	name_label = gst_dialog_get_widget (tool->main_dialog, "user_advanced_name");
 
-	user = users_table_get_current ();
-
 
 	/* set various settings */
 	widget = gst_dialog_get_widget (tool->main_dialog, "user_settings_room_number");



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