Bugzilla – Attachment 21147 Details for
Bug 10263
Add ability to limit which library can edit a bibliographic record
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10263 - Add ability to limit which branch can edit a bibliographic record ( IndependentBranchesMarcEditing )
Bug-10263---Add-ability-to-limit-which-branch-can-.patch (text/plain), 18.34 KB, created by
Kyle M Hall (khall)
on 2013-09-17 16:58:30 UTC
(
hide
)
Description:
Bug 10263 - Add ability to limit which branch can edit a bibliographic record ( IndependentBranchesMarcEditing )
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2013-09-17 16:58:30 UTC
Size:
18.34 KB
patch
obsolete
>From b53cb24baf168974b80d3ded7cbea835a36a9cd1 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Mon, 6 May 2013 13:51:27 -0400 >Subject: [PATCH] Bug 10263 - Add ability to limit which branch can edit a bibliographic record ( IndependentBranchesMarcEditing ) > >Right now, it's possible to limit who can edit items by using >IndependantBranches. However, Koha has no method of limiting who can >edit bibliographic records, as they have no defined owner. > >This patch adds a new system preference IndependentBranchesMarcEditing. If this new >syspref is enabled, a librarian can only edit or delete a bib record if >his or her logged in branch code matches the branchcode in >biblio.branchcode. This feature does not affect the ability to edit or >delete items, as that functionality is determined by >IndependantBranches. > >This patch adds the 'branches_optional' field to the authorised values >pulldown for MARC fields and subfields in the MARC frameworks editor. >'branches_optional' behaves exactly like 'branches' except it includes >an "empty" choice so the branch does not have to be set. > >Test Plan: > 1) Apply patch > 2) Run updatedatabase.pl > 3) Map a nonrepeatable field/subfield to biblio.branchcode ( e.g. 951$o ) > Pro-tip: Use the authorised value 'branches_optional' to get a pulldown of > libraries instead of entering the branchcode manually. > 4) Edit a record, and add a branchcode. > 5) Log in as a non-superlibrarian with cataloging priveleges > 6) Change the logged in branch to a branch other than the one you > entered in the record. > 7) You should note the 'edit' pulldown for the record is missing the > "Edit record" and "Delete record" options. > 8) Switch the logged in branch to match the branchcode of the record. > 9) You should now see the edit and delete options for that record. >10) Attempt to edit a record with no branchcode defined, you should be > able to. >--- > C4/Auth.pm | 1 + > C4/Biblio.pm | 21 ++++++++--- > Koha/Template/Plugin/Koha.pm | 8 ++++- > admin/marc_subfields_structure.pl | 1 + > catalogue/detail.pl | 2 + > cataloguing/addbiblio.pl | 23 ++++++++++++- > installer/data/mysql/kohastructure.sql | 2 + > installer/data/mysql/updatedatabase.pl | 35 ++++++++++++++++++- > .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 21 +++++++++--- > .../prog/en/modules/admin/preferences/admin.pref | 9 ++++- > .../prog/en/modules/catalogue/results.tt | 3 +- > 11 files changed, 108 insertions(+), 18 deletions(-) > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index 63751e8..386895b 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -188,6 +188,7 @@ sub get_template_and_user { > # to create the template's parameters that will indicate > # which menus the user can access. > if ( $flags && $flags->{superlibrarian}==1 ) { >+ $template->param( CAN_user_superlibrarian => 1 ); > $template->param( CAN_user_circulate => 1 ); > $template->param( CAN_user_catalogue => 1 ); > $template->param( CAN_user_parameters => 1 ); >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index cf83ae6..20a72fc 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -2955,12 +2955,16 @@ sub _koha_add_biblio { > seriestitle = ?, > copyrightdate = ?, > datecreated=NOW(), >- abstract = ? >+ abstract = ?, >+ branchcode = ? > "; > my $sth = $dbh->prepare($query); > $sth->execute( >- $frameworkcode, $biblio->{'author'}, $biblio->{'title'}, $biblio->{'unititle'}, $biblio->{'notes'}, >- $biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'} >+ $frameworkcode, $biblio->{'author'}, >+ $biblio->{'title'}, $biblio->{'unititle'}, >+ $biblio->{'notes'}, $biblio->{'serial'}, >+ $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, >+ $biblio->{'abstract'}, $biblio->{'branchcode'}, > ); > > my $biblionumber = $dbh->{'mysql_insertid'}; >@@ -2997,15 +3001,20 @@ sub _koha_modify_biblio { > serial = ?, > seriestitle = ?, > copyrightdate = ?, >- abstract = ? >+ abstract = ?, >+ branchcode = ? > WHERE biblionumber = ? > " > ; > my $sth = $dbh->prepare($query); > > $sth->execute( >- $frameworkcode, $biblio->{'author'}, $biblio->{'title'}, $biblio->{'unititle'}, $biblio->{'notes'}, >- $biblio->{'serial'}, $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, $biblio->{'abstract'}, $biblio->{'biblionumber'} >+ $frameworkcode, $biblio->{'author'}, >+ $biblio->{'title'}, $biblio->{'unititle'}, >+ $biblio->{'notes'}, $biblio->{'serial'}, >+ $biblio->{'seriestitle'}, $biblio->{'copyrightdate'}, >+ $biblio->{'abstract'}, $biblio->{'branchcode'}, >+ $biblio->{'biblionumber'} > ) if $biblio->{'biblionumber'}; > > if ( $dbh->errstr || !$biblio->{'biblionumber'} ) { >diff --git a/Koha/Template/Plugin/Koha.pm b/Koha/Template/Plugin/Koha.pm >index 2eff9f1..96ee539 100644 >--- a/Koha/Template/Plugin/Koha.pm >+++ b/Koha/Template/Plugin/Koha.pm >@@ -22,7 +22,7 @@ use Modern::Perl; > use base qw( Template::Plugin ); > > use C4::Context; >- >+use C4::Branch qw( GetIndependentGroupModificationRights ); > =pod > > This plugin contains various Koha replated Template Toolkit functions >@@ -44,4 +44,10 @@ sub Preference { > return C4::Context->preference( $pref ); > } > >+sub HasIndependentGroupModificationRightsFor { >+ my ( $self, $branchcode ) = @_; >+ my $value = GetIndependentGroupModificationRights( { for => $branchcode } ); >+ return $value; >+} >+ > 1; >diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl >index 615fbcf..52c3859 100755 >--- a/admin/marc_subfields_structure.pl >+++ b/admin/marc_subfields_structure.pl >@@ -133,6 +133,7 @@ if ( $op eq 'add_form' ) { > push @authorised_values, $category; > } > push( @authorised_values, "branches" ); >+ push( @authorised_values, "branches_optional" ); > push( @authorised_values, "itemtypes" ); > push( @authorised_values, "cn_source" ); > >diff --git a/catalogue/detail.pl b/catalogue/detail.pl >index 72258fd..969faa3 100755 >--- a/catalogue/detail.pl >+++ b/catalogue/detail.pl >@@ -62,6 +62,8 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > my $biblionumber = $query->param('biblionumber'); > my $record = GetMarcBiblio($biblionumber); > >+$template->param( biblio => GetBiblio( $biblionumber ) ); >+ > if ( not defined $record ) { > # biblionumber invalid -> report and exit > $template->param( unknownbiblionumber => 1, >diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl >index 986c989..797ecfd 100755 >--- a/cataloguing/addbiblio.pl >+++ b/cataloguing/addbiblio.pl >@@ -170,7 +170,7 @@ sub build_authorized_values_list { > # builds list, depending on authorised value... > > #---- branch >- if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { >+ if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} =~ /branches|branches_optional/ ) { > #Use GetBranches($onlymine) > my $onlymine = > C4::Context->preference('IndependentBranches') >@@ -183,7 +183,7 @@ sub build_authorized_values_list { > push @authorised_values, $thisbranch; > $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'}; > } >- >+ push( @authorised_values, q{} ) if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq 'branches_optional' ); > #----- itemtypes > } > elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { >@@ -808,6 +808,25 @@ if ($breedingid) { > ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ; > } > >+if ( $record != -1 >+ && C4::Context->preference('IndependentBranchesMarcEditing') ) >+{ >+ my ( $field, $subfield ) = >+ GetMarcFromKohaField( 'biblio.branchcode', $frameworkcode ); >+ if ( >+ defined( $record->field($field) ) >+ && defined( $record->subfield( $field, $subfield ) ) >+ && !GetIndependentGroupModificationRights( >+ { for => $record->subfield( $field, $subfield ) } >+ ) >+ ) >+ { >+ print $input->redirect( >+ "/cgi-bin/koha/catalogue/detail.pl?biblionumber=$biblionumber"); >+ exit; >+ } >+} >+ > #populate hostfield if hostbiblionumber is available > if ($hostbiblionumber) { > my $marcflavour = C4::Context->preference("marcflavour"); >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 9814789..99675b1 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -126,6 +126,7 @@ CREATE TABLE `biblio` ( -- table that stores bibliographic information > `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this record was last touched > `datecreated` DATE NOT NULL, -- the date this record was added to Koha > `abstract` mediumtext, -- summary from the MARC record (520$a in MARC21) >+ `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- branchcode for the opationl 'owner' of this record. > PRIMARY KEY (`biblionumber`), > KEY `blbnoidx` (`biblionumber`) > ) ENGINE=InnoDB DEFAULT CHARSET=utf8; >@@ -715,6 +716,7 @@ CREATE TABLE `deletedbiblio` ( -- stores information about bibliographic records > `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- date and time this record was last touched > `datecreated` DATE NOT NULL, -- the date this record was added to Koha > `abstract` mediumtext, -- summary from the MARC record (520$a in MARC21) >+ `branchcode` VARCHAR( 10 ) NULL DEFAULT NULL, -- branchcode for the opationl 'owner' of this record. > PRIMARY KEY (`biblionumber`), > KEY `blbnoidx` (`biblionumber`) > ) ENGINE=InnoDB DEFAULT CHARSET=utf8; >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 5b10f90..0fff005 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -6800,6 +6800,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { > ADD KEY `branchcode_idx` (`branchcode`), > ADD KEY `issuingbranch_idx` (`issuingbranch`) > }); >+ > #items > $dbh->do(q{ > ALTER TABLE `items` ADD KEY `itype_idx` (`itype`) >@@ -7153,7 +7154,7 @@ if ( CheckVersion($DBversion) ) { > > $DBversion = "3.13.00.XXX"; > if ( CheckVersion($DBversion) ) { >- $dbh->do(" >+ $dbh->do(q{ > INSERT INTO systempreferences ( > variable, > value, >@@ -7167,11 +7168,41 @@ if ( CheckVersion($DBversion) ) { > 'If on, the staff interface search will hide all records that do not contain an item owned by the logged in branch, and hide the items themselves.', > 'YesNo' > ) >- "); >+ }); > print "Upgrade to $DBversion done (Bug 10278 - Add ability to hide items and records from search results for Independent Branches)\n"; > SetVersion ($DBversion); > } > >+$DBversion = "3.13.00.XXX"; >+if ( CheckVersion($DBversion) ) { >+ $dbh->do(q{ >+ INSERT INTO systempreferences ( >+ variable, >+ value, >+ options, >+ explanation, >+ type >+ ) VALUES ( >+ 'IndependentBranchesMarcEditing', >+ '0', >+ '', >+ "If on, this preference disallows the editing of a bibliographic record unless the logged in library's branchcode matchs the branchcode stored in biblio.branchcode.", >+ 'YesNo' >+ ) >+ }); >+ >+ $dbh->do(q{ >+ ALTER TABLE biblio ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL >+ }); >+ >+ $dbh->do(q{ >+ ALTER TABLE deletedbiblio ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL >+ }); >+ >+ print "Upgrade to $DBversion done (Bug 10263 - Add ability to limit which branch can edit a bibliographic record)\n"; >+ SetVersion ($DBversion); >+} >+ > =head1 FUNCTIONS > > =head2 TableExists($table) >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc >index 553d9ae..14526bf 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc >@@ -1,3 +1,5 @@ >+[% USE Koha %] >+ > <script type="text/javascript"> > //<![CDATA[ > [% IF ( CAN_user_editcatalogue_edit_catalogue ) %] >@@ -137,7 +139,7 @@ CAN_user_serials_create_subscription ) %] > <div class="btn-group"> > <button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="icon-pencil"></i> Edit <span class="caret"></span></button> > <ul class="dropdown-menu"> >- [% IF ( CAN_user_editcatalogue_edit_catalogue ) %] >+ [% IF ( CAN_user_editcatalogue_edit_catalogue ) && ( !biblio.branchcode || CAN_user_superlibrarian || ( !Koha.Preference( 'IndependentBranchesMarcEditing' ) || ( Koha.Preference( 'IndependentBranchesMarcEditing' ) && Koha.HasIndependentGroupModificationRightsFor( biblio.branchcode ) ) ) ) %] > <li><a id="editbiblio" href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber %]&frameworkcode=[% current_framework %]&op=">Edit record</a></li> > [% END %] > >@@ -155,11 +157,20 @@ CAN_user_serials_create_subscription ) %] > [% IF ( LocalCoverImages || OPACLocalCoverImages) %][% IF ( CAN_user_tools_upload_local_cover_images ) %]<li><a href="/cgi-bin/koha/tools/upload-cover-image.pl?biblionumber=[% biblionumber %]&filetype=image">Upload image</a>[% END %][% END %] > > [% IF ( CAN_user_editcatalogue_edit_catalogue ) %] >- <li><a id="duplicatebiblio" href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber %]&frameworkcode=[% current_framework %]&op=duplicate">Edit as new (duplicate)</a></li> >- <li><a href="#" id="z3950copy">Replace record via Z39.50</a></li> >+ <li><a id="duplicatebiblio" href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber %]&frameworkcode=[% current_framework %]&op=duplicate">Edit as new (duplicate)</a></li> >+ <li><a href="#" id="z3950copy">Replace record via Z39.50</a></li> >+ >+ >+ [% IF ( !biblio.branchcode || CAN_user_superlibrarian || ( !Koha.Preference( 'IndependentBranchesMarcEditing' ) || ( Koha.Preference( 'IndependentBranchesMarcEditing' ) && LoginBranchcode == biblio.branchcode ) ) ) %] >+ [% IF ( count ) %] >+ <li class="disabled"> >+ [% ELSE %] >+ <li> >+ [% END %] > >- [% IF ( count ) %]<li class="disabled">[% ELSE %]<li>[% END %] >- <a id="deletebiblio" href="/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&biblionumber=[% biblionumber %]">Delete record</a></li> >+ <a id="deletebiblio" href="/cgi-bin/koha/cataloguing/addbiblio.pl?op=delete&biblionumber=[% biblionumber %]">Delete record</a> >+ </li> >+ [% END %] > [% END %] > > [% IF ( CAN_user_editcatalogue_edit_items ) %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >index 7433a53..97376ed 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >@@ -76,7 +76,14 @@ Administration: > choices: > yes: Prevent > no: "Don't prevent" >- - staff from seeing items owned by other libraries, and records without any items the library. >+ - staff from seeing items owned by other libraries, and records without any items the library ( requires IndependentBranches ). >+ - >+ - pref: IndependentBranchesMarcEditing >+ default: 0 >+ choices: >+ yes: Prevent >+ no: "Don't prevent" >+ - the logged in library from editing bibliographic records of other libraries. The owning library is defined by the branchcode in biblio.branchcode which should be mapped to a MARC field ( e.g. 951$o ). > CAS Authentication: > - > - pref: casAuthentication >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt >index 520e6d2..62a71b8 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt >@@ -1,3 +1,4 @@ >+[% USE Koha %] > [% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Catalog › [% IF ( searchdesc ) %]Results of search [% IF ( query_desc ) %]for '[% query_desc | html %]'[% END %][% IF ( limit_desc ) %] with limit(s): '[% limit_desc | html %]'[% END %][% ELSE %]You did not specify any search criteria[% END %]</title> > [% INCLUDE 'doc-head-close.inc' %] >@@ -517,7 +518,7 @@ var holdForPatron = function () { > <a id="reserve_[% SEARCH_RESULT.biblionumber %]" href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]">Holds</a> > [% IF ( holdfor ) %] <span class="holdforlink">| <a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]&findborrower=[% holdfor_cardnumber %]">Place hold for [% holdfor_firstname %] [% holdfor_surname %] ([% holdfor_cardnumber %])</a></span>[% END %] > [% END %] >- [% IF ( CAN_user_editcatalogue_edit_catalogue ) %] >+ [% IF ( CAN_user_editcatalogue_edit_catalogue ) && ( !SEARCH_RESULT.branchcode || CAN_user_superlibrarian || ( !Koha.Preference( 'IndependentBranchesMarcEditing' ) || ( Koha.Preference( 'IndependentBranchesMarcEditing' ) && Koha.HasIndependentGroupModificationRightsFor( SEARCH_RESULT.branchcode ) ) ) ) %] > | <a href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% SEARCH_RESULT.biblionumber %]">Edit record</a> > [% END %] > [% IF ( CAN_user_editcatalogue_edit_items ) %] >-- >1.7.2.5
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 10263
:
18174
|
18480
|
18521
|
18837
|
18848
|
18849
|
20775
|
21147
|
23491
|
23636
|
23639