From afed94ff718b414d31b9bc2ad746588d0c4a7593 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 6 May 2013 13:51:27 -0400 Subject: [PATCH] Bug 10200 - 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 +++++++++---- admin/marc_subfields_structure.pl | 1 + catalogue/detail.pl | 2 + cataloguing/addbiblio.pl | 4 +- installer/data/mysql/kohastructure.sql | 2 + installer/data/mysql/updatedatabase.pl | 31 ++++++++++++++++++++ .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 21 ++++++++++--- .../prog/en/modules/admin/preferences/admin.pref | 7 ++++ 9 files changed, 77 insertions(+), 13 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index ca061b5..08d9701 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -186,6 +186,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 7af8619..d390fff 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/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 a5b32c6..dff07a4 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -61,6 +61,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 3314f1a..e131d29 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('IndependantBranches') && C4::Context->userenv && @@ -182,7 +182,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" ) { diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index eddfc3e..7437a4d 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; @@ -613,6 +614,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 35f575a..415af6d 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6802,6 +6802,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`) @@ -6834,6 +6835,36 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion($DBversion); } +$DBversion = "3.11.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($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 9681: Add some database indexes)\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 f669d2c..729f81a 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 %] +