Avoid too-strict controller checks when fleshing for cstore, reporter-store
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 9 Apr 2012 15:27:53 +0000 (11:27 -0400)
committerThomas Berezansky <tsbere@mvlc.org>
Mon, 9 Apr 2012 17:39:19 +0000 (13:39 -0400)
Move controller-verificiation from the beginning of recursive
doFieldmapperSearch() to nearer the end, right before we recurse, so we
only check the child class's controller if we're pcrud.  If we're not
pcrud, code that calls doFieldmapperSearch() from the outside will have
already done appropriate testing of the controller.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>

Open-ILS/src/c-apps/oils_sql.c

index 24795b0..902a4e0 100644 (file)
@@ -5585,27 +5585,10 @@ static jsonObject* doFieldmapperSearch( osrfMethodContext* ctx, osrfHash* class_
        char *methodtype = osrfHashGet( (osrfHash *) ctx->method->userData, "methodtype" );
        char *inside_verify = osrfHashGet( (osrfHash*) ctx->session->userData, "inside_verify" );
        int need_to_verify = (inside_verify ? !atoi(inside_verify) : 1);
-       int has_controller = osrfStringArrayContains(osrfHashGet(class_meta, "controller"), modulename);
 
        int i_respond_directly = 0;
        int flesh_depth = 0;
 
-       // XXX This can be redundant with another instance of the same test that happens
-       // within the functions that call doFieldmapperSearch(), but we have it here to
-       // prevent any non-pcrud-controlled classes from being fleshed on.
-       //
-       // TODO To avoid redundancy, move this block to right before we recurse,
-       // and change the class we're checking to the one we're /about/ to search for,
-       // not the one we're currently searching for.
-       if (
-               (!has_controller && !enforce_pcrud) // cstore client-level case: we require the controller, period
-               || (!has_controller && enforce_pcrud && need_to_verify) // pcrud case: we require the controller in need_to_verify mode
-       ) {
-               osrfLogInfo(OSRF_LOG_MARK, "%s is not listed as a controller for %s, moving on",
-                       modulename, core_class);
-               return jsonNewObjectType( JSON_ARRAY ); /* empty */
-       }
-
        char* sql = buildSELECT( where_hash, query_hash, class_meta, ctx );
        if( !sql ) {
                osrfLogDebug( OSRF_LOG_MARK, "Problem building query, returning NULL" );
@@ -5782,6 +5765,21 @@ static jsonObject* doFieldmapperSearch( osrfMethodContext* ctx, osrfHash* class_
                                                        fields, osrfHashGet( class_meta, "primarykey" ) );
                                        }
 
+                                       int kid_has_controller = osrfStringArrayContains( osrfHashGet(kid_idl, "controller"), modulename );
+                                       // fleshing pcrud case: we require the controller in need_to_verify mode
+                                       if ( !kid_has_controller && enforce_pcrud && need_to_verify ) {
+                                               osrfLogInfo( OSRF_LOG_MARK, "%s is not listed as a controller for %s; moving on", modulename, core_class );
+
+                                               jsonObjectSetIndex(
+                                                       cur,
+                                                       (unsigned long) atoi( osrfHashGet(field, "array_position") ),
+                                                       jsonNewObjectType(
+                                                               !strcmp( reltype, "has_many" ) ? JSON_ARRAY : JSON_NULL
+                                                       )
+                                               );
+                                               continue;
+                                       }
+
                                        osrfStringArray* link_map = osrfHashGet( kid_link, "map" );
 
                                        if( link_map->size > 0 ) {