Bug 25826: Forbid changing the hidden attributes for biblionumber
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 27 Jul 2020 15:18:36 +0000 (12:18 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 7 Aug 2020 07:55:50 +0000 (09:55 +0200)
This patch tweaks the UI so it forbids changing the hidden values when
they are correct (i.e. when they are not hidden in OPAC and intranet).

To test:
1. Apply the first patch
2. Play with the hidden values of the subfield you have mapped to
   biblio.biblionumber in your picked framework. This is usually 999$c
   in MARC21, and 001 in UNIMARC.
=> SUCCESS: When you verify the about.pl, it mentions issues when you
hide in some of the interfaces
3. Apply this patch and reload everything
4. Repeat 2
=> SUCCESS: If your framework is 'ok', it prevents you from editing this
values, otherwise you can change them.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

admin/marc_subfields_structure.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt
koha-tmpl/intranet-tmpl/prog/js/marc_subfields_structure.js

index 0dce186..c02633a 100755 (executable)
@@ -25,6 +25,7 @@ use C4::Context;
 
 use Koha::Authority::Types;
 use Koha::AuthorisedValueCategories;
+use Koha::Filter::MARC::ViewPolicy;
 
 use List::MoreUtils qw( uniq );
 
@@ -192,6 +193,33 @@ if ( $op eq 'add_form' ) {
         $row_data{isurl}             = $data->{isurl};
         $row_data{row}               = $i;
         $row_data{link}              = $data->{'link'};
+
+        if ( defined $data->{kohafield}
+            and $data->{kohafield} eq 'biblio.biblionumber' )
+        {
+            my $hidden_opac = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
+                    {
+                        frameworkcode => $frameworkcode,
+                        interface     => "opac",
+                    }
+                )->{biblionumber};
+
+            my $hidden_intranet = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
+                    {
+                        frameworkcode => $frameworkcode,
+                        interface     => "intranet",
+                    }
+                )->{biblionumber};
+
+            if ( $hidden_opac or $hidden_intranet ) {
+                # We should allow editing for fixing it
+                $row_data{hidden_protected} = 0;
+            }
+            else {
+                $row_data{hidden_protected} = 1;
+            }
+        }
+
         push( @loop_data, \%row_data );
         $i++;
     }
index 7736f1f..81815e7 100644 (file)
                 <ol><li><label for="defaultvalue[% loo.row | html %]">Default value:</label>
                     <input type="text" name="defaultvalue" id="defaultvalue[% loo.row | html %]" value="[% loo.defaultvalue | html %]" /></li>
                     <li><label for="maxlength[% loo.row | html %]">Max length:</label><input type="text" id="maxlength[% loo.row | html %]" name="maxlength" value="[% loo.maxlength | html %]" size="4" /></li>
-                <li><input type="hidden" id="hidden-[% loo.row | html %]" name="hidden" value="[% loo.hidden | html %]" />
+                <li><input type="hidden" id="hidden-[% loo.row | html %]" name="hidden" value="[% loo.hidden | html %]" [%- IF loo.hidden_protected -%]data-koha-protected="1"[%- END -%] />
                     <label for="hidden[% loo.row | html %]" style="float: none;">Visibility: </label>
                     <input type="checkbox" id="hidden_opac_[% loo.row | html %]" class="inclusive_[% loo.row | html %]" name="hidden_opac_[% loo.row | html %]"/>
                     <label for="hidden_opac_[% loo.row | html %]" style="float: none;">OPAC</label>
index aa90be6..081afd2 100644 (file)
@@ -70,7 +70,10 @@ function setHiddenValue() {
         hidden_value='8';
     }
 
-    enable_cb(tab);
+    var hidden_protected = $('#hidden-'+ tab).attr('data-koha-protected');
+    if ( hidden_protected != 1 ) {
+        enable_cb(tab);
+    }
 
     $('#hidden-' + tab).val(hidden_value);
 
@@ -79,6 +82,7 @@ function setHiddenValue() {
 function populateHiddenCheckboxes(tab) {
     // read the serialized value
     var hidden_value = $('#hidden-' + tab).val();
+    var hidden_protected = $('#hidden-'+ tab).attr('data-koha-protected');
     // deafult to false
     var opac_checked = false;
     var intranet_checked = false;
@@ -143,6 +147,14 @@ function populateHiddenCheckboxes(tab) {
     $("#hidden_collapsed_" + tab).prop('checked',collapsed_checked);
     $("#hidden_flagged_" + tab).prop('checked',flagged_checked);
 
-    enable_cb(tab);
-
+    if ( hidden_protected == 1 ) {
+        $("#hidden_opac_" + tab).prop('disabled','disabled');
+        $("#hidden_intranet_" + tab).prop('disabled','disabled');
+        $("#hidden_editor_" + tab).prop('disabled','disabled');
+        $("#hidden_collapsed_" + tab).prop('disabled','disabled');
+        $("#hidden_flagged_" + tab).prop('disabled','disabled');
+    }
+    else {
+        enable_cb(tab);
+    }
 }