source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Logs.pm @ 1939

Last change on this file since 1939 was 1771, checked in by nanardon, 8 years ago

Add log search page

File size: 2.1 KB
Line 
1package LATMOS::Accounts::Web::Controller::Logs;
2use Moose;
3use namespace::autoclean;
4
5BEGIN { extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Controller::Logs - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19sub auto : Private {
20    my ( $self, $c ) = @_;
21    my $base = $c->model('Accounts')->db;
22
23    unless ($base->check_acl($c->stash->{user}, 'Log', 'r')) {
24        $c->go('/no_object');
25        return;
26    }
27
28    return 1;
29}
30
31=head2 index
32
33=cut
34
35sub index :Path :Args(0) {
36    my ( $self, $c ) = @_;
37
38    my $modifier = $c->req->param('modifier');
39    my $otype    = $c->req->param('otype');
40    my $object   = $c->req->param('object');
41    my $okey     = $c->req->param('okey');
42
43    my (@where, @values);
44    my $limit = 1000;
45
46    if ($okey) {
47        $c->stash->{logobject} = $c->model('Accounts')->db->getObjectFromOKey($okey);
48        push(@where, 'ikey = ?');
49        push(@values, $okey);
50        if (my $obj = $c->stash->{logobject}) {
51            $c->req->params->{otype} = $obj->type;
52            $c->req->params->{object} = $obj->id;
53        }
54    } elsif ($otype) {
55        push(@where, 'otype = ?');
56        push(@values, $otype);
57
58        if ($object) {
59            push(@where, '"name" = ?');
60            push(@values, $object);
61
62            $c->stash->{logobject} = $c->model('Accounts')->db->get_object($otype, $object);
63            $limit = undef;
64        }
65    }
66
67    if ($modifier) {
68        push(@where, '"username" =  ?');
69        push(@values, $modifier);
70    }
71
72    my $search = $c->model('Accounts')->db->db->prepare_cached(
73        sprintf(
74            q{select * from objectslogs %s order by logdate desc %s},
75            (@where ? 'where ' . join(' and ', @where) : ''),
76            ($limit ? "LIMIT $limit" : ''),
77        )
78    );
79
80    $search->execute(@values);
81
82    $c->stash->{logs} = $search->fetchall_arrayref({});
83}
84
85
86
87=encoding utf8
88
89=head1 AUTHOR
90
91Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,
92
93=head1 LICENSE
94
95This library is free software. You can redistribute it and/or modify
96it under the same terms as Perl itself.
97
98=cut
99
100__PACKAGE__->meta->make_immutable;
101
1021;
Note: See TracBrowser for help on using the repository browser.