From f5be07e14f893f5be1770f200ed8a6e7b663fe99 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Tue, 27 Jul 2010 09:57:37 +0200 Subject: [PATCH] Missing parents loading on load from db. --- .gitignore | 1 + docs/reference/autoz-decl-list.txt | 28 +++++----- docs/reference/autoz-decl.txt | 82 ++++++++++++++--------------- docs/schema.sql | 43 +++++++++++++-- src/autoz.c | 60 +++++++++++++++++++++ tests/test_to_db.db | Bin 6144 -> 6144 bytes 6 files changed, 154 insertions(+), 60 deletions(-) diff --git a/.gitignore b/.gitignore index d08e9f9..9d8b867 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ libtool stamp-h1 tests/test tests/test_from_xml +tests/test_from_xml_to_db POTFILES mkinstalldirs stamp-it diff --git a/docs/reference/autoz-decl-list.txt b/docs/reference/autoz-decl-list.txt index 4be7fa0..0cbb355 100644 --- a/docs/reference/autoz-decl-list.txt +++ b/docs/reference/autoz-decl-list.txt @@ -1,3 +1,17 @@ +
+resource_interface +AutozIResource +AutozIResource +AutozIResourceIface +autoz_iresource_get_resource_id + +AUTOZ_IRESOURCE +AUTOZ_IS_IRESOURCE +AUTOZ_TYPE_IRESOURCE +autoz_iresource_get_type +AUTOZ_IRESOURCE_GET_IFACE +
+
role AutozRole @@ -14,20 +28,6 @@ AUTOZ_IS_ROLE_CLASS AUTOZ_ROLE_GET_CLASS
-
-resource_interface -AutozIResource -AutozIResource -AutozIResourceIface -autoz_iresource_get_resource_id - -AUTOZ_IRESOURCE -AUTOZ_IS_IRESOURCE -AUTOZ_TYPE_IRESOURCE -autoz_iresource_get_type -AUTOZ_IRESOURCE_GET_IFACE -
-
role_interface AutozIRole diff --git a/docs/reference/autoz-decl.txt b/docs/reference/autoz-decl.txt index c3ece02..31bb465 100644 --- a/docs/reference/autoz-decl.txt +++ b/docs/reference/autoz-decl.txt @@ -143,6 +143,47 @@ Autoz *autoz, GdaConnection *gdacon, const gchar *table_prefix, gboolean replace Autoz *autoz, GdaConnection *gdacon, const gchar *table_prefix, gboolean replace +AUTOZ_TYPE_IRESOURCE +#define AUTOZ_TYPE_IRESOURCE (autoz_iresource_get_type ()) + + +AUTOZ_IRESOURCE +#define AUTOZ_IRESOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AUTOZ_TYPE_IRESOURCE, AutozIResource)) + + +AUTOZ_IS_IRESOURCE +#define AUTOZ_IS_IRESOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AUTOZ_TYPE_IRESOURCE)) + + +AUTOZ_IRESOURCE_GET_IFACE +#define AUTOZ_IRESOURCE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), AUTOZ_TYPE_IRESOURCE, AutozIResourceIface)) + + +AutozIResource + + +AutozIResourceIface + + +AutozIResourceIface +struct _AutozIResourceIface + { + GTypeInterface g_iface; + + const gchar *(*get_resource_id) (AutozIResource *iresource); + }; + + +autoz_iresource_get_type +GType +void + + +autoz_iresource_get_resource_id +const gchar * +AutozIResource *iresource + + AUTOZ_TYPE_ROLE #define AUTOZ_TYPE_ROLE (autoz_role_get_type ()) @@ -197,47 +238,6 @@ void const gchar *role_id -AUTOZ_TYPE_IRESOURCE -#define AUTOZ_TYPE_IRESOURCE (autoz_iresource_get_type ()) - - -AUTOZ_IRESOURCE -#define AUTOZ_IRESOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AUTOZ_TYPE_IRESOURCE, AutozIResource)) - - -AUTOZ_IS_IRESOURCE -#define AUTOZ_IS_IRESOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AUTOZ_TYPE_IRESOURCE)) - - -AUTOZ_IRESOURCE_GET_IFACE -#define AUTOZ_IRESOURCE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), AUTOZ_TYPE_IRESOURCE, AutozIResourceIface)) - - -AutozIResource - - -AutozIResourceIface - - -AutozIResourceIface -struct _AutozIResourceIface - { - GTypeInterface g_iface; - - const gchar *(*get_resource_id) (AutozIResource *iresource); - }; - - -autoz_iresource_get_type -GType -void - - -autoz_iresource_get_resource_id -const gchar * -AutozIResource *iresource - - AUTOZ_TYPE_IROLE #define AUTOZ_TYPE_IROLE (autoz_irole_get_type ()) diff --git a/docs/schema.sql b/docs/schema.sql index a5af5bd..adbabdb 100644 --- a/docs/schema.sql +++ b/docs/schema.sql @@ -1,5 +1,38 @@ -CREATE TABLE resources (id INTEGER, resource_id VARCHAR (255)); -CREATE TABLE resources_parents (id_resources INTEGER, id_resources_parent INTEGER); -CREATE TABLE roles (id INTEGER, role_id VARCHAR (255)); -CREATE TABLE roles_parents (id_roles INTEGER, id_roles_parent INTEGER); -CREATE TABLE rules (id INTEGER, type INTEGER, id_roles INTEGER, id_resources INTEGER); +CREATE TABLE roles +( + id integer NOT NULL, + role_id character varying(255) DEFAULT ''::character varying, + CONSTRAINT roles_pkey PRIMARY KEY (id) +) + +CREATE TABLE roles_parents +( + id_roles integer NOT NULL, + id_roles_parent integer NOT NULL, + CONSTRAINT roles_parents_pkey PRIMARY KEY (id_roles, id_roles_parent) +) + +CREATE TABLE resources +( + id integer NOT NULL, + resource_id character varying(255) DEFAULT ''::character varying, + CONSTRAINT resources_pkey PRIMARY KEY (id) +) + +CREATE TABLE resources_parents +( + id_resources integer NOT NULL, + id_resources_parent integer NOT NULL, + CONSTRAINT resources_parents_pkey PRIMARY KEY (id_resources, id_resources_parent) +) + +CREATE TABLE rules +( + id integer NOT NULL, + "type" integer, + id_roles integer, + id_resources integer, + CONSTRAINT rules_pkey PRIMARY KEY (id) +) +COMMENT ON COLUMN rules."type" IS '1 - allow +2 - deny'; diff --git a/src/autoz.c b/src/autoz.c index fd9427e..dba3689 100644 --- a/src/autoz.c +++ b/src/autoz.c @@ -1627,7 +1627,9 @@ autoz_load_from_db (Autoz *autoz, GdaConnection *gdacon, const gchar *table_pref guint rule_type; AutozIRole *irole; + AutozIRole *irole_parent; AutozIResource *iresource; + AutozIResource *iresource_parent; Rule *rule; guint row; @@ -1680,6 +1682,35 @@ autoz_load_from_db (Autoz *autoz, GdaConnection *gdacon, const gchar *table_pref error->message != NULL ? error->message : "no details"); } + /* roles parents */ + error = NULL; + table_name = g_strdup_printf ("%sroles_parents", prefix); + sql = g_strdup_printf ("SELECT r1.role_id, r2.role_id" + " FROM %s AS rp" + " INNER JOIN %sroles AS r1 ON rp.id_roles = r1.id" + " INNER JOIN %sroles AS r2 ON rp.id_roles_parent = r2.id" + " ORDER BY rp.id_roles, rp.id_roles_parent", + table_name, + prefix, + prefix); + dm = gda_execute_select_command (gdacon, sql, &error); + if (dm != NULL) + { + rows = gda_data_model_get_n_rows (dm); + for (row = 0; row < rows; row++) + { + error = NULL; + irole = AUTOZ_IROLE (autoz_role_new (gda_value_stringify (gda_data_model_get_value_at (dm, 0, row, &error)))); + irole_parent = AUTOZ_IROLE (autoz_role_new (gda_value_stringify (gda_data_model_get_value_at (dm, 1, row, &error)))); + autoz_add_parent_to_role (autoz, irole, irole_parent); + } + } + else if (error != NULL) + { + g_warning ("Error on reading table «roles_parents»: %s", + error->message != NULL ? error->message : "no details"); + } + /* resources */ error = NULL; table_name = g_strdup_printf ("%sresources", prefix); @@ -1702,6 +1733,35 @@ autoz_load_from_db (Autoz *autoz, GdaConnection *gdacon, const gchar *table_pref error->message != NULL ? error->message : "no details"); } + /* resources parents */ + error = NULL; + table_name = g_strdup_printf ("%sresources_parents", prefix); + sql = g_strdup_printf ("SELECT r1.resource_id, r2.resource_id" + " FROM %s AS rp" + " INNER JOIN %sresources AS r1 ON rp.id_resources = r1.id" + " INNER JOIN %sresources AS r2 ON rp.id_resources_parent = r2.id" + " ORDER BY rp.id_resources, rp.id_resources_parent", + table_name, + prefix, + prefix); + dm = gda_execute_select_command (gdacon, sql, &error); + if (dm != NULL) + { + rows = gda_data_model_get_n_rows (dm); + for (row = 0; row < rows; row++) + { + error = NULL; + iresource = AUTOZ_IRESOURCE (autoz_resource_new (gda_value_stringify (gda_data_model_get_value_at (dm, 0, row, &error)))); + iresource_parent = AUTOZ_IRESOURCE (autoz_resource_new (gda_value_stringify (gda_data_model_get_value_at (dm, 1, row, &error)))); + autoz_add_parent_to_resource (autoz, iresource, iresource_parent); + } + } + else if (error != NULL) + { + g_warning ("Error on reading table «resources_parents»: %s", + error->message != NULL ? error->message : "no details"); + } + /* rules */ error = NULL; table_name = g_strdup_printf ("%srules", prefix); diff --git a/tests/test_to_db.db b/tests/test_to_db.db index adf46bd677b3325e26451bcfc020d7eaa5472e92..5f17445b7f62d05ecf2590cfd895987443e92011 100644 GIT binary patch delta 12 TcmZoLXfT){%_z4~=7~4}8Jq+2 delta 12 TcmZoLXfT){%_zH3=7~4}8J7d{ -- 2.49.0