[glom] test_selfhosting_new_empty_then_users: Test user removal.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] test_selfhosting_new_empty_then_users: Test user removal.
- Date: Thu, 2 Feb 2012 09:52:28 +0000 (UTC)
commit 722df7580315d533367c406dadb33ba0e191bccc
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Feb 2 10:44:17 2012 +0100
test_selfhosting_new_empty_then_users: Test user removal.
* glom/base_db.[h|cc]: Move remove_user() and
remove_user_from_group() to
* glom/libglom/db_utils.[h|cc].
* glom/frame_glom.cc:
* glom/mode_design/users/dialog_users_list.cc: Adapted.
* tests/test_selfhosting_new_empty_then_users.cc: Test these
functions.
ChangeLog | 12 +++++
glom/base_db.cc | 35 +--------------
glom/base_db.h | 7 ---
glom/frame_glom.cc | 2 +-
glom/libglom/db_utils.cc | 31 +++++++++++++
glom/libglom/db_utils.h | 6 +++
glom/mode_design/users/dialog_users_list.cc | 4 +-
tests/test_selfhosting_new_empty_then_users.cc | 58 ++++++++++++++++--------
8 files changed, 92 insertions(+), 63 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 9cd1488..f7e5292 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2012-02-02 Murray Cumming <murrayc murrayc com>
+ test_selfhosting_new_empty_then_users: Test user removal.
+
+ * glom/base_db.[h|cc]: Move remove_user() and
+ remove_user_from_group() to
+ * glom/libglom/db_utils.[h|cc].
+ * glom/frame_glom.cc:
+ * glom/mode_design/users/dialog_users_list.cc: Adapted.
+ * tests/test_selfhosting_new_empty_then_users.cc: Test these
+ functions.
+
+2012-02-02 Murray Cumming <murrayc murrayc com>
+
Really prevent changing to developer mode for non-developers.
* glom/frame_glom.cc: on_menu_developer_developer(): Actually use the
diff --git a/glom/base_db.cc b/glom/base_db.cc
index 039d11f..18f992c 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -1584,39 +1584,6 @@ void Base_DB::set_found_set_where_clause_for_portal(FoundSet& found_set, const s
}
}
-//TODO: Move this into libglom and test it.
-bool Base_DB::remove_user(const Glib::ustring& user)
-{
- if(user.empty())
- return false;
-
- const Glib::ustring strQuery = "DROP USER " + DbUtils::escape_sql_id(user);
- const bool test = DbUtils::query_execute_string(strQuery);
- if(!test)
- {
- std::cerr << G_STRFUNC << ": DROP USER failed" << std::endl;
- return false;
- }
-
- return true;
-}
-
-bool Base_DB::remove_user_from_group(const Glib::ustring& user, const Glib::ustring& group)
-{
- if(user.empty() || group.empty())
- return false;
-
- const Glib::ustring strQuery = "ALTER GROUP " + DbUtils::escape_sql_id(group) + " DROP USER " + DbUtils::escape_sql_id(user);
- const bool test = DbUtils::query_execute_string(strQuery);
- if(!test)
- {
- std::cerr << G_STRFUNC << ": ALTER GROUP failed." << std::endl;
- return false;
- }
-
- return true;
-}
-
bool Base_DB::set_database_owner_user(const Glib::ustring& user)
{
if(user.empty())
@@ -1648,7 +1615,7 @@ bool Base_DB::disable_user(const Glib::ustring& user)
for(type_vec_strings::const_iterator iter = vecGroups.begin(); iter != vecGroups.end(); ++iter)
{
const Glib::ustring group = *iter;
- remove_user_from_group(user, group);
+ DbUtils::remove_user_from_group(user, group);
}
const Glib::ustring strQuery = "ALTER ROLE " + DbUtils::escape_sql_id(user) + " NOLOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE";
diff --git a/glom/base_db.h b/glom/base_db.h
index 36f9fcb..5365a48 100644
--- a/glom/base_db.h
+++ b/glom/base_db.h
@@ -290,13 +290,6 @@ protected:
typedef std::vector<Glib::ustring> type_vec_strings;
static type_vec_strings util_vecStrings_from_Fields(const type_vec_fields& fields);
- /** Remove the @a user from the database.
- * @result true if the removal succeeded.
- */
- bool remove_user(const Glib::ustring& user);
-
- bool remove_user_from_group(const Glib::ustring& user, const Glib::ustring& group);
-
bool set_database_owner_user(const Glib::ustring& user);
/** Revoke any login rights from the user and remove it from any groups.
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index af1ce3b..5b1990f 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -896,7 +896,7 @@ void Frame_Glom::on_menu_file_toggle_share(const Glib::RefPtr<Gtk::ToggleAction>
const bool reowned = set_database_owner_user(connectionpool->get_user());
bool removed = false;
if(reowned)
- removed = remove_user(default_user);
+ removed = DbUtils::remove_user(default_user);
if(!removed)
{
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index 77d302f..60084c5 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -2143,6 +2143,37 @@ bool add_group(const Document* document, const Glib::ustring& group)
return true;
}
+bool remove_user(const Glib::ustring& user)
+{
+ if(user.empty())
+ return false;
+
+ const Glib::ustring strQuery = "DROP USER " + DbUtils::escape_sql_id(user);
+ const bool test = DbUtils::query_execute_string(strQuery);
+ if(!test)
+ {
+ std::cerr << G_STRFUNC << ": DROP USER failed" << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+bool remove_user_from_group(const Glib::ustring& user, const Glib::ustring& group)
+{
+ if(user.empty() || group.empty())
+ return false;
+
+ const Glib::ustring strQuery = "ALTER GROUP " + DbUtils::escape_sql_id(group) + " DROP USER " + DbUtils::escape_sql_id(user);
+ const bool test = DbUtils::query_execute_string(strQuery);
+ if(!test)
+ {
+ std::cerr << G_STRFUNC << ": ALTER GROUP failed." << std::endl;
+ return false;
+ }
+
+ return true;
+}
void set_fake_connection()
{
diff --git a/glom/libglom/db_utils.h b/glom/libglom/db_utils.h
index dce560e..59f708e 100644
--- a/glom/libglom/db_utils.h
+++ b/glom/libglom/db_utils.h
@@ -184,11 +184,17 @@ Glib::ustring build_query_add_user_to_group(const Glib::ustring& group, const Gl
*/
bool add_user(const Document* document, const Glib::ustring& user, const Glib::ustring& password, const Glib::ustring& group);
+/** Remove the @a user from the database.
+ * @result true if the removal succeeded.
+ */
+bool remove_user(const Glib::ustring& user);
+
/** Add a @a group to the database.
* @result true if the addition succeeded.
*/
bool add_group(const Document* document, const Glib::ustring& group);
+bool remove_user_from_group(const Glib::ustring& user, const Glib::ustring& group);
/** Get the value of the @a source_field from the @a relationship, using the @a key_value.
*/
diff --git a/glom/mode_design/users/dialog_users_list.cc b/glom/mode_design/users/dialog_users_list.cc
index 31b7749..a6a0b6f 100644
--- a/glom/mode_design/users/dialog_users_list.cc
+++ b/glom/mode_design/users/dialog_users_list.cc
@@ -131,7 +131,7 @@ void Dialog_UsersList::on_button_user_remove()
const Glib::ustring user = row[m_model_columns_users.m_col_name];
if(!user.empty())
{
- remove_user_from_group(user, m_combo_group->get_active_text());
+ DbUtils::remove_user_from_group(user, m_combo_group->get_active_text());
fill_list();
}
@@ -167,7 +167,7 @@ void Dialog_UsersList::on_button_user_delete()
if(response == Gtk::RESPONSE_OK)
{
- remove_user(user);
+ DbUtils::remove_user(user); //TODO: Warn about failure when this returns false?
fill_list();
}
}
diff --git a/tests/test_selfhosting_new_empty_then_users.cc b/tests/test_selfhosting_new_empty_then_users.cc
index e75cc3d..a5e7509 100644
--- a/tests/test_selfhosting_new_empty_then_users.cc
+++ b/tests/test_selfhosting_new_empty_then_users.cc
@@ -85,6 +85,33 @@ static bool test_add_user(const Glom::Document& document, const Glib::ustring& u
}
+static bool change_privileges(const Glib::ustring& group_name, const Glib::ustring& table_name, bool view, bool edit, bool create, bool del)
+{
+ //Change the privs and make sure that it worked:
+ Glom::Privileges privs_new;
+ privs_new.m_view = view;
+ privs_new.m_edit = edit;
+ privs_new.m_create = create;
+ privs_new.m_delete = del;
+ if(!Glom::Privs::set_table_privileges(group_name, table_name, privs_new, false))
+ {
+ std::cerr << "Privs::set_table_privileges() failed for group=" << group_name << ", table_name=" << table_name << std::endl;
+ return false;
+ }
+
+ const Glom::Privileges privs_changed = Glom::Privs::get_table_privileges(group_name, table_name);
+ if( (privs_changed.m_view != privs_new.m_view) ||
+ (privs_changed.m_edit != privs_new.m_edit) ||
+ (privs_changed.m_create != privs_new.m_create) ||
+ (privs_changed.m_delete != privs_new.m_delete) )
+ {
+ std::cerr << "Changing and re-reading privileges failed for group=" << group_name << ", table_name=" << table_name << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
static bool test(Glom::Document::HostingMode hosting_mode)
{
//Create and self-host the document:
@@ -202,27 +229,20 @@ static bool test(Glom::Document::HostingMode hosting_mode)
}
*/
- //Change the privs and make sure that it worked:
- Glom::Privileges privs_new;
- privs_new.m_view = true;
- privs_new.m_edit = true;
- privs_new.m_create = true;
- privs_new.m_delete = false;
- if(!Glom::Privs::set_table_privileges(group_name, table_name, privs_new, false))
- {
- std::cerr << "Privs::set_table_privileges() failed for group=" << group_name << ", table_name=" << table_name << std::endl;
+ if(!change_privileges(group_name, table_name, true, true, true, false))
return false;
- }
+ }
- const Glom::Privileges privs_changed = Glom::Privs::get_table_privileges(group_name, table_name);
- if( (privs_changed.m_view != privs_new.m_view) ||
- (privs_changed.m_edit != privs_new.m_edit) ||
- (privs_changed.m_create != privs_new.m_create) ||
- (privs_changed.m_delete != privs_new.m_delete) )
- {
- std::cerr << "Changing and re-reading privileges failed for group=" << group_name << ", table_name=" << table_name << std::endl;
- return false;
- }
+ if(!Glom::DbUtils::remove_user_from_group(username, group_name))
+ {
+ std::cerr << "DbUtils::remove_user() failed for user=" << username << ", group=" << group_name << std::endl;
+ return false;
+ }
+
+ if(!Glom::DbUtils::remove_user(username))
+ {
+ std::cerr << "DbUtils::remove_user() failed for user=" << username << std::endl;
+ return false;
}
++i;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]