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

(-)a/Koha/Patron.pm (-3 / +3 lines)
Lines 3600-3606 my $flags = $patron->permissions Link Here
3600
Returns a hashref of the patron's permissions. This method has the same
3600
Returns a hashref of the patron's permissions. This method has the same
3601
return structure as C4::Auth::getuserflags for consistency.
3601
return structure as C4::Auth::getuserflags for consistency.
3602
3602
3603
Exemple return structure:
3603
Example return structure:
3604
{
3604
{
3605
  "superlibrarian": 0,
3605
  "superlibrarian": 0,
3606
  "permissions": 0,
3606
  "permissions": 0,
Lines 3633-3640 sub permissions { Link Here
3633
3633
3634
    # Get userFlags using ORM
3634
    # Get userFlags using ORM
3635
3635
3636
    my $schema = Koha::Database->schema;
3636
    my $schema        = Koha::Database->schema;
3637
    my @userflags = $schema->resultset('Userflag')->search( {}, { order_by => 'bit'})->all;
3637
    my @userflags     = $schema->resultset('Userflag')->search( {}, { order_by => 'bit' } )->all;
3638
    my %userflags_map = map { $_->bit => $_->flag } @userflags;
3638
    my %userflags_map = map { $_->bit => $_->flag } @userflags;
3639
3639
3640
    my $flags = $self->flags // 0;
3640
    my $flags = $self->flags // 0;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt (-2 / +48 lines)
Lines 406-416 Link Here
406
                                            >
406
                                            >
407
                                        </div>
407
                                        </div>
408
                                    [% ELSE %]
408
                                    [% ELSE %]
409
                                        <div class="loginfo" id="loginfo[% loopro.action_id | html %]"> [% loopro.info | html %] </div>
409
                                        <div class="loginfo" id="loginfo[% loopro.action_id | html %]">
410
                                            [% IF ( loopro.module == 'MEMBERS' ) %]
411
                                                <pre>[% loopro.info | html %]</pre>
412
                                            [% ELSE %]
413
                                                [% loopro.info | html %]
414
                                            [% END %]
415
                                        </div>
410
                                    [% END %]
416
                                    [% END %]
411
                                </td>
417
                                </td>
412
                                <td>[% PROCESS translate_log_interface log_interface=loopro.interface %]</td>
418
                                <td>[% PROCESS translate_log_interface log_interface=loopro.interface %]</td>
413
                                <td>[% loopro.diff | html %]</td>
419
                                <td>
420
                                    [% IF ( loopro.module == 'MEMBERS' ) %]
421
                                        <pre class="permissions-diff">[% loopro.diff | html %]</pre>
422
                                    [% ELSE %]
423
                                        [% loopro.diff | html %]
424
                                    [% END %]
425
                                </td>
414
                            </tr>
426
                            </tr>
415
                        [% END %]
427
                        [% END %]
416
                    </tbody>
428
                    </tbody>
Lines 474-479 Link Here
474
    <script>
486
    <script>
475
        var table_settings = [% TablesSettings.GetTableSettings('tools', 'logviewer', 'logst', 'json') | $raw %];
487
        var table_settings = [% TablesSettings.GetTableSettings('tools', 'logviewer', 'logst', 'json') | $raw %];
476
        var CAN_user_parameters_manage_sysprefs = "[% CAN_user_parameters_manage_sysprefs | html %]";
488
        var CAN_user_parameters_manage_sysprefs = "[% CAN_user_parameters_manage_sysprefs | html %]";
489
        $(document).ready(function() {
490
            $("pre.permissions-diff").each(function() {
491
                let text = $(this).html();
492
                let dCounter = 0;
493
494
                let added_label = _("Added ");
495
                let removed_label =  _("Removed ");
496
497
                let all_label = _("-- All --");
498
499
500
                text = text.replace(/^(\s{0,8}"[^"]+"\s*:\s*)\{\s*"A"\s*:\s*1\s*\}/gm, '$1<span style="color:#2ea44f; font-weight:bold;">' +  added_label + all_label + '</span>');
501
                text = text.replace(/^(\s{0,8}"[^"]+"\s*:\s*)\{\s*"R"\s*:\s*1\s*\}/gm, '$1<span style="color:#cf222e; font-weight:bold;">' +  removed_label + all_label + '</span>');
502
503
                text = text.replace(/^(\s*"[^"]+"\s*:\s*)\{\s*"A"\s*:\s*1\s*\}/gm, '$1<span style="color:#2ea44f; font-weight:bold;">' + added_label + '✅</span>');
504
                text = text.replace(/^(\s*"[^"]+"\s*:\s*)\{\s*"R"\s*:\s*1\s*\}/gm, '$1<span style="color:#cf222e; font-weight:bold;">' + removed_label + '❌</span>');
505
506
                text = text.replace(/"D"/g, function() {
507
                    dCounter++;
508
                    var label = (dCounter === 1) ? _("Modifications") : "&nbsp;↳";
509
                    var color = (dCounter === 1) ? "#0056b3" : "#6e7781";
510
                    return '<span style="color:' + color + '; font-weight:bold;">' + label + '</span>';
511
                });
512
513
                text = text.replace(/"A"/g, '<span style="color:#2ea44f; font-weight:bold;">' + _("Added ") + '✅' + '</span>');
514
                text = text.replace(/"R"/g, '<span style="color:#cf222e; font-weight:bold;">' + _("Removed ") + '❌' + '</span>');
515
                text = text.replace(/"O"/g, '<span style="color:#6e7781; font-weight:bold;">' + _("Old value") + '</span>');
516
                text = text.replace(/"N"/g, '<span style="color:#0969da; font-weight:bold;">' + _("New value") + '</span>');
517
518
                text = text.replace(/,\s*$/gm, "");
519
520
                $(this).html(text);
521
            });
522
        });
477
    </script>
523
    </script>
478
    [% Asset.js("js/viewlog.js") | $raw %]
524
    [% Asset.js("js/viewlog.js") | $raw %]
479
[% END %]
525
[% END %]
(-)a/t/db_dependent/Koha/Patron.t (-26 / +34 lines)
Lines 2386-2406 subtest 'alert_subscriptions tests' => sub { Link Here
2386
2386
2387
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2387
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2388
2388
2389
    my $subscription1 = $builder->build_object( {
2389
    my $subscription1 = $builder->build_object(
2390
        class => 'Koha::Subscriptions',
2390
        {
2391
        value => {
2391
            class => 'Koha::Subscriptions',
2392
            librarian => $patron->borrowernumber,
2392
            value => {
2393
                librarian => $patron->borrowernumber,
2394
            }
2393
        }
2395
        }
2394
    });
2396
    );
2395
    $subscription1->add_subscriber($patron);
2397
    $subscription1->add_subscriber($patron);
2396
2398
2397
2399
    my $subscription2 = $builder->build_object(
2398
    my $subscription2 = $builder->build_object( {
2400
        {
2399
        class => 'Koha::Subscriptions',
2401
            class => 'Koha::Subscriptions',
2400
        value => {
2402
            value => {
2401
            librarian => $patron->borrowernumber,
2403
                librarian => $patron->borrowernumber,
2404
            }
2402
        }
2405
        }
2403
    });
2406
    );
2404
    $subscription2->add_subscriber($patron);
2407
    $subscription2->add_subscriber($patron);
2405
2408
2406
    my @subscriptions = $patron->alert_subscriptions->as_list;
2409
    my @subscriptions = $patron->alert_subscriptions->as_list;
Lines 2439-2454 subtest 'update_lastseen tests' => sub { Link Here
2439
    my $mock_cache = Test::MockModule->new('Koha::Cache');
2442
    my $mock_cache = Test::MockModule->new('Koha::Cache');
2440
    my %fake_cache;
2443
    my %fake_cache;
2441
2444
2442
    $mock_cache->mock('set_in_cache', sub {
2445
    $mock_cache->mock(
2443
        my ( $self, $key, $value ) = @_;
2446
        'set_in_cache',
2444
        $fake_cache{$key} = $value;
2447
        sub {
2445
        return;
2448
            my ( $self, $key, $value ) = @_;
2446
    });
2449
            $fake_cache{$key} = $value;
2450
            return;
2451
        }
2452
    );
2447
2453
2448
    $mock_cache->mock('get_from_cache', sub {
2454
    $mock_cache->mock(
2449
        my ( $self, $key ) = @_;
2455
        'get_from_cache',
2450
        return $fake_cache{$key};
2456
        sub {
2451
    });
2457
            my ( $self, $key ) = @_;
2458
            return $fake_cache{$key};
2459
        }
2460
    );
2452
2461
2453
    my $cache = Koha::Caches->get_instance();
2462
    my $cache = Koha::Caches->get_instance();
2454
2463
Lines 2457-2468 subtest 'update_lastseen tests' => sub { Link Here
2457
        'creation,login,connection,check_in,check_out,renewal,hold,article'
2466
        'creation,login,connection,check_in,check_out,renewal,hold,article'
2458
    );
2467
    );
2459
2468
2460
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2469
    my $patron      = $builder->build_object( { class => 'Koha::Patrons' } );
2461
    my $patron_info = $patron->unblessed;
2470
    my $patron_info = $patron->unblessed;
2462
    delete $patron_info->{borrowernumber};
2471
    delete $patron_info->{borrowernumber};
2463
    $patron->delete();
2472
    $patron->delete();
2464
    $patron = Koha::Patron->new($patron_info)->store();
2473
    $patron = Koha::Patron->new($patron_info)->store();
2465
    $patron->update_lastseen({ activity => 'creation' });
2474
    $patron->update_lastseen( { activity => 'creation' } );
2466
    $patron->discard_changes();
2475
    $patron->discard_changes();
2467
2476
2468
    my $now   = dt_from_string();
2477
    my $now   = dt_from_string();
Lines 2486-2505 subtest 'update_lastseen tests' => sub { Link Here
2486
2495
2487
    $patron_no_trigger->lastseen(undef)->store();
2496
    $patron_no_trigger->lastseen(undef)->store();
2488
2497
2489
    $patron_no_trigger->update_lastseen({ activity => 'login' });
2498
    $patron_no_trigger->update_lastseen( { activity => 'login' } );
2490
    $patron_no_trigger->discard_changes();
2499
    $patron_no_trigger->discard_changes();
2491
2500
2492
    is( $patron_no_trigger->lastseen, undef,
2501
    is(
2502
        $patron_no_trigger->lastseen, undef,
2493
        'Patron should have not last seen when newly created if trigger not set'
2503
        'Patron should have not last seen when newly created if trigger not set'
2494
    );
2504
    );
2495
2505
2496
2497
    t::lib::Mocks::mock_preference(
2506
    t::lib::Mocks::mock_preference(
2498
        'TrackLastPatronActivityTriggers',
2507
        'TrackLastPatronActivityTriggers',
2499
        'login,connection,check_in,check_out,renewal,hold,article'
2508
        'login,connection,check_in,check_out,renewal,hold,article'
2500
    );
2509
    );
2501
2510
2502
2503
    $now = dt_from_string();
2511
    $now = dt_from_string();
2504
    Time::Fake->offset( $now->epoch );
2512
    Time::Fake->offset( $now->epoch );
2505
2513
(-)a/tools/viewlog.pl (-1 / +15 lines)
Lines 234-239 if ($do_it) { Link Here
234
                }
234
                }
235
            }
235
            }
236
        }
236
        }
237
238
        if ( $result->{module} eq 'MEMBERS' ) {
239
            my $json_engine = JSON->new->utf8->canonical(1)->pretty(1);
240
241
            if ( $result->{info} && $result->{info} =~ /^[{\[]/ ) {
242
                my $perl_info = $json_engine->decode( $result->{info} );
243
                $result->{info} = $json_engine->encode($perl_info);
244
            }
245
246
            if ( $result->{diff} && $result->{diff} =~ /^[{\[]/ ) {
247
                my $perl_diff = $json_engine->decode( $result->{diff} );
248
                $result->{diff} = $json_engine->encode($perl_diff);
249
            }
250
        }
251
237
        push @data, $result;
252
        push @data, $result;
238
    }
253
    }
239
    if ( $output eq "screen" ) {
254
    if ( $output eq "screen" ) {
240
- 

Return to bug 20956