View | Details | Raw Unified | Return to bug 34631
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/bug_34631.pl (+18 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
3
4
return {
5
    bug_number  => "34631",
6
    description => "Add new system preference IndependentBranchesAdditionalcontents",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        # Do you stuffs here
12
        $dbh->do(
13
            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')}
14
        );
15
16
        say $out "Added system preference 'IndependentBranchesAdditionalcontents'";
17
    },
18
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 346-351 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
346
('IncludeSeeAlsoFromInSearches','0','','Include see-also-from references in searches.','YesNo'),
346
('IncludeSeeAlsoFromInSearches','0','','Include see-also-from references in searches.','YesNo'),
347
('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'),
347
('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'),
348
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
348
('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'),
349
('IndependentBranchesAdditionalcontents','0', NULL, 'Prevent staff (but not superlibrarians) from editing Additional contents in other libraries','YesNo'),
349
('IndependentBranchesPatronModifications','0', NULL, 'Show only modification request for the logged in branch','YesNo'),
350
('IndependentBranchesPatronModifications','0', NULL, 'Show only modification request for the logged in branch','YesNo'),
350
('IndependentBranchesTransfers','0', NULL, 'Allow non-superlibrarians to transfer items between libraries','YesNo'),
351
('IndependentBranchesTransfers','0', NULL, 'Allow non-superlibrarians to transfer items between libraries','YesNo'),
351
('IntranetAddMastheadLibraryPulldown','0', NULL, 'Add a library select pulldown menu on the staff header search','YesNo'),
352
('IntranetAddMastheadLibraryPulldown','0', NULL, 'Add a library select pulldown menu on the staff header search','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (+7 lines)
Lines 148-153 Administration: Link Here
148
              choices:
148
              choices:
149
                  1: "Yes"
149
                  1: "Yes"
150
                  0: "No"
150
                  0: "No"
151
        -
152
            - "Prevent staff (but not superlibrarians) from editing Additional contents in other libraries: "
153
            - pref: IndependentBranchesAdditionalcontents
154
              default: 0
155
              choices:
156
                  1: "Yes"
157
                  0: "No"
151
        -
158
        -
152
            - pref: ForceLibrarySelection
159
            - pref: ForceLibrarySelection
153
              choices:
160
              choices:
(-)a/tools/additional-contents.pl (-24 / +38 lines)
Lines 64-76 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
64
64
65
my @messages;
65
my @messages;
66
my $my_branch_as_staff =
66
my $my_branch_as_staff =
67
    C4::Context->preference("IndependentBranches")
67
    C4::Context->preference("IndependentBranchesAdditionalcontents")
68
    && !C4::Context->IsSuperLibrarian()
68
    && !C4::Context->IsSuperLibrarian()
69
    ? C4::Context->userenv()->{'branch'}
69
    ? C4::Context->userenv()->{'branch'}
70
    : undef;
70
    : undef;
71
if ( $op eq 'add_form' ) {
71
if ( $op eq 'add_form' ) {
72
72
73
    my $additional_content = Koha::AdditionalContents->find($id);
73
    my $additional_content = Koha::AdditionalContents->find($id);
74
    $additional_content =
75
           undef $my_branch_as_staff
76
        && $additional_content
77
        && C4::Context->userenv()->{'branch'} ne $additional_content->branchcode;
74
    my $translated_contents;
78
    my $translated_contents;
75
    if ($additional_content) {
79
    if ($additional_content) {
76
        $translated_contents = { map { $_->lang => $_ } $additional_content->translated_contents->as_list };
80
        $translated_contents = { map { $_->lang => $_ } $additional_content->translated_contents->as_list };
Lines 200-231 if ( $op eq 'add_form' ) { Link Here
200
    output_and_exit_if_error( $cgi, $cookie, $template, { check => 'csrf_token' } );
204
    output_and_exit_if_error( $cgi, $cookie, $template, { check => 'csrf_token' } );
201
    my @ids = $cgi->multi_param('ids');
205
    my @ids = $cgi->multi_param('ids');
202
206
203
    try {
207
    if ($my_branch_as_staff) {
204
        Koha::Database->new->schema->txn_do(
208
        @ids = grep {
205
            sub {
209
            my $id                 = $_;
206
                my $contents = Koha::AdditionalContents->search( { id => \@ids } );
210
            my $additional_content = Koha::AdditionalContents->find($id);
211
            defined $additional_content->branchcode
212
                && $additional_content->branchcode eq C4::Context->userenv()->{'branch'};
213
        } @ids;
214
    }
215
    if (@ids) {
216
        try {
217
            Koha::Database->new->schema->txn_do(
218
                sub {
219
                    my $contents = Koha::AdditionalContents->search( { id => \@ids } );
207
220
208
                if ( C4::Context->preference("AdditionalContentLog") ) {
221
                    if ( C4::Context->preference("AdditionalContentLog") ) {
209
                    while ( my $c = $contents->next ) {
222
                        while ( my $c = $contents->next ) {
210
                        my $translated_contents = $c->translated_contents;
223
                            my $translated_contents = $c->translated_contents;
211
                        while ( my $translated_content = $translated_contents->next ) {
224
                            while ( my $translated_content = $translated_contents->next ) {
212
                            logaction(
225
                                logaction(
213
                                'NEWS', 'DELETE', undef,
226
                                    'NEWS', 'DELETE', undef,
214
                                sprintf(
227
                                    sprintf(
215
                                    "%s|%s|%s|%s", $c->code, $translated_content->lang, $translated_content->content
228
                                        "%s|%s|%s|%s", $c->code, $translated_content->lang,
216
                                )
229
                                        $translated_content->content
217
                            );
230
                                    )
231
                                );
232
                            }
218
                        }
233
                        }
219
                    }
234
                    }
235
                    $contents->delete;
220
                }
236
                }
221
                $contents->delete;
237
            );
222
            }
238
            push @messages, { type => 'message', code => 'success_on_delete' };
223
        );
239
        } catch {
224
        push @messages, { type => 'message', code => 'success_on_delete' };
240
            warn $_;
225
    } catch {
241
            push @messages, { type => 'error', code => 'error_on_delete' };
226
        warn $_;
242
        };
227
        push @messages, { type => 'error', code => 'error_on_delete' };
243
    }
228
    };
229
244
230
    $op = 'list';
245
    $op = 'list';
231
}
246
}
232
- 

Return to bug 34631