[glom/glom-1-20] Users: Warn if we cannot get the list of users.



commit a7285d54a2566d5956bcbcbdbda0829919c6e99e
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Feb 13 13:31:50 2012 +0100

    Users: Warn if we cannot get the list of users.
    
    * glom/libglom/privs.[h|cc]: get_database_users(): Add documentation
    about the case that the result is empty.
    * glom/mode_design/users/dialog_users_list.cc: on_button_user_add():
    If the users list is empty then warn that something is probably wrong
    with the permissions. I would like to warn much earlier if the user is
    not a superuser, but I do not know how.
    Bug #669178 (alien)

 ChangeLog                                   |   12 ++++++++++++
 glom/libglom/privs.cc                       |    4 ++++
 glom/libglom/privs.h                        |    1 +
 glom/mode_design/users/dialog_users_list.cc |   12 ++++++++++--
 4 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b91ab19..c89ff9d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2012-02-13  Murray Cumming  <murrayc murrayc com>
+
+	Users: Warn if we cannot get the list of users.
+
+	* glom/libglom/privs.[h|cc]: get_database_users(): Add documentation
+	about the case that the result is empty.
+	* glom/mode_design/users/dialog_users_list.cc: on_button_user_add():
+	If the users list is empty then warn that something is probably wrong
+	with the permissions. I would like to warn much earlier if the user is
+	not a superuser, but I do not know how.
+	Bug #669178 (alien)
+
 2012-02-09  Murray Cumming  <murrayc murrayc com>
 
 	Print Layout: Print Preview: Avoid warnings when there are no records yet.
diff --git a/glom/libglom/privs.cc b/glom/libglom/privs.cc
index 58d72c0..ba6d24f 100644
--- a/glom/libglom/privs.cc
+++ b/glom/libglom/privs.cc
@@ -100,6 +100,10 @@ Privs::type_vec_strings Privs::get_database_users(const Glib::ustring& group_nam
 {
   //TODO_Moved: BusyCursor cursor(Application::get_application());
 
+  //Note that these queries can fail with "permission denied for relation pg_shadow" if the user is not a superuser.
+  //So the caller should interpret an empty result for group_name="" as an error,
+  //because there should always be at least one user.
+
   type_vec_strings result;
 
   if(group_name.empty())
diff --git a/glom/libglom/privs.h b/glom/libglom/privs.h
index 38d97d7..a323b9c 100644
--- a/glom/libglom/privs.h
+++ b/glom/libglom/privs.h
@@ -47,6 +47,7 @@ public:
   static type_vec_strings get_database_groups();
 
   /** Get users with access to the database.
+   * If the resuilt is empty even when @a group_name is empty then it was not possible to get the list of users, probably due to a permissions problem.
    * @param group_name Get only users in this group.
    */
   static type_vec_strings get_database_users(const Glib::ustring& group_name = Glib::ustring());
diff --git a/glom/mode_design/users/dialog_users_list.cc b/glom/mode_design/users/dialog_users_list.cc
index e6a22e4..61e9eb1 100644
--- a/glom/mode_design/users/dialog_users_list.cc
+++ b/glom/mode_design/users/dialog_users_list.cc
@@ -182,6 +182,15 @@ void Dialog_UsersList::on_button_user_delete()
 
 void Dialog_UsersList::on_button_user_add()
 {
+  //Fill it with the list of users:
+  const Privs::type_vec_strings users = Privs::get_database_users();
+  if(users.empty())
+  {
+    Utils::show_ok_dialog(_("Error Retrieving the List of Users"),
+      _("Glom could not get the list of users from the database server. You probably do not have enough permissions. You should be a superuser."), *this, Gtk::MESSAGE_ERROR);
+    return;
+  }
+
   Dialog_ChooseUser* dialog = 0;
   Utils::get_glade_widget_derived_with_warning(dialog);
   if(!dialog) //Unlikely and it already warns on stderr.
@@ -189,8 +198,7 @@ void Dialog_UsersList::on_button_user_add()
 
   dialog->set_transient_for(*this);
 
-  //Fill it with the list of users:
-  dialog->set_user_list( Privs::get_database_users() );
+  dialog->set_user_list(users);
 
   const int response = Glom::Utils::dialog_run_with_help(dialog);
 



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