]> saetta.ns0.it Git - zakautho/libzakautho/commitdiff
Missing parents loading on load from db.
authorAndrea Zagli <azagli@libero.it>
Tue, 27 Jul 2010 07:57:37 +0000 (09:57 +0200)
committerAndrea Zagli <azagli@libero.it>
Tue, 27 Jul 2010 07:57:37 +0000 (09:57 +0200)
.gitignore
docs/reference/autoz-decl-list.txt
docs/reference/autoz-decl.txt
docs/schema.sql
src/autoz.c
tests/test_to_db.db

index d08e9f991d884165cc654c507d0789131b1e59ad..9d8b86744ac39f66c4691854ea4649e8b4c3bacf 100644 (file)
@@ -42,6 +42,7 @@ libtool
 stamp-h1
 tests/test
 tests/test_from_xml
+tests/test_from_xml_to_db
 POTFILES
 mkinstalldirs
 stamp-it
index 4be7fa0b6dcee2bd628c8478abc0b6ddd836aff1..0cbb355917ef83597b64ac5eb41c42f33229c0a6 100644 (file)
@@ -1,3 +1,17 @@
+<SECTION>
+<FILE>resource_interface</FILE>
+<TITLE>AutozIResource</TITLE>
+AutozIResource
+AutozIResourceIface
+autoz_iresource_get_resource_id
+<SUBSECTION Standard>
+AUTOZ_IRESOURCE
+AUTOZ_IS_IRESOURCE
+AUTOZ_TYPE_IRESOURCE
+autoz_iresource_get_type
+AUTOZ_IRESOURCE_GET_IFACE
+</SECTION>
+
 <SECTION>
 <FILE>role</FILE>
 <TITLE>AutozRole</TITLE>
@@ -14,20 +28,6 @@ AUTOZ_IS_ROLE_CLASS
 AUTOZ_ROLE_GET_CLASS
 </SECTION>
 
-<SECTION>
-<FILE>resource_interface</FILE>
-<TITLE>AutozIResource</TITLE>
-AutozIResource
-AutozIResourceIface
-autoz_iresource_get_resource_id
-<SUBSECTION Standard>
-AUTOZ_IRESOURCE
-AUTOZ_IS_IRESOURCE
-AUTOZ_TYPE_IRESOURCE
-autoz_iresource_get_type
-AUTOZ_IRESOURCE_GET_IFACE
-</SECTION>
-
 <SECTION>
 <FILE>role_interface</FILE>
 <TITLE>AutozIRole</TITLE>
index c3ece028360a493bad6e723f48ddc10191aec4f8..31bb465e1c84c4171ce963a37071a20d1b5b2bdc 100644 (file)
@@ -143,6 +143,47 @@ Autoz *autoz, GdaConnection *gdacon, const gchar *table_prefix, gboolean replace
 Autoz *autoz, GdaConnection *gdacon, const gchar *table_prefix, gboolean replace 
 </FUNCTION>
 <MACRO>
+<NAME>AUTOZ_TYPE_IRESOURCE</NAME>
+#define AUTOZ_TYPE_IRESOURCE             (autoz_iresource_get_type ())
+</MACRO>
+<MACRO>
+<NAME>AUTOZ_IRESOURCE</NAME>
+#define AUTOZ_IRESOURCE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), AUTOZ_TYPE_IRESOURCE, AutozIResource))
+</MACRO>
+<MACRO>
+<NAME>AUTOZ_IS_IRESOURCE</NAME>
+#define AUTOZ_IS_IRESOURCE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AUTOZ_TYPE_IRESOURCE))
+</MACRO>
+<MACRO>
+<NAME>AUTOZ_IRESOURCE_GET_IFACE</NAME>
+#define AUTOZ_IRESOURCE_GET_IFACE(obj)   (G_TYPE_INSTANCE_GET_INTERFACE ((obj), AUTOZ_TYPE_IRESOURCE, AutozIResourceIface))
+</MACRO>
+<STRUCT>
+<NAME>AutozIResource</NAME>
+</STRUCT>
+<STRUCT>
+<NAME>AutozIResourceIface</NAME>
+</STRUCT>
+<STRUCT>
+<NAME>AutozIResourceIface</NAME>
+struct _AutozIResourceIface
+       {
+               GTypeInterface g_iface;
+
+               const gchar *(*get_resource_id) (AutozIResource *iresource);
+       };
+</STRUCT>
+<FUNCTION>
+<NAME>autoz_iresource_get_type</NAME>
+<RETURNS>GType </RETURNS>
+void 
+</FUNCTION>
+<FUNCTION>
+<NAME>autoz_iresource_get_resource_id</NAME>
+<RETURNS>const gchar *</RETURNS>
+AutozIResource *iresource 
+</FUNCTION>
+<MACRO>
 <NAME>AUTOZ_TYPE_ROLE</NAME>
 #define AUTOZ_TYPE_ROLE                 (autoz_role_get_type ())
 </MACRO>
@@ -197,47 +238,6 @@ void
 const gchar *role_id 
 </FUNCTION>
 <MACRO>
-<NAME>AUTOZ_TYPE_IRESOURCE</NAME>
-#define AUTOZ_TYPE_IRESOURCE             (autoz_iresource_get_type ())
-</MACRO>
-<MACRO>
-<NAME>AUTOZ_IRESOURCE</NAME>
-#define AUTOZ_IRESOURCE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), AUTOZ_TYPE_IRESOURCE, AutozIResource))
-</MACRO>
-<MACRO>
-<NAME>AUTOZ_IS_IRESOURCE</NAME>
-#define AUTOZ_IS_IRESOURCE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AUTOZ_TYPE_IRESOURCE))
-</MACRO>
-<MACRO>
-<NAME>AUTOZ_IRESOURCE_GET_IFACE</NAME>
-#define AUTOZ_IRESOURCE_GET_IFACE(obj)   (G_TYPE_INSTANCE_GET_INTERFACE ((obj), AUTOZ_TYPE_IRESOURCE, AutozIResourceIface))
-</MACRO>
-<STRUCT>
-<NAME>AutozIResource</NAME>
-</STRUCT>
-<STRUCT>
-<NAME>AutozIResourceIface</NAME>
-</STRUCT>
-<STRUCT>
-<NAME>AutozIResourceIface</NAME>
-struct _AutozIResourceIface
-       {
-               GTypeInterface g_iface;
-
-               const gchar *(*get_resource_id) (AutozIResource *iresource);
-       };
-</STRUCT>
-<FUNCTION>
-<NAME>autoz_iresource_get_type</NAME>
-<RETURNS>GType </RETURNS>
-void 
-</FUNCTION>
-<FUNCTION>
-<NAME>autoz_iresource_get_resource_id</NAME>
-<RETURNS>const gchar *</RETURNS>
-AutozIResource *iresource 
-</FUNCTION>
-<MACRO>
 <NAME>AUTOZ_TYPE_IROLE</NAME>
 #define AUTOZ_TYPE_IROLE             (autoz_irole_get_type ())
 </MACRO>
index a5af5bdd4be75bb84c286e94aeb3bb80a44932a9..adbabdb72d0a33c371ce908da0d5bdf9db6c9043 100644 (file)
@@ -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';
index fd9427e8102c1feae0c67b9437fce7f82354333d..dba36890cf89daef8ee52db18cfe38be07e65cfd 100644 (file)
@@ -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);
index adf46bd677b3325e26451bcfc020d7eaa5472e92..5f17445b7f62d05ecf2590cfd895987443e92011 100644 (file)
Binary files a/tests/test_to_db.db and b/tests/test_to_db.db differ