Bug 33578

Summary: Cannot edit patron restriction types
Product: Koha Reporter: Katrin Fischer <katrin.fischer>
Component: System AdministrationAssignee: Jonathan Druart <jonathan.druart>
Status: RESOLVED FIXED QA Contact: Marcel de Rooy <m.de.rooy>
Severity: normal    
Priority: P5 - low CC: andrewfh, gmcharlt, jonathan.druart, Laura.escamilla, m.de.rooy, martin.renvoize, michaela.sieber
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.11.00,23.05.02,22.11.08
Bug Depends on: 23681    
Bug Blocks:    
Attachments: Bug 33578: Fix patron restriction types edition
Bug 33578: Fix controller when editing a restriction type
Bug 33578: Fix patron restriction types edition
Bug 33578: Fix controller when editing a restriction type
Bug 33578: Fix patron restriction types edition
Bug 33578: Fix controller when editing a restriction type

Description Katrin Fischer 2023-04-20 21:04:48 UTC
When editing an existing patron restriction type you'll always get an error on saving:

Label is already in use 

Of course the label is already in use... for the restriction type I am just editing.

To test:
* Activate use of patron restriction types
* Edit any of the system types
* Save --> Notice error :(
Comment 1 Martin Renvoize 2023-04-21 08:29:42 UTC
Is this on a specific version, Katrin?  I can't replicate it here
Comment 2 Katrin Fischer 2023-04-21 09:58:53 UTC
I was testing on master yesterday - I'll repeat the test now.
Comment 3 Katrin Fischer 2023-04-21 10:00:57 UTC
Hm, I still have the issue, git pulled master, restart_all and in a new private window.

Edit MANUAL
Change nothing
Try to save > Error
Comment 4 Katrin Fischer 2023-04-21 10:04:11 UTC
Quick guess: Maybe the one you edit shouldn't be in the list of existing ones?
    <script>
        var MSG_DUPLICATE_CODE = _("Restriction code is already in use");
        var MSG_DUPLICATE_DISPLAY_TEXT = _("Label is already in use");
        var existing = {
        
            DISCHARGE: 'Discharge tkk',
        
            MANUAL: 'Manual',
        
            OVERDUES: 'Overdues',
        
            SUSPENSION: 'Suspension',
        
        };
    </script>

jQuery.validator.addMethod( "restrictionDisplayText", function(value){
    var ex = Object.values(existing).map(function(el) {
        return el.toLowerCase();
    });
    return (value.length > 0 && ex.indexOf(value.toLowerCase()) > -1) ?
        false :
        true;
}, MSG_DUPLICATE_DISPLAY_TEXT);
Comment 5 Jonathan Druart 2023-05-10 09:22:30 UTC
Created attachment 150957 [details] [review]
Bug 33578: Fix patron restriction types edition

When editing an existing patron restriction type you'll always get an error on saving:

Label is already in use

To test:
* Activate use of patron restriction types
* Edit any of the system types
* Create new ones
Comment 6 Owen Leonard 2023-05-10 11:04:41 UTC
This patch works for the form validation error, but I see something else too: If you open the restriction edit form and submit it without changing anything you'll be returned to the "Patron restrictions" page where there will be a message, " Another restriction already has this label"
Comment 7 Jonathan Druart 2023-05-10 11:54:54 UTC
Created attachment 150976 [details] [review]
Bug 33578: Fix controller when editing a restriction type

Do not display a warning when we are editing a restriction type and no
other types with this description exists.
Comment 8 Laura Escamilla 2023-05-17 20:43:12 UTC
(In reply to Jonathan Druart from comment #7)
> Created attachment 150976 [details] [review] [review]
> Bug 33578: Fix controller when editing a restriction type
> 
> Do not display a warning when we are editing a restriction type and no
> other types with this description exists.

Still seeing the message that Owen reported.
Comment 9 PTFS Europe Sandboxes 2023-05-19 13:48:20 UTC
Created attachment 151478 [details] [review]
Bug 33578: Fix patron restriction types edition

When editing an existing patron restriction type you'll always get an error on saving:

Label is already in use

To test:
* Activate use of patron restriction types
* Edit any of the system types
* Create new ones

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 10 PTFS Europe Sandboxes 2023-05-19 13:48:22 UTC
Created attachment 151479 [details] [review]
Bug 33578: Fix controller when editing a restriction type

Do not display a warning when we are editing a restriction type and no
other types with this description exists.

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Comment 11 Marcel de Rooy 2023-06-23 06:27:56 UTC
Created attachment 152610 [details] [review]
Bug 33578: Fix patron restriction types edition

When editing an existing patron restriction type you'll always get an error on saving:

Label is already in use

To test:
* Activate use of patron restriction types
* Edit any of the system types
* Create new ones

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 12 Marcel de Rooy 2023-06-23 06:27:58 UTC
Created attachment 152611 [details] [review]
Bug 33578: Fix controller when editing a restriction type

Do not display a warning when we are editing a restriction type and no
other types with this description exists.

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 13 Tomás Cohen Arazi 2023-06-23 13:01:49 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 14 Martin Renvoize 2023-07-17 14:02:52 UTC
Thanks for all the hard work!

Pushed to 23.05.x for the next release
Comment 15 Pedro Amorim 2023-07-18 11:54:29 UTC
Nice work everyone!

Pushed to 22.11.x for next release