source: trunk/LATMOS-Accounts/bin/la-sql-edit-form @ 1806

Last change on this file since 1806 was 1044, checked in by nanardon, 12 years ago

Kill redundant LATMOS::Account::default_base()

Use $LA->base(undef) to get default base instead

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8
9=head1 NAME
10
11    la-sql-edit-form - Tools to edit forms (accreq)
12
13=head1 SYNOPSIS
14
15    la-sql-edit-form formid
16
17=cut
18
19GetOptions(
20    'c|config=s' => \my $config,
21    'b|base=s'   => \my $base,
22    'f=s'        => \my $inputfile,
23    'help'       => sub { pod2usage(0) },
24) or pod2usage();
25
26=head1 OPTIONS
27
28=over 4
29
30=item -c|--config configdir
31
32Use this configuration directory instead of the default one.
33
34=item -b|--base basename
35
36Query this specific base instead of the default one.
37
38=item -f FILE
39
40Use this file to get attributes (- use stdin)
41If this option is not present, you'll have a file opened in your prefered editor to edit.
42
43=back
44
45=cut
46
47if (!$ARGV[0]) { warn "You must specify 'obj_id', aborting\n"; pod2usage(); }
48
49my $LA = LATMOS::Accounts->new($config, noacl => 1);
50my $labase = $LA->base($base);
51$labase && $labase->load or die "Cannot load base";
52$labase->wexported(1);
53
54sub input_from_handle {
55    my ($obj, $fh) = @_;
56    my $yaml = join('', <$fh>);
57    my $res = $obj->set_c_fields(form => $yaml);
58    if($res) {
59        print "Changes applied\n";
60        $labase->commit;
61        $LA->call_batch_sync;
62    }
63    return
64    $res ? 1 : 0;
65}
66
67if (my $ouid = shift(@ARGV)) {
68    my $obj = $labase->get_object('accreq', $ouid) or do {
69        die "Object accreq $ouid not found\n";
70    };
71
72    if ($inputfile) {
73        my $handle;
74        if ($inputfile eq '-') {
75            $handle = *STDIN;
76        } else {
77            open($handle, '<', $inputfile) or die
78                "Cannot open input file $@\n";
79        }
80        my $res = input_from_handle($obj, $handle);
81        close($handle);
82        exit(!$res);
83    } else {
84        exit ! LATMOS::Accounts::Utils::dump_read_temp_file(
85            sub {
86                my ($fh) = @_;
87                print $fh $obj->get_attributes('form');
88            },
89            sub {
90                my ($fh) = @_;
91                return input_from_handle($obj, $fh);
92            }
93        );
94    }
95} else {
96    pod2usage();
97}
98
99=head1 FORM FORMAT
100
101=head2 EXAMPLE
102
103    ---
104    attrs:
105      - formtype: textarea
106        label: Please explain why your name must changed
107        name: reason
108      - sn
109      - givenName
110    description: Change my name
111    notifyMail: sysadmin@nomail
112
113=head2 SYNTAX
114
115The form must be describe in YAML format (L<http://en.wikipedia.org/wiki/YAML>).
116
117=head2 OPTIONS
118
119=over 4
120
121=item description
122
123A short description about this form
124
125=item notifyMail
126
127If set a mail is sent to this address when someone submit the form
128
129=item attrs
130
131The list of attributes the form must contains. See below.
132
133=back
134
135=head2 ATTRIBUTES DESCRIPTION
136
137Each attributes is either:
138
139=over 4
140
141=item a name
142
143Just the name of an object's attribute the is related (C<sn>, C<givenName> for user objects)
144
145=item an option list
146
147A list of options describing how the attribute must appear:
148
149=over 4
150
151=item name
152
153The internal short name of attribute
154
155=item label
156
157The text displayed to user
158
159=item formtype
160
161The type of field to diaply (text, textarea, date, checkbox or list)
162
163=back
164
165=back
166
167=cut
Note: See TracBrowser for help on using the repository browser.