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

Last change on this file since 1738 was 1334, checked in by nanardon, 9 years ago

Add jquery ui menu instead flat list

File size: 3.4 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
26=head1 FUNCTIONS
27
28=cut
29
30sub new {
31    my ($class) = @_;
32    bless(LATMOS::Accounts
33        ->new(LATMOS::Accounts::Web->config->{config}),
34        $class);
35}
36
37sub ACCEPT_CONTEXT {
38    my ($self, $c, $form, $object, $base) = @_;
39    $self->{c} = $c;
40    $self;
41}
42
43sub accounts {
44    my ($self) = @_;
45    $self;
46}
47
48sub db {
49    my ($self) = @_;
50    $self->{_default_base} and return $self->{_default_base};
51    $self->{_default_base} = $self->base;
52    $self->{_default_base}->load or return;
53    $self->{_default_base}->wexported(1);
54    $self->{_default_base}
55}
56
57=head2 obj_to_label($ref)
58
59Return a proper label to display for each object
60
61=cut
62
63sub obj_to_label {
64    my ($self, $ref) = @_;
65    my $uri_part = {
66        user => 'Utilisateurs',
67        group => 'Groupes',
68        nethost => 'HÃŽtes réseaux',
69        netzone => 'Zones réseau',
70        site => 'Sites',
71        aliases => 'Alias',
72        service => 'Services',
73    }->{$ref};
74}
75
76sub obj_to_uri {
77    my ($self, $ref, $id) = @_;
78    my $uri_part = {
79        user => 'users',
80        group => 'groups',
81        nethost => 'nethosts',
82        netzone => 'netzones',
83        site => 'sites',
84        aliases => 'aliases',
85        service => 'services',
86    }->{$ref} || $ref;
87
88    return $self->{c}->uri_for('/', $uri_part, ($id ? $id : ()));
89}
90
91sub object_prev_next {
92    my ($self, $otype, $id) = @_;
93
94    my @list = $self->db->list_objects($otype);
95    my $prev;
96    while (@list && ($list[0] || '') ne $id) {
97        $prev = shift(@list);
98    }
99    return([ $prev, $list[1] ]);
100}
101
102sub object_navigate {
103    my ($self, $otype, $id, @filter) = @_;
104
105    my @list = $self->db->search_objects($otype, @filter);
106
107    my $i = 0;
108    for($i = 0; $i <= $#list; $i++) {
109        $list[$i] eq $id and last;
110    }
111
112    my %ptr = ();
113    $ptr{oprev} = $list[$i-1] if ($i > 0);
114    $ptr{'onext'} = $list[$i+1] if ($i < $#list);
115    $ptr{ofirst} = $list[0] if ($i > 1);
116    $ptr{'olast'} = $list[$#list] if ($i < $#list -1);
117    $ptr{list} = \@list;
118
119    return \%ptr;
120}
121
122# Such function must not be here, but in LATMOS::Accounts
123# But code does not allow this at time
124sub list_unowned_aliases {
125    my ($self, $filter) = @_;
126    my $db = $self->db;
127    my $sth = $db->db->prepare_cached(q{
128        select name, forward from aliases where
129        name not in (select name from "user")
130            and
131        forward not in (select array[name] from "user")
132    } . 
133    ($filter 
134        ? q{
135            and (lower(name) ILIKE $1 or
136            lower(array_to_string(forward, ',')) ILIKE $1)
137          }
138        : '')
139    );
140
141    $sth->execute($filter ? ('%' . $filter . '%') : ());
142    my %aliases;
143    while (my $res = $sth->fetchrow_hashref) {
144        $aliases{$res->{name}} = $res->{forward};
145    }
146    return \%aliases
147}
148
149sub sync_access {
150    my ($self) = @_;
151    $self->SUPER::sync_access
152}
153
154sub sync {
155    my ($self) = @_;
156    $self->default_synchro()
157}
158
159=head1 AUTHOR
160
161Thauvin Olivier
162
163=head1 LICENSE
164
165This library is free software, you can redistribute it and/or modify
166it under the same terms as Perl itself.
167
168=cut
169
1701;
Note: See TracBrowser for help on using the repository browser.