[glom/feature_backup2] Saving from examples: Set the table privileges mentioned in the document.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/feature_backup2] Saving from examples: Set the table privileges mentioned in the document.
- Date: Wed, 21 Jul 2010 09:08:11 +0000 (UTC)
commit 3d1cdf5d9af3ffd3e702d3b2ed57139c50b2ba25
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Jul 21 11:07:50 2010 +0200
Saving from examples: Set the table privileges mentioned in the document.
* glom/base_db.[h|cc]: Added set_table_privileges_groups_from_document().
* glom/application.cc: recreate_database_from_example(): call it.
ChangeLog | 9 +++-
glom/application.cc | 6 ++
glom/base_db.cc | 68 +++++++++++++++++++++++++-
glom/base_db.h | 1 +
glom/mode_design/users/dialog_groups_list.cc | 3 +-
5 files changed, 83 insertions(+), 4 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 06ea47a..fcca316 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,16 @@
+2010-07-21 Murray Cumming <murrayc murrayc com>>
+
+ Saving from examples: Set the table privileges mentioned in the document.
+
+ * glom/base_db.[h|cc]: Added set_table_privileges_groups_from_document().
+ * glom/application.cc: recreate_database_from_example(): call it.
+
2010-07-21 Murray Cumming <murrayc murrayc com>
Saving from examples: Create the groups mentioned in the document.
* glom/base_db.[h|cc]: Added add_groups_from_document().
- * glom/application.cc: recreate_database_from_example() call it.
+ * glom/application.cc: recreate_database_from_example(): call it.
2010-07-20 Murray Cumming <murrayc murrayc com>>
diff --git a/glom/application.cc b/glom/application.cc
index a39b038..9660490 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -1830,6 +1830,12 @@ bool Application::recreate_database_from_example(bool& user_cancelled)
dialog_progress->pulse();
m_pFrame->add_standard_tables(); //Add internal, hidden, tables.
+ //Set table priviliges, using the groups we just added:
+ dialog_progress->pulse();
+ test = m_pFrame->set_table_privileges_groups_from_document();
+ if(!test)
+ return false;
+
for(Document::type_listTableInfo::const_iterator iter = tables.begin(); iter != tables.end(); ++iter)
{
sharedptr<const TableInfo> table_info = *iter;
diff --git a/glom/base_db.cc b/glom/base_db.cc
index f23fc6b..9001119 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -1226,6 +1226,7 @@ bool Base_DB::add_standard_groups()
if(!(sharedconnection->get_gda_connection()->supports_feature(Gnome::Gda::CONNECTION_FEATURE_USERS)))
{
std::cout << "DEBUG: Connection does not support users" << std::endl;
+ return true;
}
const type_vec_strings vecGroups = Privs::get_database_groups();
@@ -1301,6 +1302,7 @@ bool Base_DB::add_groups_from_document()
if(!(sharedconnection->get_gda_connection()->supports_feature(Gnome::Gda::CONNECTION_FEATURE_USERS)))
{
std::cout << "DEBUG: Connection does not support users" << std::endl;
+ return true;
}
@@ -1318,7 +1320,7 @@ bool Base_DB::add_groups_from_document()
const GroupInfo& group = *iter;
const Glib::ustring name = group.get_name();
- //See if the group exists in the document:
+ //See if the group exists in the database:
type_vec_strings::const_iterator iterFind = std::find(database_groups.begin(), database_groups.end(), name);
if(!name.empty() && iterFind == database_groups.end())
{
@@ -1341,6 +1343,70 @@ bool Base_DB::add_groups_from_document()
return true;
}
+bool Base_DB::set_table_privileges_groups_from_document()
+{
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+ sharedptr<SharedConnection> sharedconnection = connect_to_server();
+#else
+ std::auto_ptr<ExceptionConnection> error;
+ sharedptr<SharedConnection> sharedconnection = connect_to_server(0, error);
+ if(error.get())
+ {
+ g_warning("Base_DB::add_standard_groups: Failed to connect: %s", error->what());
+ // TODO: Rethrow?
+ }
+#endif
+
+ // If the connection doesn't support users we can skip this step
+ if(!(sharedconnection->get_gda_connection()->supports_feature(Gnome::Gda::CONNECTION_FEATURE_USERS)))
+ {
+ std::cout << "DEBUG: Connection does not support users" << std::endl;
+ return true;
+ }
+
+
+ //Get the list of groups from the database server:
+ const type_vec_strings database_groups = Privs::get_database_groups();
+
+ //Get the list of groups from the document:
+ Document* document = get_document();
+ const Document::type_list_groups document_groups = document->get_groups();
+
+ //Get the list of tables:
+ const Document::type_listTableInfo table_list = document->get_tables();
+
+ bool result = true;
+
+ for(Document::type_list_groups::const_iterator iter = document_groups.begin();
+ iter != document_groups.end(); ++iter)
+ {
+ const GroupInfo& group_info = *iter;
+ const Glib::ustring group_name = group_info.get_name();
+
+ //See if the group exists in the database:
+ type_vec_strings::const_iterator iterFind = std::find(database_groups.begin(), database_groups.end(), group_name);
+ if(!group_name.empty() && iterFind == database_groups.end())
+ {
+ std::cerr << G_STRFUNC << ": group does not exist in the database. group name=" << group_name << std::endl;
+ result = false;
+ continue;
+ }
+
+ //Look at each table privilege for this group:
+ for(GroupInfo::type_map_table_privileges::const_iterator iter = group_info.m_map_privileges.begin();
+ iter != group_info.m_map_privileges.end(); ++iter)
+ {
+ const Glib::ustring table_name = iter->first;
+ const Privileges& privs = iter->second;
+
+ //Set the table privilege for the group:
+ Privs::set_table_privileges(group_name, table_name, privs, group_info.m_developer);
+ }
+ }
+
+ return result;
+}
+
void Base_DB::set_database_preferences(const SystemPrefs& prefs)
{
if(get_userlevel() == AppState::USERLEVEL_DEVELOPER)
diff --git a/glom/base_db.h b/glom/base_db.h
index 2850cbc..b758022 100644
--- a/glom/base_db.h
+++ b/glom/base_db.h
@@ -100,6 +100,7 @@ public:
bool create_table(const sharedptr<const TableInfo>& table_info, const Document::type_vec_fields& fields) const;
bool create_table_add_missing_fields(const sharedptr<const TableInfo>& table_info, const Document::type_vec_fields& fields) const;
+ bool set_table_privileges_groups_from_document();
/// Also saves the table information in the document:
bool create_table_with_default_fields(const Glib::ustring& table_name);
diff --git a/glom/mode_design/users/dialog_groups_list.cc b/glom/mode_design/users/dialog_groups_list.cc
index 7fd3fa8..5cbbd91 100644
--- a/glom/mode_design/users/dialog_groups_list.cc
+++ b/glom/mode_design/users/dialog_groups_list.cc
@@ -439,6 +439,7 @@ void Dialog_GroupsList::treeview_append_bool_column(Gtk::TreeView& treeview, con
pCellRenderer->signal_toggled().connect( slot_toggled );
}
+//TODO: Use Privs::set_table_privileges() instead?
bool Dialog_GroupsList::set_table_privilege(const Glib::ustring& table_name, const Glib::ustring& group_name, bool grant, enumPriv priv)
{
if(group_name.empty() || table_name.empty())
@@ -615,5 +616,3 @@ void Dialog_GroupsList::on_cell_data_group_name(Gtk::CellRenderer* renderer, con
}
} //namespace Glom
-
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]