1 | package LATMOS::Accounts::Web::Controller::Logs; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | |
---|
5 | BEGIN { extends 'Catalyst::Controller'; } |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | LATMOS::Accounts::Web::Controller::Logs - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | sub 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 | |
---|
35 | sub 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 | |
---|
91 | Olivier Thauvin,Guyancourt - B1428,+33 1 80285052, |
---|
92 | |
---|
93 | =head1 LICENSE |
---|
94 | |
---|
95 | This library is free software. You can redistribute it and/or modify |
---|
96 | it under the same terms as Perl itself. |
---|
97 | |
---|
98 | =cut |
---|
99 | |
---|
100 | __PACKAGE__->meta->make_immutable; |
---|
101 | |
---|
102 | 1; |
---|