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

(-)a/C4/Log.pm (+2 lines)
Lines 140-145 sub logaction { Link Here
140
    $diff //= encode_json( diff( $original, $updated, noU => 1 ) )
140
    $diff //= encode_json( diff( $original, $updated, noU => 1 ) )
141
        if $original && ref $updated eq 'HASH';
141
        if $original && ref $updated eq 'HASH';
142
142
143
    $infos = encode_json($infos) if ( ref $infos eq 'HASH' );
144
143
    Koha::ActionLog->new(
145
    Koha::ActionLog->new(
144
        {
146
        {
145
            timestamp => \'NOW()',
147
            timestamp => \'NOW()',
(-)a/members/member-flags.pl (-3 / +42 lines)
Lines 10-15 use CGI qw ( -utf8 ); Link Here
10
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
10
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
11
use C4::Auth   qw( get_template_and_user get_all_subpermissions get_user_subpermissions );
11
use C4::Auth   qw( get_template_and_user get_all_subpermissions get_user_subpermissions );
12
use C4::Context;
12
use C4::Context;
13
use C4::Log qw( logaction );
13
14
14
use Koha::Patron::Categories;
15
use Koha::Patron::Categories;
15
use Koha::Patrons;
16
use Koha::Patrons;
Lines 69-84 if ( $op eq 'cud-newflags' ) { Link Here
69
70
70
    # construct flags
71
    # construct flags
71
    my $module_flags = 0;
72
    my $module_flags = 0;
72
    my $sth          = $dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
73
    my $sth          = $dbh->prepare("SELECT bit,flag,flagdesc FROM userflags ORDER BY bit");
73
    $sth->execute();
74
    $sth->execute();
74
    while ( my ( $bit, $flag ) = $sth->fetchrow_array ) {
75
    my %userflags;
76
    while ( my ( $bit, $flag, $flagdesc ) = $sth->fetchrow_array ) {
75
        if ( exists $all_module_perms{$flag} ) {
77
        if ( exists $all_module_perms{$flag} ) {
76
            $module_flags += 2**$bit;
78
            $module_flags += 2**$bit;
77
        }
79
        }
80
        $userflags{$bit} = [ $flag, $flagdesc ];
78
    }
81
    }
79
82
80
    $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
83
    $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
81
    my $old_flags = $patron->flags // 0;
84
    my $old_flags          = $patron->flags // 0;
85
    my %permissions_before = get_permissions( \%userflags, $old_flags );
82
    if ( ( $old_flags == 1 || $module_flags == 1 )
86
    if ( ( $old_flags == 1 || $module_flags == 1 )
83
        && $old_flags != $module_flags )
87
        && $old_flags != $module_flags )
84
    {
88
    {
Lines 105-110 if ( $op eq 'cud-newflags' ) { Link Here
105
        }
109
        }
106
    }
110
    }
107
111
112
    my %permissions_after = get_permissions( \%userflags, $module_flags );
113
    logaction( 'MEMBERS', 'MODIFY', $member, \%permissions_after, undef, \%permissions_before );
108
    print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
114
    print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
109
} else {
115
} else {
110
116
Lines 200-202 if ( $op eq 'cud-newflags' ) { Link Here
200
    output_html_with_http_headers $input, $cookie, $template->output;
206
    output_html_with_http_headers $input, $cookie, $template->output;
201
207
202
}
208
}
209
210
sub get_permissions {
211
    my ( $userflags, $old_flags ) = @_;
212
213
    my %active_flag = decode_flags( $userflags, $old_flags );
214
    my $user_perms  = get_user_subpermissions( $bor->{'userid'} );
215
    my %permissions;
216
    my $dbh = C4::Context->dbh();
217
    my $sth = $dbh->prepare("SELECT code, description FROM permissions");
218
    $sth->execute();
219
220
    while ( my ( $code, $desc ) = $sth->fetchrow_array ) {
221
        $permissions{$code} = $desc;
222
    }
223
    for my $module ( keys %$user_perms ) {
224
        for my $code ( keys %{ $user_perms->{$module} } ) {
225
            $active_flag{$code} = $permissions{$code};
226
        }
227
    }
228
    return %active_flag;
229
}
230
231
sub decode_flags {
232
    my ( $userflags, $flags ) = @_;
233
    my %active_flags;
234
    foreach my $bit ( keys %$userflags ) {
235
        if ( $flags & ( 2**$bit ) ) {
236
            my ( $flag, $desc ) = @{ $userflags->{$bit} };
237
            $active_flags{$flag} = $desc;
238
        }
239
    }
240
    return %active_flags;
241
}
(-)a/t/db_dependent/Log.t (-2 / +20 lines)
Lines 16-23 Link Here
16
16
17
use Modern::Perl;
17
use Modern::Perl;
18
use Data::Dumper qw( Dumper );
18
use Data::Dumper qw( Dumper );
19
19
use Test::NoWarnings;
20
use Test::NoWarnings;
20
use Test::More tests => 8;
21
use Test::More tests => 9;
21
22
22
use C4::Context;
23
use C4::Context;
23
use C4::Log  qw( logaction cronlogaction );
24
use C4::Log  qw( logaction cronlogaction );
Lines 221-226 subtest 'Test storing diff of objects' => sub { Link Here
221
    is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' );
222
    is( $diff->{D}->{barcode}->{N}, '_MY_TEST_BARCODE_', 'Diff of changes logged successfully' );
222
};
223
};
223
224
225
subtest 'Test storing diff of hashrefs' => sub {
226
    plan tests => 1;
227
    my $original_data = {
228
        firstname => 'John',
229
        surname   => 'Doe'
230
    };
231
    my $edited_data = {
232
        firstname => 'Johnny',
233
        surname   => 'Doe'
234
    };
235
236
    logaction( 'MY_MODULE', 'TEST', 12345, $edited_data, 'staff', $original_data );
237
238
    my $logs = Koha::ActionLogs->search( { module => 'MY_MODULE', action => 'TEST' } )->next;
239
    my $diff = decode_json( $logs->diff );
240
    is( $diff->{D}->{firstname}->{N}, 'Johnny', 'Diff of changes logged successfully' );
241
};
242
224
subtest 'Test storing original version of an item' => sub {
243
subtest 'Test storing original version of an item' => sub {
225
    plan tests => 1;
244
    plan tests => 1;
226
245
227
- 

Return to bug 20956