Make it possible to suppress IDL fields
authorMike Rylander <mrylander@gmail.com>
Wed, 10 Oct 2012 21:36:52 +0000 (17:36 -0400)
committerBill Erickson <berick@esilibrary.com>
Thu, 8 Nov 2012 18:20:58 +0000 (13:20 -0500)
Some clients of external services, particularly pcrud and reporter-store,
need to be able to access tables that contain columns we'd rather restrict.
For instance, the passwd field on actor.usr.

To effect this feature we provide a blacklist attribute for fields, called
suppress_controller, which works in the same way as the class controller
attribute but names controllers not allowed to use the field.  When the field
is explicitly named in a query (fieldmapper select block or json_query) an
error is thrown, and suppressed fields are ingored in general fieldmapper
search/retreive requests.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/examples/fm_IDL.xsd
Open-ILS/src/c-apps/oils_idl-core.c
Open-ILS/src/c-apps/oils_sql.c
Open-ILS/web/reports/xul/source-browse.js
Open-ILS/web/reports/xul/source-setup.js

index 5b9725a..a7a765d 100644 (file)
@@ -2805,7 +2805,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Is Group Lead Account" name="master_account" reporter:datatype="bool"/>
                        <field reporter:label="Internet Access Level" name="net_access_level" reporter:datatype="link"/>
                        <field reporter:label="Other Phone" name="other_phone"  reporter:datatype="text"/>
-                       <field reporter:label="Password" name="passwd"  reporter:datatype="text"/>
+                       <field reporter:label="Password" name="passwd" suppress_controller="open-ils.pcrud open-ils.reporter-store" reporter:datatype="text"/>
                        <field reporter:label="Photo URL" name="photo_url"  reporter:datatype="text"/>
                        <field reporter:label="Prefix/Title" name="prefix"  reporter:datatype="text"/>
                        <field reporter:label="Main (Profile) Permission Group" name="profile" reporter:datatype="link"/>
index b2720a1..7ebbd51 100644 (file)
@@ -51,6 +51,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
    <xs:element ref="idl:description" minOccurs="0" maxOccurs="1"/>
   </xs:sequence>
   <xs:attribute name="name"/>
+  <xs:attribute name="suppress_controller"/>
   <xs:attribute ref="oils_obj:array_position"/>
   <xs:attribute ref="oils_obj:required"/>
   <xs:attribute ref="oils_obj:validate"/>
index 471435c..5d432ab 100644 (file)
@@ -156,6 +156,13 @@ osrfHash* oilsIDLInit( const char* idl_filename ) {
                                                snprintf( array_pos_buf, sizeof( array_pos_buf ), "%u", array_pos++ );
                                                osrfHashSet( field_def_hash, strdup( array_pos_buf ), "array_position" );
 
+                                               // Tokenize suppress_controller attribute into an osrfStringArray
+                                               if( (prop_str = (char*)xmlGetProp(_f, BAD_CAST "suppress_controller")) ) {
+                                                       osrfLogDebug(OSRF_LOG_MARK, "Controller suppression list is %s", prop_str );
+                                                       osrfStringArray* controller = osrfStringArrayTokenize( prop_str, ' ' );
+                                                       osrfHashSet( field_def_hash, controller, "suppress_controller");
+                                               }
+
                                                if( (prop_str = (char*)xmlGetNsProp(_f, BAD_CAST "i18n", BAD_CAST PERSIST_NS)) ) {
                                                        osrfHashSet(
                                                                field_def_hash,
index b262a70..a0ba678 100644 (file)
@@ -4203,7 +4203,16 @@ char* SELECT (
 
                                        // Look up the field in the IDL
                                        const char* col_name = jsonObjectGetString( selfield );
-                                       osrfHash* field_def = osrfHashGet( class_field_set, col_name );
+                                       osrfHash* field_def;
+
+                                       if (!osrfStringArrayContains(
+                                                       osrfHashGet(
+                                                               osrfHashGet( class_field_set, col_name ),
+                                                               "suppress_controller"),
+                                                       modulename
+                                       ))
+                                               field_def = osrfHashGet( class_field_set, col_name );
+
                                        if( !field_def ) {
                                                // No such field in current class
                                                osrfLogError(
@@ -4282,7 +4291,16 @@ char* SELECT (
                                                        jsonObjectGetKeyConst( selfield, "column" ) );
 
                                        // Get the field definition from the IDL
-                                       osrfHash* field_def = osrfHashGet( class_field_set, col_name );
+                                       osrfHash* field_def;
+                                       if (!osrfStringArrayContains(
+                                                       osrfHashGet(
+                                                               osrfHashGet( class_field_set, col_name ),
+                                                               "suppress_controller"),
+                                                       modulename
+                                       ))
+                                               field_def = osrfHashGet( class_field_set, col_name );
+
+
                                        if( !field_def ) {
                                                // No such field in current class
                                                osrfLogError(
@@ -5202,6 +5220,9 @@ static char* buildSELECT ( const jsonObject* search_hash, jsonObject* rest_of_qu
                        if( !field )
                                continue;
 
+                       if (osrfStringArrayContains( osrfHashGet(field, "suppress_controller"), modulename ))
+                               continue;
+
                        if( first ) {
                                first = 0;
                        } else {
@@ -6056,6 +6077,10 @@ int doUpdate( osrfMethodContext* ctx ) {
                if( str_is_true( osrfHashGet( field_def, "virtual") ) )
                        continue;
 
+               if (osrfStringArrayContains( osrfHashGet(field_def, "suppress_controller"), modulename ))
+                       continue;
+
+
                const char* field_name = osrfHashIteratorKey( field_itr );
                if( ! strcmp( field_name, pkey ) )
                        continue;
index 4075dd1..0442e3a 100644 (file)
@@ -36,6 +36,9 @@ function sourceTreeHandler (ev, dbl) {
                                var name = field.getAttributeNS(rptNS,'label');
                                if (!name) name = field.getAttribute('name');
 
+                               var suppress = field.getAttribute('suppress_controller');
+                               if (suppress && suppress.indexOf('open-ils.reporter-store') > -1) continue;
+
                                var idlclass = link_fields[i].getAttribute('class');
                                var map = link_fields[i].getAttribute('map');
                                var link = link_fields[i].getAttribute('field');
index d3b919c..1e0d456 100644 (file)
@@ -312,6 +312,9 @@ function populateDetailTree (tcNode, c, item) {
                var type = fields[i].getAttributeNS(rptNS, 'datatype');
                //if (!type) type = 'text';
 
+               var suppress = fields[i].getAttribute('suppress_controller');
+               if (suppress && suppress.indexOf('open-ils.reporter-store') > -1) continue;
+
                var label = fields[i].getAttributeNS(rptNS, 'label');
                var name = fields[i].getAttribute('name');
                if (!label) label = name;