Bugzilla – Attachment 180604 Details for
Bug 34631
Independentbranches - Non-superuser should not be able to write Additional contents for other branches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34631: Add IndependentBranchesAdditionalcontents preference and some checks into additional-contents.pl
Bug-34631-Add-IndependentBranchesAdditionalcontent.patch (text/plain), 8.24 KB, created by
Hammat wele
on 2025-04-03 18:16:09 UTC
(
hide
)
Description:
Bug 34631: Add IndependentBranchesAdditionalcontents preference and some checks into additional-contents.pl
Filename:
MIME Type:
Creator:
Hammat wele
Created:
2025-04-03 18:16:09 UTC
Size:
8.24 KB
patch
obsolete
>From 4790191aa0c86ae34bbc4e4278181c90f441bf98 Mon Sep 17 00:00:00 2001 >From: Hammat Wele <hammat.wele@inlibro.com> >Date: Thu, 3 Apr 2025 18:12:27 +0000 >Subject: [PATCH] Bug 34631: Add IndependentBranchesAdditionalcontents > preference and some checks into additional-contents.pl > >To reproduce: >1- Connect to staff interface as superlibrarian >2- Enable IndependentBranches preference >3- Go to Tools -> HTML customizations >4- Crete an additional content for all libraries >5- Create or edit a borrower > 5-1- Set permission for the borrower > - catalogue > - edit_additional_contents >4- Log in to the staff interface with the non-superlibrarian staff user >5- Go to Tools -> HTML customizations > --> you can delete or edit the additional contents created by superlibrarian for All libraries >6- Click on New entry > --> you can add additional content for other branches >7- Apply the patch and run updatedatabase >8- Enable IndependentBranchesAdditionalcontents preference >9- Repeat step 5 > --> you cannot delete or edit the additional contents create by superlibrarian for All libraries > even by url manipulation >10- Repeat step 6 > --> you cannot add additional content for other branches >11- submit the form > --> the branch of the created additional content is the current user branch >--- > .../data/mysql/atomicupdate/bug_34631.pl | 18 ++++++ > installer/data/mysql/mandatory/sysprefs.sql | 1 + > .../en/modules/admin/preferences/admin.pref | 7 +++ > tools/additional-contents.pl | 61 ++++++++++++------- > 4 files changed, 64 insertions(+), 23 deletions(-) > create mode 100755 installer/data/mysql/atomicupdate/bug_34631.pl > >diff --git a/installer/data/mysql/atomicupdate/bug_34631.pl b/installer/data/mysql/atomicupdate/bug_34631.pl >new file mode 100755 >index 0000000000..9d598bf03f >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_34631.pl >@@ -0,0 +1,18 @@ >+use Modern::Perl; >+use Koha::Installer::Output qw(say_warning say_failure say_success say_info); >+ >+return { >+ bug_number => "34631", >+ description => "Add new system preference IndependentBranchesAdditionalcontents", >+ up => sub { >+ my ($args) = @_; >+ my ( $dbh, $out ) = @$args{qw(dbh out)}; >+ >+ # Do you stuffs here >+ $dbh->do( >+ q{INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('IndependentBranchesAdditionalcontents','0',NULL,'Prevent staff (but not superlibrarians) from editing Additional contents in other libraries', 'YesNo')} >+ ); >+ >+ say $out "Added system preference 'IndependentBranchesAdditionalcontents'"; >+ }, >+}; >diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql >index 2bf9d0b648..b99de3d657 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -336,6 +336,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('IncludeSeeAlsoFromInSearches','0','','Include see-also-from references in searches.','YesNo'), > ('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'), > ('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'), >+('IndependentBranchesAdditionalcontents','0', NULL, 'Prevent staff (but not superlibrarians) from editing Additional contents in other libraries','YesNo'), > ('IndependentBranchesPatronModifications','0', NULL, 'Show only modification request for the logged in branch','YesNo'), > ('IndependentBranchesTransfers','0', NULL, 'Allow non-superlibrarians to transfer items between libraries','YesNo'), > ('IntranetAddMastheadLibraryPulldown','0', NULL, 'Add a library select pulldown menu on the staff header search','YesNo'), >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 18d21a955a..fe190b32ea 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 >@@ -148,6 +148,13 @@ Administration: > choices: > 1: "Yes" > 0: "No" >+ - >+ - "Prevent staff (but not superlibrarians) from editing Additional contents in other libraries: " >+ - pref: IndependentBranchesAdditionalcontents >+ default: 0 >+ choices: >+ 1: "Yes" >+ 0: "No" > - > - pref: ForceLibrarySelection > choices: >diff --git a/tools/additional-contents.pl b/tools/additional-contents.pl >index be173ff9ce..c81f39b1b6 100755 >--- a/tools/additional-contents.pl >+++ b/tools/additional-contents.pl >@@ -64,13 +64,17 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > > my @messages; > my $my_branch_as_staff = >- C4::Context->preference("IndependentBranches") >+ C4::Context->preference("IndependentBranchesAdditionalcontents") > && !C4::Context->IsSuperLibrarian() > ? C4::Context->userenv()->{'branch'} > : undef; > if ( $op eq 'add_form' ) { > > my $additional_content = Koha::AdditionalContents->find($id); >+ $additional_content = >+ undef $my_branch_as_staff >+ && $additional_content >+ && C4::Context->userenv()->{'branch'} ne $additional_content->branchcode; > my $translated_contents; > if ($additional_content) { > $translated_contents = { map { $_->lang => $_ } $additional_content->translated_contents->as_list }; >@@ -198,32 +202,43 @@ if ( $op eq 'add_form' ) { > output_and_exit_if_error( $cgi, $cookie, $template, { check => 'csrf_token' } ); > my @ids = $cgi->multi_param('ids'); > >- try { >- Koha::Database->new->schema->txn_do( >- sub { >- my $contents = Koha::AdditionalContents->search( { id => \@ids } ); >+ if ($my_branch_as_staff) { >+ @ids = grep { >+ my $id = $_; >+ my $additional_content = Koha::AdditionalContents->find($id); >+ defined $additional_content->branchcode >+ && $additional_content->branchcode eq C4::Context->userenv()->{'branch'}; >+ } @ids; >+ } >+ if (@ids) { >+ try { >+ Koha::Database->new->schema->txn_do( >+ sub { >+ my $contents = Koha::AdditionalContents->search( { id => \@ids } ); > >- if ( C4::Context->preference("NewsLog") ) { >- while ( my $c = $contents->next ) { >- my $translated_contents = $c->translated_contents; >- while ( my $translated_content = $translated_contents->next ) { >- logaction( >- 'NEWS', 'DELETE', undef, >- sprintf( >- "%s|%s|%s|%s", $c->code, $translated_content->lang, $translated_content->content >- ) >- ); >+ if ( C4::Context->preference("NewsLog") ) { >+ while ( my $c = $contents->next ) { >+ my $translated_contents = $c->translated_contents; >+ while ( my $translated_content = $translated_contents->next ) { >+ logaction( >+ 'NEWS', 'DELETE', undef, >+ sprintf( >+ "%s|%s|%s|%s", $c->code, $translated_content->lang, >+ $translated_content->content >+ ) >+ ); >+ } > } > } >+ $contents->delete; > } >- $contents->delete; >- } >- ); >- push @messages, { type => 'message', code => 'success_on_delete' }; >- } catch { >- warn $_; >- push @messages, { type => 'error', code => 'error_on_delete' }; >- }; >+ ); >+ push @messages, { type => 'message', code => 'success_on_delete' }; >+ } catch { >+ warn $_; >+ push @messages, { type => 'error', code => 'error_on_delete' }; >+ }; >+ } > > $op = 'list'; > } >-- >2.34.1
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 34631
:
154889
|
154890
|
162787
|
162788
|
162856
|
162929
|
162972
|
162995
|
172231
|
175973
|
175974
|
175975
|
175976
|
179859
|
179860
|
180602
|
180603
| 180604