1 | package LATMOS::Accounts::Web::Controller::Json::Tree; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | |
---|
5 | BEGIN { extends 'Catalyst::Controller'; } |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | LATMOS::Accounts::Web::Controller::Json::Expire - 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 :Path :Args(0) { |
---|
25 | my ( $self, $c ) = @_; |
---|
26 | |
---|
27 | my $base = $c->model('Accounts')->db; |
---|
28 | |
---|
29 | my %users = map { $_ => 1 } $base->search_objects('user', 'active=1', 'givenName=*'); |
---|
30 | my %dpmts = map { $_ => 1 } $base->search_objects('group', 'sutype=dpmt'); |
---|
31 | my %dpmtmanager = $base->attributes_summary_by_object('group', 'managedBy'); |
---|
32 | my %usermanager = $base->attributes_summary_by_object('user', 'managerContact'); |
---|
33 | my %dpmtuser = $base->attributes_summary_by_object('user', 'department'); |
---|
34 | |
---|
35 | my %nodes; |
---|
36 | my $data = { |
---|
37 | nodes => [], |
---|
38 | links => [], |
---|
39 | }; |
---|
40 | |
---|
41 | foreach my $user (keys %users) { |
---|
42 | my $ouser = $base->get_object('user', $user); |
---|
43 | push(@{ $data->{nodes} }, { |
---|
44 | "name" => $ouser->id, |
---|
45 | label => $ouser->get_attributes('displayName'), |
---|
46 | }); |
---|
47 | $nodes{$ouser->id} = $#{ $data->{nodes} }; |
---|
48 | } |
---|
49 | |
---|
50 | foreach my $user (keys %users) { |
---|
51 | my $manager = $usermanager{$user}->[0] || |
---|
52 | $dpmtmanager { $dpmtuser{ $user }->[0] }->[0] or next; |
---|
53 | |
---|
54 | if (!$nodes{$manager}) { |
---|
55 | my $ouser = $base->get_object('user', $manager); |
---|
56 | $nodes{$manager} = $nodes{$ouser->id}; |
---|
57 | } |
---|
58 | $nodes{$manager} or next; |
---|
59 | |
---|
60 | push(@{ $data->{links} }, |
---|
61 | { |
---|
62 | "source" => $nodes{$user}, |
---|
63 | "target" => $nodes{$manager}, |
---|
64 | } |
---|
65 | ); |
---|
66 | |
---|
67 | } |
---|
68 | |
---|
69 | $c->stash->{data} = $data; |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | =encoding utf8 |
---|
75 | |
---|
76 | =head1 AUTHOR |
---|
77 | |
---|
78 | Olivier Thauvin,Guyancourt - B1428,+33 1 80285052, |
---|
79 | |
---|
80 | =head1 LICENSE |
---|
81 | |
---|
82 | This library is free software. You can redistribute it and/or modify |
---|
83 | it under the same terms as Perl itself. |
---|
84 | |
---|
85 | =cut |
---|
86 | |
---|
87 | __PACKAGE__->meta->make_immutable; |
---|
88 | |
---|
89 | 1; |
---|