LP#1750894 setting api returns object
authorBill Erickson <berickxx@gmail.com>
Tue, 29 May 2018 15:07:51 +0000 (11:07 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 29 May 2018 15:47:35 +0000 (11:47 -0400)
... since some settings calls happen before the browser has parsed the
IDL, have the API return an generic object instead of an IDL object.

And better handle org-only settings.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Settings.pm
Open-ILS/web/js/ui/default/staff/services/hatch.js

index 2848be8..bb9f9c0 100644 (file)
@@ -12403,20 +12403,6 @@ SELECT  usr,
                </links>
        </class>
 
-       <class id="acss" 
-               controller="open-ils.cstore" 
-               oils_obj:fieldmapper="actor::cascade_setting_summary"
-               oils_persist:virtual="true" 
-               reporter:label="Cascade Setting Summary">
-       <fields>
-               <field reporter:label="Setting Name" name="name" reporter:datatype="text"/>
-               <field reporter:label="Value" name="value" reporter:datatype="text"/>
-               <field reporter:label="Has Org Setting" name="has_org_setting" reporter:datatype="bool"/>
-               <field reporter:label="Has User Setting" name="has_user_setting" reporter:datatype="bool"/>
-               <field reporter:label="Has Workstation Setting" name="has_workstation_setting" reporter:datatype="bool"/>
-       </fields>
-       </class>
-
        <!-- ********************************************************************************************************************* -->
 </IDL>
 
index d76aedb..6ab6818 100644 (file)
@@ -77,12 +77,9 @@ sub retrieve_settings {
         ]
     });
 
-    # The DB responds in setting-name order.
     while (my $resp = $req->recv) {
-        my $sumhash = $resp->content;
-        my $summary = Fieldmapper::actor::cascade_setting_summary->new;
-        $summary->$_($sumhash->{$_}) for keys %$sumhash;
-        $summary->value(OpenSRF::Utils::JSON->JSON2perl($summary->value));
+        my $summary = $resp->content;
+        $summary->{value} = OpenSRF::Utils::JSON->JSON2perl($summary->{value});
         $client->respond($summary);
     }
 
index 12a25f7..4936cab 100644 (file)
@@ -366,14 +366,18 @@ angular.module('egCoreMod')
         // If we have already attempted to retrieve a value for this
         // setting, then we can tell up front whether applying a value
         // at the server will be an option.  If not, store locally.
-        // Note that the existence of an org unit setting type and no
-        // user/ws setting type means applying a value locally is
-        // not allowed.
         var summary = service.serverSettingSummaries[key];
-        if (summary &&
-            summary.has_org_setting() === 'f' &&
-            summary.has_user_setting() === 'f' && 
-            summary.has_workstation_setting() === 'f') {
+        if (summary && !summary.has_staff_setting) {
+
+            if (summary.has_org_setting === 't') {
+                // When no user/ws setting types exist but an org unit
+                // setting type does, it means the value cannot be
+                // applied by an individual user.  Nothing left to do.
+                return $q.when();
+            }
+
+            // No setting types of any flavor exist.
+            // Fall back to local storage.
 
             if (value === null) {
                 // a null value means clear the server setting.
@@ -424,10 +428,17 @@ angular.module('egCoreMod')
     }
 
     service.handleServerItemResponse = function(summary) {
-        var key = summary.name();
-        var val = summary.value();
+        var key = summary.name;
+        var val = summary.value;
+
+        // For our purposes, we only care if a setting can be stored
+        // as an org setting or a user-or-workstation setting.
+        summary.has_staff_setting = (
+            summary.has_user_setting === 't' || 
+            summary.has_workstation_setting === 't'
+        );
 
-        summary.value(null); // avoid duplicate value caches
+        summary.value = null; // avoid duplicate value caches
         service.serverSettingSummaries[key] = summary;
 
         if (val !== null) {
@@ -435,12 +446,15 @@ angular.module('egCoreMod')
             return $q.when(service.keyCache[key] = val);
         }
 
-        // Note that the existence of an org unit setting type and no
-        // user/ws setting type means applying a value locally is
-        // not allowed.
-        if (summary.has_org_setting() === 'f' &&
-            summary.has_user_setting() === 'f' &&
-            summary.has_workstation_setting() === 'f') {
+        if (!summary.has_staff_setting) {
+
+            if (summary.has_org_setting === 't') {
+                // An org unit setting type exists but no value is applied
+                // that this workstation has access to.  The existence of 
+                // an org unit setting type and no user/ws setting type 
+                // means applying a value locally is not allowed.  
+                return $q.when(service.keyCache[key] = undefined);
+            }
 
             console.warn('No server setting type exists for ' 
                 + key + ', using local value.');
@@ -448,8 +462,8 @@ angular.module('egCoreMod')
             return service.getBrowserItem(key);
         }
 
-        // A server setting type exists, but no server value exists.
-        // See if we can migrate a local setting to the server.
+        // A user/ws setting type exists, but no server value exists.
+        // Migrate the local setting to the server.
 
         var deferred = $q.defer();
         service.getBrowserItem(key).then(function(browserVal) {