Bugzilla – Attachment 163491 Details for
Bug 36351
CSRF Adjustments for Cataloguing editor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36351: Adjust saveRecord and _fromXMLStruct
Bug-36351-Adjust-saveRecord-and-fromXMLStruct.patch (text/plain), 6.27 KB, created by
Jonathan Druart
on 2024-03-20 05:10:09 UTC
(
hide
)
Description:
Bug 36351: Adjust saveRecord and _fromXMLStruct
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2024-03-20 05:10:09 UTC
Size:
6.27 KB
patch
obsolete
>From 79ef9ebfcdd2ae81281d6094be6b5ae5e4e65b96 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 19 Mar 2024 15:33:28 +0000 >Subject: [PATCH] Bug 36351: Adjust saveRecord and _fromXMLStruct > >Using the new API Client means we need to handle some calls differently. >the http-client is returning only the response, not the text, so we need to handle getting this out >with a new async function (or promises, but this works) > >We also need to adjust _fromXMLStruct as we have reduced the levels in the response by the time it is called > >This now adds a new 'update' function to the cataloguing client as well. > >Eventually, this should all be using the REST API, but I think for now handling the non-standard responses gets it >working again > >To test: >To test: >1 - Browse to Cataloguing->Advanced editor >2 - New Record >3 - Enter values and save - confirm it works >4 - Confirm url now ends in : editor.pl#catalog/{biblionumber} and not editor.pl#new >5 - Save the record again, confirm biblio is updated and not saved as new > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > .../lib/koha/cateditor/koha-backend.js | 59 ++++++++++++------- > .../prog/js/fetch/cataloguing-api-client.js | 9 +++ > 2 files changed, 48 insertions(+), 20 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js >index 8586206ade0..0ac49808726 100644 >--- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js >+++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/koha-backend.js >@@ -23,10 +23,16 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin > var _framework_mappings = {}; > var _framework_kohafields = {}; > >+ async function _readStream(stream){ >+ let xml_response = new Response(stream); >+ let the_xml = await xml_response.text(); >+ return the_xml; >+ } >+ > function _fromXMLStruct( data ) { > result = {}; > >- $(data).children().eq(0).children().each( function() { >+ $(data).children().each( function() { > var $contents = $(this).contents(); > if ( $contents.length == 1 && $contents[0].nodeType == Node.TEXT_NODE ) { > result[ this.localName ] = $contents[0].data; >@@ -137,14 +143,21 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin > _removeBiblionumberFields( record ); > > const client = APIClient.cataloguing; >- client.catalog_bib.create({ frameworkcode, record }).then( >+ client.catalog_bib.create({ frameworkcode: frameworkcode, record: record }).then( > success => { >- var record = _fromXMLStruct( success ); >- if ( record.marcxml ) { >- record.marcxml[0].frameworkcode = frameworkcode; >+ _readStream( success.body ).then( >+ success=> { >+ var xml_response = success; >+ var record =_fromXMLStruct( xml_response ); >+ if ( record.marcxml ) { >+ record.marcxml[0].frameworkcode = frameworkcode; >+ } >+ callback( record ); >+ }, >+ error => { >+ callback( { error: _('Could not parse response') } ); > } >- callback( record ); >- }, >+ );}, > error => { > callback( { error: _('Could not save record') } ); > } >@@ -156,20 +169,26 @@ define( [ '/cgi-bin/koha/svc/cataloguing/framework?frameworkcode=&callback=defin > record = record.clone(); > _removeBiblionumberFields( record ); > >- $.ajax( { >- type: 'POST', >- url: '/cgi-bin/koha/svc/bib/' + id + '?frameworkcode=' + encodeURIComponent(frameworkcode), >- data: record.toXML(), >- contentType: 'text/xml' >- } ).done( function( data ) { >- var record = _fromXMLStruct( data ); >- if ( record.marcxml ) { >- record.marcxml[0].frameworkcode = frameworkcode; >+ const client = APIClient.cataloguing; >+ client.catalog_bib.update({ frameworkcode: frameworkcode, record: record, id: id }).then( >+ success => { >+ _readStream( success.body ).then( >+ success=> { >+ var xml_response = success; >+ var record =_fromXMLStruct( xml_response ); >+ if ( record.marcxml ) { >+ record.marcxml[0].frameworkcode = frameworkcode; >+ } >+ callback( record ); >+ }, >+ error => { >+ callback( { error: _('Could not parse response') } ); >+ } >+ );}, >+ error => { >+ callback( { error: _('Could not save record') } ); > } >- callback( record ); >- } ).fail( function( data ) { >- callback( { error: _('Could not save record') } ); >- } ); >+ ); > }, > > GetTagsBy: function( frameworkcode, field, value ) { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/fetch/cataloguing-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/fetch/cataloguing-api-client.js >index 435be5b834d..d6d1d1b45df 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/fetch/cataloguing-api-client.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/fetch/cataloguing-api-client.js >@@ -18,6 +18,15 @@ export class CataloguingAPIClient extends HttpClient { > "text/xml", > }, > }), >+ update: bib_info => >+ this.post({ >+ endpoint: "bib/%s?frameworkcode=%s".format( bib_info.id, bib_info.frameworkcode ), >+ body: bib_info.record.toXML(), >+ headers: { >+ "Content-Type": >+ "text/xml", >+ }, >+ }), > }; > } > >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36351
:
163362
|
163364
|
163387
|
163388
|
163457
|
163458
|
163459
|
163489
|
163490
| 163491 |
163492