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 | if ($c->req->param('adduser')) { |
---|
66 | $c->stash->{group}->addAttributeValue('memberUID', $c->req->param('adduser')); |
---|
67 | $c->stash->{group}->base->commit; |
---|
68 | } elsif ($c->req->param('deluser')) { |
---|
69 | $c->stash->{group}->delAttributeValue('memberUID', $c->req->param('deluser')); |
---|
70 | $c->stash->{group}->base->commit; |
---|
71 | } |
---|
72 | |
---|
73 | last; |
---|
74 | }; |
---|
75 | /^dpmt$/ and do { |
---|
76 | $c->stash->{template} = 'groups/dpmt.tt'; |
---|
77 | my @filter = (); |
---|
78 | push(@filter, 'active=*') if (!$c->req->param('inactive')); |
---|
79 | push(@filter, 'mail=*') if ($c->req->param('mail')); |
---|
80 | push(@filter, 'company=' . $c->req->param('company')) if |
---|
81 | ($c->req->param('company')); |
---|
82 | $c->stash->{dpmt} = $groupname; |
---|
83 | $c->stash->{odpmt} = $c->stash->{group}; |
---|
84 | $c->stash->{user} = [ $base->search_objects('user', |
---|
85 | 'department=' . $c->stash->{dpmt}, |
---|
86 | @filter, |
---|
87 | ) ]; |
---|
88 | foreach my $u ($base->search_objects('user', |
---|
89 | 'memberOf=' . $c->stash->{dpmt}, |
---|
90 | @filter, |
---|
91 | )) { |
---|
92 | push(@{$c->{stash}->{guser}}, $u) |
---|
93 | unless(grep { $u eq $_ } @{$c->stash->{user}}); |
---|
94 | } |
---|
95 | last; |
---|
96 | }; |
---|
97 | |
---|
98 | $c->stash->{form} = $c->model('AttrForms', 'group' . $c->stash->{subform}, $c->stash->{group}); |
---|
99 | $c->stash->{form}->set_attrs; |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | =head1 AUTHOR |
---|
104 | |
---|
105 | Thauvin Olivier |
---|
106 | |
---|
107 | =head1 LICENSE |
---|
108 | |
---|
109 | This library is free software, you can redistribute it and/or modify |
---|
110 | it under the same terms as Perl itself. |
---|
111 | |
---|
112 | =cut |
---|
113 | |
---|
114 | 1; |
---|