[123] | 1 | package LATMOS::Accounts::Web::Controller::Groups; |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
[884] | 5 | use base 'Catalyst::Controller'; |
---|
[123] | 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 ) = @_; |
---|
[240] | 26 | |
---|
[245] | 27 | $c->stash->{ofilter} = $c->model('AttrFilter', 'group'); |
---|
[861] | 28 | $c->stash->{page}{title} = "Liste des groupes"; |
---|
[226] | 29 | |
---|
[123] | 30 | } |
---|
| 31 | |
---|
[125] | 32 | sub default : LocalPath { |
---|
| 33 | my ( $self, $c, undef, $groupname, $subform ) = @_; |
---|
[123] | 34 | |
---|
[125] | 35 | my $base = $c->model('Accounts')->db; |
---|
| 36 | |
---|
[861] | 37 | $c->stash->{page}{title} = "Groupe :: $groupname"; |
---|
[125] | 38 | $c->stash->{groupname} = $groupname; |
---|
[718] | 39 | $c->stash->{group} = $base->get_object('group', $groupname) or do { |
---|
| 40 | $c->forward('/no_object'); |
---|
| 41 | return; |
---|
| 42 | }; |
---|
| 43 | |
---|
[1162] | 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 | |
---|
[125] | 58 | $c->stash->{subform} = $subform || ''; |
---|
| 59 | |
---|
[165] | 60 | for ($subform || '') { |
---|
[125] | 61 | # Exceptions... |
---|
[157] | 62 | /^users$/ and do { |
---|
| 63 | $c->stash->{template} = 'groups/users.tt'; |
---|
[217] | 64 | |
---|
| 65 | if ($c->req->param('adduser')) { |
---|
[1337] | 66 | $c->stash->{group}->addAttributeValue('memberUID', $c->req->param('adduser')); |
---|
[217] | 67 | $c->stash->{group}->base->commit; |
---|
| 68 | } elsif ($c->req->param('deluser')) { |
---|
[1337] | 69 | $c->stash->{group}->delAttributeValue('memberUID', $c->req->param('deluser')); |
---|
[217] | 70 | $c->stash->{group}->base->commit; |
---|
| 71 | } |
---|
| 72 | |
---|
[157] | 73 | last; |
---|
| 74 | }; |
---|
[861] | 75 | /^dpmt$/ and do { |
---|
| 76 | $c->stash->{template} = 'groups/dpmt.tt'; |
---|
| 77 | my @filter = (); |
---|
[1626] | 78 | push(@filter, 'active=1') if (!$c->req->param('inactive')); |
---|
[861] | 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 | }; |
---|
[125] | 97 | |
---|
| 98 | $c->stash->{form} = $c->model('AttrForms', 'group' . $c->stash->{subform}, $c->stash->{group}); |
---|
| 99 | $c->stash->{form}->set_attrs; |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
[123] | 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; |
---|