source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Remote/Obj.pm @ 1882

Last change on this file since 1882 was 1882, checked in by nanardon, 7 years ago

Dont return oalias by default in remote

File size: 1.7 KB
Line 
1package LATMOS::Accounts::Web::Controller::Remote::Obj;
2use Moose;
3use namespace::autoclean;
4
5BEGIN { extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9LATMOS::Accounts::Web::Controller::Remote::Obj - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub index :Path :Args(0) {
25    my ( $self, $c ) = @_;
26
27    $c->stash->{data} = [
28        $c->model('Accounts')->db->list_supported_objects
29    ];
30}
31
32sub List :Path :Args(1) {
33    my ($self, $c, $otype) = @_;
34
35    if (!$c->model('Accounts')->db->is_supported_object($otype)) {
36        $c->res->status('404');
37        return;
38    }
39
40    $c->stash->{data} = [
41        $c->req->param('oalias')
42            ? $c->model('Accounts')->db->listRealObjects($otype)
43            : $c->model('Accounts')->db->list_objects($otype)
44    ]
45}
46
47sub Show :Path :Args(2) {
48    my ($self, $c, $otype, $id) = @_;
49
50    my $base = $c->model('Accounts')->db;
51
52    if (!$base->is_supported_object($otype)) {
53        $c->res->status('404');
54        return;
55    }
56
57    my $obj = $base->get_object($otype, $id);
58
59    if (!$obj) {
60        $c->res->status('404');
61        return;
62    } 
63
64    foreach my $attr (sort { $a cmp $b } $base->list_canonical_fields($otype, 'r')) {
65        my $oattr = $obj->attribute($attr) or next;
66        if ($oattr->hidden) { next; }
67        my $val = $obj->get_c_field($attr);
68        $c->stash->{data}{$attr} = $val if ($val);
69    } 
70}
71
72=encoding utf8
73
74=head1 AUTHOR
75
76Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,
77
78=head1 LICENSE
79
80This library is free software. You can redistribute it and/or modify
81it under the same terms as Perl itself.
82
83=cut
84
85__PACKAGE__->meta->make_immutable;
86
871;
Note: See TracBrowser for help on using the repository browser.