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

(-)a/C4/Auth.pm (-58 / +4 lines)
Lines 50-55 use C4::Auth_with_shibboleth qw( shib_ok get_login_shib login_shib_url logout_sh Link Here
50
use Net::CIDR;
50
use Net::CIDR;
51
use C4::Log qw( logaction );
51
use C4::Log qw( logaction );
52
use Koha::CookieManager;
52
use Koha::CookieManager;
53
use Koha::Auth::Permissions;
53
54
54
# use utf8;
55
# use utf8;
55
56
Lines 321-387 sub get_template_and_user { Link Here
321
            );
322
            );
322
        }
323
        }
323
324
324
        my $all_perms = get_all_subpermissions();
325
326
        my @flagroots = qw(circulate catalogue parameters borrowers permissions reserveforothers borrow
327
          editcatalogue updatecharges tools editauthorities serials reports acquisition clubs problem_reports);
328
329
        # We are going to use the $flags returned by checkauth
325
        # We are going to use the $flags returned by checkauth
330
        # to create the template's parameters that will indicate
326
        # to create the template's parameters that will indicate
331
        # which menus the user can access.
327
        # which menus the user can access.
332
        if ( $flags && $flags->{superlibrarian} == 1 ) {
328
        my $authz = Koha::Auth::Permissions->get_authz_from_flags({ flags => $flags });
333
            $template->param( CAN_user_circulate        => 1 );
329
        foreach my $permission ( keys %{ $authz } ){
334
            $template->param( CAN_user_catalogue        => 1 );
330
            $template->param( $permission => $authz->{$permission} );
335
            $template->param( CAN_user_parameters       => 1 );
336
            $template->param( CAN_user_borrowers        => 1 );
337
            $template->param( CAN_user_permissions      => 1 );
338
            $template->param( CAN_user_reserveforothers => 1 );
339
            $template->param( CAN_user_editcatalogue    => 1 );
340
            $template->param( CAN_user_updatecharges    => 1 );
341
            $template->param( CAN_user_acquisition      => 1 );
342
            $template->param( CAN_user_suggestions      => 1 );
343
            $template->param( CAN_user_tools            => 1 );
344
            $template->param( CAN_user_editauthorities  => 1 );
345
            $template->param( CAN_user_serials          => 1 );
346
            $template->param( CAN_user_reports          => 1 );
347
            $template->param( CAN_user_staffaccess      => 1 );
348
            $template->param( CAN_user_coursereserves   => 1 );
349
            $template->param( CAN_user_plugins          => 1 );
350
            $template->param( CAN_user_lists            => 1 );
351
            $template->param( CAN_user_clubs            => 1 );
352
            $template->param( CAN_user_ill              => 1 );
353
            $template->param( CAN_user_stockrotation    => 1 );
354
            $template->param( CAN_user_cash_management  => 1 );
355
            $template->param( CAN_user_problem_reports  => 1 );
356
            $template->param( CAN_user_recalls          => 1 );
357
358
            foreach my $module ( keys %$all_perms ) {
359
                foreach my $subperm ( keys %{ $all_perms->{$module} } ) {
360
                    $template->param( "CAN_user_${module}_${subperm}" => 1 );
361
                }
362
            }
363
        }
364
365
        if ($flags) {
366
            foreach my $module ( keys %$all_perms ) {
367
                if ( defined($flags->{$module}) && $flags->{$module} == 1 ) {
368
                    foreach my $subperm ( keys %{ $all_perms->{$module} } ) {
369
                        $template->param( "CAN_user_${module}_${subperm}" => 1 );
370
                    }
371
                } elsif ( ref( $flags->{$module} ) ) {
372
                    foreach my $subperm ( keys %{ $flags->{$module} } ) {
373
                        $template->param( "CAN_user_${module}_${subperm}" => 1 );
374
                    }
375
                }
376
            }
377
        }
378
379
        if ($flags) {
380
            foreach my $module ( keys %$flags ) {
381
                if ( $flags->{$module} == 1 or ref( $flags->{$module} ) ) {
382
                    $template->param( "CAN_user_$module" => 1 );
383
                }
384
            }
385
        }
331
        }
386
332
387
        # Logged-in opac search history
333
        # Logged-in opac search history
(-)a/Koha/Auth/Permissions.pm (+69 lines)
Line 0 Link Here
1
package Koha::Auth::Permissions;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use C4::Auth qw//;
21
22
=head1 NAME
23
24
Koha::Auth::Permissions - Class for setting up CAN_user_* permissions
25
26
=head1 SYNOPSIS
27
28
=head2 METHODS
29
30
=head3 get_authz_from_flags
31
32
=cut
33
34
sub get_authz_from_flags {
35
    my ($class,$args) = @_;
36
    my $flags = $args->{flags};
37
    my $authz;
38
    my $all_perms = C4::Auth::get_all_subpermissions();
39
    if ($flags && $all_perms){
40
        foreach my $module ( keys %$all_perms ) {
41
            if (
42
                ( $flags->{superlibrarian} == 1 ) ||
43
                ( defined($flags->{$module}) && $flags->{$module} == 1 )
44
            ) {
45
                foreach my $subperm ( keys %{ $all_perms->{$module} } ) {
46
                    $authz->{ "CAN_user_${module}_${subperm}" } = 1;
47
                }
48
            }
49
            elsif ( ref( $flags->{$module} ) ){
50
                foreach my $subperm ( keys %{ $flags->{$module} } ) {
51
                    $authz->{ "CAN_user_${module}_${subperm}" } = 1;
52
                }
53
            }
54
        }
55
        foreach my $module ( keys %$flags ) {
56
            if (
57
                ( $flags->{superlibrarian} == 1 ) ||
58
                ( $flags->{$module} == 1 ) ||
59
                ( ref( $flags->{$module} ) )
60
            ) {
61
                $authz->{ "CAN_user_$module" } = 1;
62
            }
63
        }
64
    }
65
    return $authz;
66
}
67
68
69
1;
(-)a/t/Koha/Auth/Permissions.t (-1 / +269 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 3;
21
22
use_ok('Koha::Auth::Permissions');
23
24
subtest 'normal staff user test' => sub {
25
    plan tests => 1;
26
    my $flags = {
27
      'permissions' => 0,
28
      'circulate' => {
29
        circulate_remaining_permissions => 1,
30
      },
31
      'staffaccess' => 1,
32
      'editcatalogue' => 0,
33
      'cash_management' => 0,
34
      'reserveforothers' => 0,
35
      'serials' => 0,
36
      'borrowers' => 0,
37
      'lists' => 0,
38
      'suggestions' => 0,
39
      'acquisition' => 0,
40
      'tools' => 0,
41
      'stockrotation' => 0,
42
      'clubs' => 0,
43
      'reports' => 0,
44
      'editauthorities' => 0,
45
      'updatecharges' => 0,
46
      'ill' => 0,
47
      'coursereserves' => 0,
48
      'self_check' => 0,
49
      'plugins' => 0,
50
      'superlibrarian' => 0,
51
      'recalls' => 0,
52
      'catalogue' => 0,
53
      'problem_reports' => 0,
54
      'parameters' => 0
55
    };
56
    my $authz = Koha::Auth::Permissions->get_authz_from_flags({ flags => $flags });
57
    my $expected = {
58
      'CAN_user_staffaccess' => 1,
59
      'CAN_user_circulate' => 1,
60
      'CAN_user_circulate_circulate_remaining_permissions' => 1,
61
    };
62
    is_deeply($authz,$expected,'Expected permissions generated for superlibrarian');
63
};
64
65
subtest 'superlibrarian tests' => sub {
66
    plan tests => 1;
67
    my $flags = {
68
      'permissions' => 0,
69
      'circulate' => 0,
70
      'staffaccess' => 0,
71
      'editcatalogue' => 0,
72
      'cash_management' => 0,
73
      'reserveforothers' => 0,
74
      'serials' => 0,
75
      'borrowers' => 0,
76
      'lists' => 0,
77
      'suggestions' => 0,
78
      'acquisition' => 0,
79
      'tools' => 0,
80
      'stockrotation' => 0,
81
      'clubs' => 0,
82
      'reports' => 0,
83
      'editauthorities' => 0,
84
      'updatecharges' => 0,
85
      'ill' => 0,
86
      'coursereserves' => 0,
87
      'self_check' => 0,
88
      'plugins' => 0,
89
      'superlibrarian' => 1,
90
      'recalls' => 0,
91
      'catalogue' => 0,
92
      'problem_reports' => 0,
93
      'parameters' => 0
94
    };
95
    my $authz = Koha::Auth::Permissions->get_authz_from_flags({ flags => $flags });
96
    my $expected = {
97
      'CAN_user_staffaccess' => 1,
98
      'CAN_user_parameters_manage_curbside_pickups' => 1,
99
      'CAN_user_serials' => 1,
100
      'CAN_user_self_check_self_checkout_module' => 1,
101
      'CAN_user_parameters_manage_audio_alerts' => 1,
102
      'CAN_user_parameters_manage_additional_fields' => 1,
103
      'CAN_user_parameters_manage_accounts' => 1,
104
      'CAN_user_tools_moderate_tags' => 1,
105
      'CAN_user_coursereserves_manage_courses' => 1,
106
      'CAN_user_clubs_enroll' => 1,
107
      'CAN_user_tools_manage_staged_marc' => 1,
108
      'CAN_user_updatecharges_discount' => 1,
109
      'CAN_user_tools_moderate_comments' => 1,
110
      'CAN_user_parameters_manage_search_engine_config' => 1,
111
      'CAN_user_acquisition_planning_manage' => 1,
112
      'CAN_user_updatecharges_refund' => 1,
113
      'CAN_user_self_check_self_checkin_module' => 1,
114
      'CAN_user_acquisition_currencies_manage' => 1,
115
      'CAN_user_acquisition_vendors_manage' => 1,
116
      'CAN_user_updatecharges_writeoff' => 1,
117
      'CAN_user_tools_edit_quotes' => 1,
118
      'CAN_user_acquisition_group_manage' => 1,
119
      'CAN_user_circulate' => 1,
120
      'CAN_user_acquisition_budget_modify' => 1,
121
      'CAN_user_permissions' => 1,
122
      'CAN_user_plugins' => 1,
123
      'CAN_user_superlibrarian' => 1,
124
      'CAN_user_parameters_manage_marc_overlay_rules' => 1,
125
      'CAN_user_circulate_circulate_remaining_permissions' => 1,
126
      'CAN_user_circulate_manage_curbside_pickups' => 1,
127
      'CAN_user_acquisition_budget_manage' => 1,
128
      'CAN_user_tools_manage_patron_lists' => 1,
129
      'CAN_user_reserveforothers_modify_holds_priority' => 1,
130
      'CAN_user_cash_management_anonymous_refund' => 1,
131
      'CAN_user_editcatalogue_edit_items_restricted' => 1,
132
      'CAN_user_tools_delete_anonymize_patrons' => 1,
133
      'CAN_user_editcatalogue' => 1,
134
      'CAN_user_tools_upload_manage' => 1,
135
      'CAN_user_parameters_manage_marc_frameworks' => 1,
136
      'CAN_user_reports_delete_reports' => 1,
137
      'CAN_user_tools_import_patrons' => 1,
138
      'CAN_user_borrowers_delete_borrowers' => 1,
139
      'CAN_user_tools_rotating_collections' => 1,
140
      'CAN_user_acquisition_budget_manage_all' => 1,
141
      'CAN_user_circulate_override_renewals' => 1,
142
      'CAN_user_serials_claim_serials' => 1,
143
      'CAN_user_tools_stage_marc_import' => 1,
144
      'CAN_user_serials_edit_subscription' => 1,
145
      'CAN_user_cash_management_cashup' => 1,
146
      'CAN_user_parameters_manage_cities' => 1,
147
      'CAN_user_parameters_manage_auth_values' => 1,
148
      'CAN_user_parameters_manage_column_config' => 1,
149
      'CAN_user_parameters_manage_didyoumean' => 1,
150
      'CAN_user_problem_reports' => 1,
151
      'CAN_user_acquisition_delete_invoices' => 1,
152
      'CAN_user_cash_management_takepayment' => 1,
153
      'CAN_user_tools_batch_extend_due_dates' => 1,
154
      'CAN_user_circulate_manage_checkout_notes' => 1,
155
      'CAN_user_circulate_overdues_report' => 1,
156
      'CAN_user_reports_execute_reports' => 1,
157
      'CAN_user_tools_marc_modification_templates' => 1,
158
      'CAN_user_tools_manage_csv_profiles' => 1,
159
      'CAN_user_recalls_manage_recalls' => 1,
160
      'CAN_user_reserveforothers_place_holds' => 1,
161
      'CAN_user_plugins_tool' => 1,
162
      'CAN_user_editcatalogue_delete_all_items' => 1,
163
      'CAN_user_editcatalogue_edit_catalogue' => 1,
164
      'CAN_user_coursereserves_delete_reserves' => 1,
165
      'CAN_user_lists_edit_public_lists' => 1,
166
      'CAN_user_parameters_manage_item_search_fields' => 1,
167
      'CAN_user_editcatalogue_manage_item_groups' => 1,
168
      'CAN_user_borrowers_view_borrower_infos_from_any_libraries' => 1,
169
      'CAN_user_stockrotation_manage_rota_items' => 1,
170
      'CAN_user_editauthorities' => 1,
171
      'CAN_user_parameters_manage_usage_stats' => 1,
172
      'CAN_user_parameters_manage_item_circ_alerts' => 1,
173
      'CAN_user_circulate_manage_restrictions' => 1,
174
      'CAN_user_parameters_manage_classifications' => 1,
175
      'CAN_user_clubs' => 1,
176
      'CAN_user_tools_items_batchdel' => 1,
177
      'CAN_user_borrowers_edit_borrowers' => 1,
178
      'CAN_user_parameters_manage_sms_providers' => 1,
179
      'CAN_user_reports_create_reports' => 1,
180
      'CAN_user_parameters_manage_oai_sets' => 1,
181
      'CAN_user_acquisition_order_manage' => 1,
182
      'CAN_user_editcatalogue_advanced_editor' => 1,
183
      'CAN_user_suggestions' => 1,
184
      'CAN_user_clubs_edit_clubs' => 1,
185
      'CAN_user_parameters_manage_patron_attributes' => 1,
186
      'CAN_user_reserveforothers' => 1,
187
      'CAN_user_acquisition_period_manage' => 1,
188
      'CAN_user_editcatalogue_create_shared_macros' => 1,
189
      'CAN_user_plugins_manage' => 1,
190
      'CAN_user_problem_reports_manage_problem_reports' => 1,
191
      'CAN_user_tools_label_creator' => 1,
192
      'CAN_user_parameters_manage_circ_rules_from_any_libraries' => 1,
193
      'CAN_user_serials_create_subscription' => 1,
194
      'CAN_user_tools_inventory' => 1,
195
      'CAN_user_tools_upload_general_files' => 1,
196
      'CAN_user_tools_edit_additional_contents' => 1,
197
      'CAN_user_acquisition_edi_manage' => 1,
198
      'CAN_user_tools_edit_notice_status_triggers' => 1,
199
      'CAN_user_parameters_manage_smtp_servers' => 1,
200
      'CAN_user_parameters_manage_libraries' => 1,
201
      'CAN_user_serials_receive_serials' => 1,
202
      'CAN_user_parameters_manage_patron_categories' => 1,
203
      'CAN_user_tools_items_batchmod' => 1,
204
      'CAN_user_tools_view_system_logs' => 1,
205
      'CAN_user_serials_renew_subscription' => 1,
206
      'CAN_user_parameters_manage_keyboard_shortcuts' => 1,
207
      'CAN_user_recalls' => 1,
208
      'CAN_user_acquisition_contracts_manage' => 1,
209
      'CAN_user_circulate_force_checkout' => 1,
210
      'CAN_user_coursereserves_add_reserves' => 1,
211
      'CAN_user_acquisition_order_receive' => 1,
212
      'CAN_user_stockrotation_manage_rotas' => 1,
213
      'CAN_user_updatecharges_payout' => 1,
214
      'CAN_user_tools_batch_upload_patron_images' => 1,
215
      'CAN_user_catalogue' => 1,
216
      'CAN_user_serials_delete_subscription' => 1,
217
      'CAN_user_stockrotation' => 1,
218
      'CAN_user_self_check' => 1,
219
      'CAN_user_tools_upload_local_cover_images' => 1,
220
      'CAN_user_tools_edit_notices' => 1,
221
      'CAN_user_acquisition_reopen_closed_invoices' => 1,
222
      'CAN_user_parameters_manage_mana' => 1,
223
      'CAN_user_tools_export_catalog' => 1,
224
      'CAN_user_parameters_manage_itemtypes' => 1,
225
      'CAN_user_parameters_manage_matching_rules' => 1,
226
      'CAN_user_suggestions_suggestions_manage' => 1,
227
      'CAN_user_parameters_manage_background_jobs' => 1,
228
      'CAN_user_tools_records_batchmod' => 1,
229
      'CAN_user_tools_items_batchmod_restricted' => 1,
230
      'CAN_user_parameters_manage_sysprefs' => 1,
231
      'CAN_user_tools_edit_calendar' => 1,
232
      'CAN_user_acquisition_merge_invoices' => 1,
233
      'CAN_user_tools_records_batchdel' => 1,
234
      'CAN_user_tools_edit_patrons' => 1,
235
      'CAN_user_borrowers' => 1,
236
      'CAN_user_updatecharges_remaining_permissions' => 1,
237
      'CAN_user_parameters_parameters_remaining_permissions' => 1,
238
      'CAN_user_parameters' => 1,
239
      'CAN_user_cash_management' => 1,
240
      'CAN_user_tools' => 1,
241
      'CAN_user_editcatalogue_edit_items' => 1,
242
      'CAN_user_tools_access_files' => 1,
243
      'CAN_user_parameters_manage_cash_registers' => 1,
244
      'CAN_user_plugins_report' => 1,
245
      'CAN_user_clubs_edit_templates' => 1,
246
      'CAN_user_serials_routing' => 1,
247
      'CAN_user_editcatalogue_delete_shared_macros' => 1,
248
      'CAN_user_parameters_manage_circ_rules' => 1,
249
      'CAN_user_ill' => 1,
250
      'CAN_user_lists_delete_public_lists' => 1,
251
      'CAN_user_parameters_manage_search_targets' => 1,
252
      'CAN_user_editcatalogue_fast_cataloging' => 1,
253
      'CAN_user_acquisition' => 1,
254
      'CAN_user_acquisition_edit_invoices' => 1,
255
      'CAN_user_acquisition_order_manage_all' => 1,
256
      'CAN_user_parameters_manage_transfers' => 1,
257
      'CAN_user_coursereserves' => 1,
258
      'CAN_user_serials_check_expiration' => 1,
259
      'CAN_user_updatecharges' => 1,
260
      'CAN_user_reports' => 1,
261
      'CAN_user_plugins_configure' => 1,
262
      'CAN_user_tools_schedule_tasks' => 1,
263
      'CAN_user_lists' => 1,
264
      'CAN_user_acquisition_delete_baskets' => 1,
265
      'CAN_user_acquisition_budget_add_del' => 1,
266
      'CAN_user_serials_superserials' => 1
267
    };
268
    is_deeply($authz,$expected,'Expected permissions generated for superlibrarian');
269
};

Return to bug 31389