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

Last change on this file since 544 was 544, checked in by nanardon, 15 years ago
  • add prev/next link on object page (user and groups at time)
File size: 2.0 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->default_base;
42    $self->{_default_base}->wexported(1);
43    $self->{_default_base}
44}
45
46sub object_prev_next {
47    my ($self, $otype, $id) = @_;
48
49    my @list = $self->db->list_objects($otype);
50    my $prev;
51    while (@list && ($list[0] || '') ne $id) {
52        $prev = shift(@list);
53    }
54    return([ $prev, $list[1] ]);
55}
56
57# Such function must not be here, but in LATMOS::Accounts
58# But code does not allow this at time
59sub list_unowned_aliases {
60    my ($self, $filter) = @_;
61    my $db = $self->db;
62    my $sth = $db->db->prepare_cached(q{
63        select name, forward from aliases where
64        name not in (select name from "user")
65            and
66        forward not in (select array[name] from "user")
67    } . 
68    ($filter 
69        ? q{
70            and (lower(name) ILIKE $1 or
71            lower(array_to_string(forward, ',')) ILIKE $1)
72          }
73        : '')
74    );
75
76    $sth->execute($filter ? ('%' . $filter . '%') : ());
77    my %aliases;
78    while (my $res = $sth->fetchrow_hashref) {
79        $aliases{$res->{name}} = $res->{forward};
80    }
81    return \%aliases
82}
83
84sub sync_access {
85    my ($self) = @_;
86    $self->SUPER::sync_access
87}
88
89sub sync {
90    my ($self) = @_;
91    $self->default_synchro()
92}
93
94=head1 AUTHOR
95
96Thauvin Olivier
97
98=head1 LICENSE
99
100This library is free software, you can redistribute it and/or modify
101it under the same terms as Perl itself.
102
103=cut
104
1051;
Note: See TracBrowser for help on using the repository browser.