LPXXX Open Non-Cataloged Circs View user/berick/lpxxx-non-cat-view
authorBill Erickson <berickxx@gmail.com>
Tue, 16 May 2023 21:56:36 +0000 (17:56 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 17 May 2023 14:30:21 +0000 (10:30 -0400)
* Make open non-cataloged circs available as a cstore/pcrud-accessible
  DB view.
* Migrate the public API to cstore retrieval
* Migrate one of the browser client calls to pcrud
* Minor code tidying

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/eg2/src/app/staff/share/patron/patron.service.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/NonCat.pm
Open-ILS/src/sql/Pg/090.schema.action.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.non-cat-view.sql [new file with mode: 0644]

index 949ed2b..174d95e 100644 (file)
@@ -8515,6 +8515,32 @@ SELECT  usr,
                        </actions>
                </permacrud>
        </class>
+       <class id="aoncc" controller="open-ils.cstore open-ils.pcrud" 
+               oils_obj:fieldmapper="action::open_non_cataloged_circulation" 
+               oils_persist:tablename="action.open_non_cataloged_circulation" 
+               oils_persist:readonly="true" reporter:core="true" 
+               reporter:label="Open Non-cataloged Circulation">
+               <fields oils_persist:primary="id" oils_persist:sequence="action.non_cataloged_circulation_id_seq">
+                       <field reporter:label="Circulating Library" name="circ_lib"  reporter:datatype="org_unit"/>
+                       <field reporter:label="Circulation Date/Time" name="circ_time" reporter:datatype="timestamp"/>
+                       <field reporter:label="Non-cat Circulation ID" name="id" reporter:datatype="id" />
+                       <field reporter:label="Non-cat Item Type" name="item_type" reporter:datatype="link"/>
+                       <field reporter:label="Patron" name="patron" reporter:datatype="link"/>
+                       <field reporter:label="Circulating Staff" name="staff" reporter:datatype="link"/>
+                       <field reporter:label="Virtual Due Date/Time" name="duedate" reporter:datatype="timestamp" oils_persist:virtual="true"/>
+               </fields>
+               <links>
+                       <link field="item_type" reltype="has_a" key="id" map="" class="cnct"/>
+                       <link field="staff" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="patron" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="circ_lib" reltype="has_a" key="id" map="" class="aou"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions>
+                               <retrieve permission="VIEW_CIRCULATIONS" context_field="circ_lib" />
+                       </actions>
+               </permacrud>
+       </class>
        <class id="moucs" controller="open-ils.cstore" oils_obj:fieldmapper="money::open_user_circulation_summary" oils_persist:tablename="money.open_usr_circulation_summary" reporter:label="Open User Circulation Summary">
                <fields oils_persist:primary="usr" oils_persist:sequence="">
                        <field name="balance_owed" reporter:datatype="money" />
index fbf075a..bce516f 100644 (file)
@@ -296,14 +296,10 @@ export class PatronService {
             }
 
             return patronStats = stats;
-        })
 
-        .then(_ => {
-            return this.net.request(
-                'open-ils.circ',
-                'open-ils.circ.open_non_cataloged_circulation.user.authoritative',
-                this.auth.token(), patron.id()
-            ).toPromise();
+        }).then(_ => {
+            return this.pcrud.search('aoncc',
+                {patron: patron.id()}, {}, {idlist: true, atomic: true}).toPromise();
 
         }).then(noncats => {
             if (noncats && patronStats) {
index 3105ddf..fde9b50 100644 (file)
@@ -233,18 +233,20 @@ __PACKAGE__->register_method(
 );
 
 sub fetch_open_noncats {
-    my( $self, $conn, $auth, $userid ) = @_;
-    my $e = new_editor( authtoken => $auth );
+    my ($self, $conn, $auth, $user_id) = @_;
+
+    my $e = new_editor(authtoken => $auth);
     return $e->event unless $e->checkauth;
-    $userid ||= $e->requestor->id;
-    if( $e->requestor->id ne $userid ) {
-        return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); # XXX rely on editor perm
+
+    $user_id ||= $e->requestor->id;
+
+    if ($e->requestor->id ne $user_id) {
+        return $e->event unless $e->allowed('VIEW_CIRCULATIONS');
     }
 
-    return $U->simplereq(
-        'open-ils.storage',
-        'open-ils.storage.action.open_non_cataloged_circulation.user',
-        $userid
+    return $e->search_action_open_non_cataloged_circulation(
+        {patron => $user_id},
+        {idlist => 1}
     );
 }
 
@@ -271,14 +273,14 @@ sub fetch_open_noncats_batch {
     my $e = new_editor(authtoken => $auth);
     return $e->event unless $e->checkauth;
 
+    $user_id ||= $e->requestor->id;
     if ($e->requestor->id ne $user_id) {
         return $e->event unless $e->allowed('VIEW_CIRCULATIONS');
     }
 
-    my $ids = $U->simplereq(
-        'open-ils.storage',
-        'open-ils.storage.action.open_non_cataloged_circulation.user',
-        $user_id
+    my $ids = $e->search_action_open_non_cataloged_circulation(
+        {patron => $user_id},
+        {idlist => 1}
     );
 
     for my $id (@$ids) {
index 7ce47d3..159c9c4 100644 (file)
@@ -54,6 +54,13 @@ CREATE TABLE action.non_cat_in_house_use (
 CREATE INDEX non_cat_in_house_use_staff_idx ON action.non_cat_in_house_use ( staff );
 CREATE INDEX non_cat_in_house_use_ws_idx ON action.non_cat_in_house_use ( workstation );
 
+CREATE OR REPLACE VIEW action.open_non_cataloged_circulation AS
+    SELECT ncc.* 
+    FROM action.non_cataloged_circulation ncc
+    JOIN config.non_cataloged_type nct ON nct.id = ncc.item_type
+    WHERE ncc.circ_time + nct.circ_duration > CURRENT_TIMESTAMP
+;
+
 CREATE TABLE action.survey (
        id              SERIAL                          PRIMARY KEY,
        owner           INT                             NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.non-cat-view.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.non-cat-view.sql
new file mode 100644 (file)
index 0000000..8915927
--- /dev/null
@@ -0,0 +1,14 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version);
+
+CREATE OR REPLACE VIEW action.open_non_cataloged_circulation AS
+    SELECT ncc.* 
+    FROM action.non_cataloged_circulation ncc
+    JOIN config.non_cataloged_type nct ON nct.id = ncc.item_type
+    WHERE ncc.circ_time + nct.circ_duration > CURRENT_TIMESTAMP
+;
+
+COMMIT;
+
+