Bug 35287 - Add additional fields support to ERM Licenses
Summary: Add additional fields support to ERM Licenses
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: ERM (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Pedro Amorim
QA Contact:
URL:
Keywords:
Depends on: 30645 35044
Blocks: 32751 34324
  Show dependency treegraph
 
Reported: 2023-11-08 12:35 UTC by Pedro Amorim
Modified: 2024-02-13 09:47 UTC (History)
8 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 35287: Add cypress tests (955.08 KB, patch)
2023-11-09 14:41 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 35287: Add unit tests (4.25 KB, patch)
2023-11-09 14:41 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 35287: Preparation: Extend AdditionalFields Mixin (3.41 KB, patch)
2023-11-09 14:41 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 35287: Preparation: AdditionalFields License Mixin (1.38 KB, patch)
2023-11-09 14:41 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 35287: Admin (1.71 KB, patch)
2023-11-09 14:41 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 35287: REST API - Add additional fields support to ERM Licenses (6.45 KB, patch)
2023-11-09 14:41 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 35287: Vue preparation - AdditionalFields (15.85 KB, patch)
2023-11-09 14:42 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 35287: Vue preparation - Extend KohaTable to consider searchable additional fields (3.85 KB, patch)
2023-11-09 14:42 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 35287: Vue - Add additional fields support to ERM Licenses (10.50 KB, patch)
2023-11-09 14:42 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 35287: perltidy for green QA script (16.70 KB, patch)
2023-11-09 14:42 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 35287: Add cypress tests (955.14 KB, patch)
2023-12-07 12:28 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 35287: Add unit tests (4.31 KB, patch)
2023-12-07 12:28 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 35287: Preparation: Extend AdditionalFields Mixin (3.47 KB, patch)
2023-12-07 12:28 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 35287: Preparation: AdditionalFields License Mixin (1.44 KB, patch)
2023-12-07 12:28 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 35287: Admin (1.77 KB, patch)
2023-12-07 12:28 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 35287: REST API - Add additional fields support to ERM Licenses (6.51 KB, patch)
2023-12-07 12:29 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 35287: Vue preparation - AdditionalFields (15.91 KB, patch)
2023-12-07 12:29 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 35287: Vue preparation - Extend KohaTable to consider searchable additional fields (3.91 KB, patch)
2023-12-07 12:29 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 35287: Vue - Add additional fields support to ERM Licenses (10.56 KB, patch)
2023-12-07 12:29 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 35287: perltidy for green QA script (16.75 KB, patch)
2023-12-07 12:29 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Pedro Amorim 2023-11-08 12:35:26 UTC

    
Comment 1 Pedro Amorim 2023-11-09 14:41:45 UTC
Created attachment 158725 [details] [review]
Bug 35287: Add cypress tests

Test plan, k-t-d:
cd /kohadevbox/koha
cypress run --spec "t/cypress/integration/AdditionalFields_spec.ts"
Comment 2 Pedro Amorim 2023-11-09 14:41:48 UTC
Created attachment 158726 [details] [review]
Bug 35287: Add unit tests

Test plan, k-t-d:
prove t/db_dependent/Koha/Object/Mixin/AdditionalFields.t
Comment 3 Pedro Amorim 2023-11-09 14:41:51 UTC
Created attachment 158727 [details] [review]
Bug 35287: Preparation: Extend AdditionalFields Mixin

The mixin now implements the extended_attributes method to be utilized by any Koha class that implements the AdditionalFields Mixin and is exposed through the REST API
It also implements a strings_map to be utilized in the same fashion as described above. This is useful because additional fields may be an authorised value
Comment 4 Pedro Amorim 2023-11-09 14:41:53 UTC
Created attachment 158728 [details] [review]
Bug 35287: Preparation: AdditionalFields License Mixin

Koha::Object::Mixin::AdditionalFields needs to come before Koha::Object
in the inheritance so that the strings_map method that is called is
the one from Mixin and not from Koha::Object.
This is only required for Koha classes implementing the AdditionalFields Mixin and expose data through the REST API, because strings_map is implement in both the aforementioned classes
Comment 5 Pedro Amorim 2023-11-09 14:41:56 UTC
Created attachment 158729 [details] [review]
Bug 35287: Admin

ERM licenses is now a table option in the additional fields admin panel
ERM licenses allows for the 'searchable' option (as well as 'repeatable')
Comment 6 Pedro Amorim 2023-11-09 14:41:58 UTC
Created attachment 158730 [details] [review]
Bug 35287: REST API - Add additional fields support to ERM Licenses
Comment 7 Pedro Amorim 2023-11-09 14:42:01 UTC
Created attachment 158731 [details] [review]
Bug 35287: Vue preparation - AdditionalFields

New api client: additional-fields-api-client.js to interact with the REST endpoint introduced by bug 35197
2 new components:
- AdditionalFieldsEntry: Component used to extend the FormAdd component including the corresponding additional fields
- AdditionalFieldsDisplay: Component used to display the additional fields associated to a data record implementing it (makes use of strings_map)
Comment 8 Pedro Amorim 2023-11-09 14:42:03 UTC
Created attachment 158732 [details] [review]
Bug 35287: Vue preparation - Extend KohaTable to consider searchable additional fields

This follows the same pattern as in subscription serials searchable additional fields, i.e. if an additional field is searchable, it is added to the list table - with the corresponding search inputs and functionality
Comment 9 Pedro Amorim 2023-11-09 14:42:06 UTC
Created attachment 158733 [details] [review]
Bug 35287: Vue - Add additional fields support to ERM Licenses

Test plan, k-t-d:
1) Add a new additional field for the newly supported 'erm_licenses', visit:
/cgi-bin/koha/admin/additional-fields.pl?tablename=erm_licenses
2) Create 4 fields by clicking on '+ New field'
2.1) 'text non-repeatable'
2.2) 'text repeatable', check the 'repeatable' box
2.3) 'av non-repeatable', pick an authorised value category
2.4) 'av repeatable', pick an authorised value category and check the 'repeatable' box
3) Add a new ERM license, visit:
/cgi-bin/koha/erm/licenses/add
4) Notice there is now a 'Additional fields' section at the bottom listing the fields we created
5) Fill in the mandatory regular license fields and play around with the additional fields
5.1) Put in some text in the text fields, test out the 'clear' and '+new' buttons
5.2) Select some AV options from the AV fields, deselect them, notice the repeatable one allows for multiple selection, the non-repeatable one does not
6) Save the license. On the list table, click on the license name (to navigate to the show page), or if license id=1, visit:
/cgi-bin/koha/erm/licenses/1
7) Notice the additional fields are listed there, AV fields show their human readable description, not the AV code. Repeatable fields are shown comma separated
8) Edit the license, visit:
/cgi-bin/koha/erm/licenses/edit/1
9) Play around again, do some more inserting and deletion of additional fields. Save. Notice everything is as expected.

Searchable testing:
10) Go back to the additional fields admin panel, visit:
/cgi-bin/koha/admin/additional-fields.pl?tablename=erm_licenses
11) Edit one field (AV or not) that you have inserted some data in, in the previous steps, and tick the 'searchable' box
12) Go back to licenses, visit:
/cgi-bin/koha/erm/licenses
13) Notice the searchable additional field now has its own column in the licenses list table
14) If the searchable field is AV, it has a dropdown with the AV values of the same AV category
15) If the searchable field not AV, it has a text input that allows for normal text search
16) If the searchable field is repeatable and has multiple values, its displayed in comma separated
Comment 10 Pedro Amorim 2023-11-09 14:42:09 UTC
Created attachment 158734 [details] [review]
Bug 35287: perltidy for green QA script
Comment 11 PTFS Europe Sandboxes 2023-12-07 12:28:48 UTC
Created attachment 159634 [details] [review]
Bug 35287: Add cypress tests

Test plan, k-t-d:
cd /kohadevbox/koha
cypress run --spec "t/cypress/integration/AdditionalFields_spec.ts"

Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk>
Comment 12 PTFS Europe Sandboxes 2023-12-07 12:28:51 UTC
Created attachment 159635 [details] [review]
Bug 35287: Add unit tests

Test plan, k-t-d:
prove t/db_dependent/Koha/Object/Mixin/AdditionalFields.t

Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk>
Comment 13 PTFS Europe Sandboxes 2023-12-07 12:28:53 UTC
Created attachment 159636 [details] [review]
Bug 35287: Preparation: Extend AdditionalFields Mixin

The mixin now implements the extended_attributes method to be utilized by any Koha class that implements the AdditionalFields Mixin and is exposed through the REST API
It also implements a strings_map to be utilized in the same fashion as described above. This is useful because additional fields may be an authorised value

Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk>
Comment 14 PTFS Europe Sandboxes 2023-12-07 12:28:55 UTC
Created attachment 159637 [details] [review]
Bug 35287: Preparation: AdditionalFields License Mixin

Koha::Object::Mixin::AdditionalFields needs to come before Koha::Object
in the inheritance so that the strings_map method that is called is
the one from Mixin and not from Koha::Object.
This is only required for Koha classes implementing the AdditionalFields Mixin and expose data through the REST API, because strings_map is implement in both the aforementioned classes

Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk>
Comment 15 PTFS Europe Sandboxes 2023-12-07 12:28:58 UTC
Created attachment 159638 [details] [review]
Bug 35287: Admin

ERM licenses is now a table option in the additional fields admin panel
ERM licenses allows for the 'searchable' option (as well as 'repeatable')

Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk>
Comment 16 PTFS Europe Sandboxes 2023-12-07 12:29:00 UTC
Created attachment 159639 [details] [review]
Bug 35287: REST API - Add additional fields support to ERM Licenses

Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk>
Comment 17 PTFS Europe Sandboxes 2023-12-07 12:29:03 UTC
Created attachment 159640 [details] [review]
Bug 35287: Vue preparation - AdditionalFields

New api client: additional-fields-api-client.js to interact with the REST endpoint introduced by bug 35197
2 new components:
- AdditionalFieldsEntry: Component used to extend the FormAdd component including the corresponding additional fields
- AdditionalFieldsDisplay: Component used to display the additional fields associated to a data record implementing it (makes use of strings_map)

Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk>
Comment 18 PTFS Europe Sandboxes 2023-12-07 12:29:05 UTC
Created attachment 159641 [details] [review]
Bug 35287: Vue preparation - Extend KohaTable to consider searchable additional fields

This follows the same pattern as in subscription serials searchable additional fields, i.e. if an additional field is searchable, it is added to the list table - with the corresponding search inputs and functionality

Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk>
Comment 19 PTFS Europe Sandboxes 2023-12-07 12:29:08 UTC
Created attachment 159642 [details] [review]
Bug 35287: Vue - Add additional fields support to ERM Licenses

Test plan, k-t-d:
1) Add a new additional field for the newly supported 'erm_licenses', visit:
/cgi-bin/koha/admin/additional-fields.pl?tablename=erm_licenses
2) Create 4 fields by clicking on '+ New field'
2.1) 'text non-repeatable'
2.2) 'text repeatable', check the 'repeatable' box
2.3) 'av non-repeatable', pick an authorised value category
2.4) 'av repeatable', pick an authorised value category and check the 'repeatable' box
3) Add a new ERM license, visit:
/cgi-bin/koha/erm/licenses/add
4) Notice there is now a 'Additional fields' section at the bottom listing the fields we created
5) Fill in the mandatory regular license fields and play around with the additional fields
5.1) Put in some text in the text fields, test out the 'clear' and '+new' buttons
5.2) Select some AV options from the AV fields, deselect them, notice the repeatable one allows for multiple selection, the non-repeatable one does not
6) Save the license. On the list table, click on the license name (to navigate to the show page), or if license id=1, visit:
/cgi-bin/koha/erm/licenses/1
7) Notice the additional fields are listed there, AV fields show their human readable description, not the AV code. Repeatable fields are shown comma separated
8) Edit the license, visit:
/cgi-bin/koha/erm/licenses/edit/1
9) Play around again, do some more inserting and deletion of additional fields. Save. Notice everything is as expected.

Searchable testing:
10) Go back to the additional fields admin panel, visit:
/cgi-bin/koha/admin/additional-fields.pl?tablename=erm_licenses
11) Edit one field (AV or not) that you have inserted some data in, in the previous steps, and tick the 'searchable' box
12) Go back to licenses, visit:
/cgi-bin/koha/erm/licenses
13) Notice the searchable additional field now has its own column in the licenses list table
14) If the searchable field is AV, it has a dropdown with the AV values of the same AV category
15) If the searchable field not AV, it has a text input that allows for normal text search
16) If the searchable field is repeatable and has multiple values, its displayed in comma separated

Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk>
Comment 20 PTFS Europe Sandboxes 2023-12-07 12:29:11 UTC
Created attachment 159643 [details] [review]
Bug 35287: perltidy for green QA script

Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk>
Comment 21 Edith Speller 2023-12-07 12:31:18 UTC
Great work, thanks very much Pedro!
Comment 22 Martin Renvoize 2023-12-20 16:43:21 UTC
Comment on attachment 159639 [details] [review]
Bug 35287: REST API - Add additional fields support to ERM Licenses

Review of attachment 159639 [details] [review]:
-----------------------------------------------------------------

::: Koha/REST/V1/ERM/Licenses.pm
@@ +183,5 @@
>                  $license->user_roles($user_roles);
>                  $license->documents($documents);
>  
> +                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
> +                $license->extended_attributes( \@extended_attributes );

Won't you need to check here that @extended_attributes is indeed populated.. else you may wipe them away without meaning to?
Comment 23 Pedro Amorim 2024-01-09 17:18:12 UTC
(In reply to Martin Renvoize from comment #22)
> Comment on attachment 159639 [details] [review] [review]
> Bug 35287: REST API - Add additional fields support to ERM Licenses
> 
> Review of attachment 159639 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> ::: Koha/REST/V1/ERM/Licenses.pm
> @@ +183,5 @@
> >                  $license->user_roles($user_roles);
> >                  $license->documents($documents);
> >  
> > +                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
> > +                $license->extended_attributes( \@extended_attributes );
> 
> Won't you need to check here that @extended_attributes is indeed populated..
> else you may wipe them away without meaning to?

Good point. It's working like that by design. The scenario of wiping additional attributes without meaning to should not be possible through the Koha form, as existing data is always pre-populated on the form when editing.

Having said that, it is still possible with a third-party request to the REST API but I believe that to be a wider topic. I've opened bug 35747 where I provide a test plan to discuss it.