1 | package LATMOS::Accounts::Web::Controller::Groups; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use base 'Catalyst::Controller'; |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | LATMOS::Accounts::Web::Controller::Groups - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | |
---|
20 | =head2 index |
---|
21 | |
---|
22 | =cut |
---|
23 | |
---|
24 | sub index : Private { |
---|
25 | my ( $self, $c ) = @_; |
---|
26 | |
---|
27 | $c->stash->{ofilter} = $c->model('AttrFilter', 'group'); |
---|
28 | $c->stash->{page}{title} = "Liste des groupes"; |
---|
29 | |
---|
30 | } |
---|
31 | |
---|
32 | sub default : LocalPath { |
---|
33 | my ( $self, $c, undef, $groupname, $subform ) = @_; |
---|
34 | |
---|
35 | my $base = $c->model('Accounts')->db; |
---|
36 | |
---|
37 | $c->stash->{page}{title} = "Groupe :: $groupname"; |
---|
38 | $c->stash->{groupname} = $groupname; |
---|
39 | $c->stash->{group} = $base->get_object('group', $groupname) or do { |
---|
40 | $c->forward('/no_object'); |
---|
41 | return; |
---|
42 | }; |
---|
43 | |
---|
44 | if ($c->req->param('make_active')) { |
---|
45 | $c->stash->{group}->set_c_fields('exported' => 1); |
---|
46 | $base->commit; |
---|
47 | } |
---|
48 | if ($c->req->param('make_inactive')) { |
---|
49 | $c->stash->{group}->set_c_fields('exported' => 0); |
---|
50 | $base->commit; |
---|
51 | } |
---|
52 | if ($c->req->param('delete')) { |
---|
53 | $base->delete_object('group', $groupname); |
---|
54 | $base->commit; |
---|
55 | $c->res->redirect('/groups'); |
---|
56 | } |
---|
57 | |
---|
58 | $c->stash->{subform} = $subform || ''; |
---|
59 | |
---|
60 | for ($subform || '') { |
---|
61 | # Exceptions... |
---|
62 | /^users$/ and do { |
---|
63 | $c->stash->{template} = 'groups/users.tt'; |
---|
64 | |
---|
65 | my %ingroup = map { $_ => 1 } @{ |
---|
66 | $c->stash->{group}->get_c_field('memberUID') || [] }; |
---|
67 | if ($c->req->param('adduser')) { |
---|
68 | $c->stash->{group}->set_c_fields('memberUID' => [ (keys %ingroup), $c->req->param('adduser') ]); |
---|
69 | $c->stash->{group}->base->commit; |
---|
70 | %ingroup = map { $_ => 1 } @{ $c->stash->{group}->get_c_field('memberUID') }; |
---|
71 | } elsif ($c->req->param('deluser')) { |
---|
72 | $c->stash->{group}->set_c_fields('memberUID', |
---|
73 | [ grep { $_ ne $c->req->param('deluser') } keys %ingroup ] |
---|
74 | ); |
---|
75 | $c->stash->{group}->base->commit; |
---|
76 | %ingroup = map { $_ => 1 } @{ $c->stash->{group}->get_c_field('memberUID') }; |
---|
77 | } |
---|
78 | |
---|
79 | $c->stash->{add_user_list} = [ grep { ! $ingroup{$_} } $base->list_objects('user') ]; |
---|
80 | last; |
---|
81 | }; |
---|
82 | /^dpmt$/ and do { |
---|
83 | $c->stash->{template} = 'groups/dpmt.tt'; |
---|
84 | my @filter = (); |
---|
85 | push(@filter, 'active=*') if (!$c->req->param('inactive')); |
---|
86 | push(@filter, 'mail=*') if ($c->req->param('mail')); |
---|
87 | push(@filter, 'company=' . $c->req->param('company')) if |
---|
88 | ($c->req->param('company')); |
---|
89 | $c->stash->{dpmt} = $groupname; |
---|
90 | $c->stash->{odpmt} = $c->stash->{group}; |
---|
91 | $c->stash->{user} = [ $base->search_objects('user', |
---|
92 | 'department=' . $c->stash->{dpmt}, |
---|
93 | @filter, |
---|
94 | ) ]; |
---|
95 | foreach my $u ($base->search_objects('user', |
---|
96 | 'memberOf=' . $c->stash->{dpmt}, |
---|
97 | @filter, |
---|
98 | )) { |
---|
99 | push(@{$c->{stash}->{guser}}, $u) |
---|
100 | unless(grep { $u eq $_ } @{$c->stash->{user}}); |
---|
101 | } |
---|
102 | last; |
---|
103 | }; |
---|
104 | |
---|
105 | $c->stash->{form} = $c->model('AttrForms', 'group' . $c->stash->{subform}, $c->stash->{group}); |
---|
106 | $c->stash->{form}->set_attrs; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | =head1 AUTHOR |
---|
111 | |
---|
112 | Thauvin Olivier |
---|
113 | |
---|
114 | =head1 LICENSE |
---|
115 | |
---|
116 | This library is free software, you can redistribute it and/or modify |
---|
117 | it under the same terms as Perl itself. |
---|
118 | |
---|
119 | =cut |
---|
120 | |
---|
121 | 1; |
---|