Commit 722df758 authored by Murray Cumming's avatar Murray Cumming
Browse files

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.
parent 4c29d921
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.
......
......@@ -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";
......
......@@ -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.
......
......@@ -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)
{
......
......@@ -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()
{
......
......@@ -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.
*/
......
......@@ -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();
}
}
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment