source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/Accounts.pm @ 1049

Last change on this file since 1049 was 1049, checked in by nanardon, 12 years ago
  • fix base allocation in web app
File size: 2.5 KB
Line 
1package LATMOS::Accounts::Web::Model::Accounts;
2
3use strict;
4use warnings;
5use FindBin;
6use lib "$FindBin::Bin/../../LATMOS-Accounts/lib";
7use base 'Catalyst::Model';
8use base 'LATMOS::Accounts';
9use LATMOS::Accounts::Log;
10
11la_set_log(
12    syslog => [],
13    console => LA_WARNING,
14);
15
16=head1 NAME
17
18LATMOS::Accounts::Web::Model::Accounts - Catalyst Model
19
20=head1 DESCRIPTION
21
22Catalyst Model.
23
24=cut
25
26sub new {
27    my ($class) = @_;
28    bless(LATMOS::Accounts
29        ->new(LATMOS::Accounts::Web->config->{config}),
30        $class);
31}
32
33sub accounts {
34    my ($self) = @_;
35    $self;
36}
37
38sub db {
39    my ($self) = @_;
40    $self->{_default_base} and return $self->{_default_base};
41    $self->{_default_base} = $self->base;
42    $self->{_default_base}->load or return;
43    $self->{_default_base}->wexported(1);
44    $self->{_default_base}
45}
46
47sub object_prev_next {
48    my ($self, $otype, $id) = @_;
49
50    my @list = $self->db->list_objects($otype);
51    my $prev;
52    while (@list && ($list[0] || '') ne $id) {
53        $prev = shift(@list);
54    }
55    return([ $prev, $list[1] ]);
56}
57
58sub object_navigate {
59    my ($self, $otype, $id, @filter) = @_;
60
61    my @list = $self->db->search_objects($otype, @filter);
62
63    my $i = 0;
64    for($i = 0; $i <= $#list; $i++) {
65        $list[$i] eq $id and last;
66    }
67
68    my %ptr = ();
69    $ptr{oprev} = $list[$i-1] if ($i > 0);
70    $ptr{'onext'} = $list[$i+1] if ($i < $#list);
71    $ptr{ofirst} = $list[0] if ($i > 1);
72    $ptr{'olast'} = $list[$#list] if ($i < $#list -1);
73    $ptr{list} = \@list;
74
75    return \%ptr;
76}
77
78# Such function must not be here, but in LATMOS::Accounts
79# But code does not allow this at time
80sub list_unowned_aliases {
81    my ($self, $filter) = @_;
82    my $db = $self->db;
83    my $sth = $db->db->prepare_cached(q{
84        select name, forward from aliases where
85        name not in (select name from "user")
86            and
87        forward not in (select array[name] from "user")
88    } . 
89    ($filter 
90        ? q{
91            and (lower(name) ILIKE $1 or
92            lower(array_to_string(forward, ',')) ILIKE $1)
93          }
94        : '')
95    );
96
97    $sth->execute($filter ? ('%' . $filter . '%') : ());
98    my %aliases;
99    while (my $res = $sth->fetchrow_hashref) {
100        $aliases{$res->{name}} = $res->{forward};
101    }
102    return \%aliases
103}
104
105sub sync_access {
106    my ($self) = @_;
107    $self->SUPER::sync_access
108}
109
110sub sync {
111    my ($self) = @_;
112    $self->default_synchro()
113}
114
115=head1 AUTHOR
116
117Thauvin Olivier
118
119=head1 LICENSE
120
121This library is free software, you can redistribute it and/or modify
122it under the same terms as Perl itself.
123
124=cut
125
1261;
Note: See TracBrowser for help on using the repository browser.