Upgrade to 4.2.2
[usit-rt.git] / share / html / REST / 1.0 / Forms / queue / default
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
320f0092 5%# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
84fb5b46
MKG
6%# <sales@bestpractical.com>
7%#
8%# (Except where explicitly superseded by other copyright notices)
9%#
10%#
11%# LICENSE:
12%#
13%# This work is made available to you under the terms of Version 2 of
14%# the GNU General Public License. A copy of that license should have
15%# been provided with this software, but in any event can be snarfed
16%# from www.gnu.org.
17%#
18%# This work is distributed in the hope that it will be useful, but
19%# WITHOUT ANY WARRANTY; without even the implied warranty of
20%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21%# General Public License for more details.
22%#
23%# You should have received a copy of the GNU General Public License
24%# along with this program; if not, write to the Free Software
25%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26%# 02110-1301 or visit their web page on the internet at
27%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28%#
29%#
30%# CONTRIBUTION SUBMISSION POLICY:
31%#
32%# (The following paragraph is not intended to limit the rights granted
33%# to you to modify and distribute this software under the terms of
34%# the GNU General Public License and is only of importance to you if
35%# you choose to contribute your changes and enhancements to the
36%# community by submitting them to Best Practical Solutions, LLC.)
37%#
38%# By intentionally submitting any modifications, corrections or
39%# derivatives to this work, or any other work intended for use with
40%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41%# you are the copyright holder for those contributions and you grant
42%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43%# royalty-free, perpetual, license to use, copy, create derivative
44%# works based on those contributions, and sublicense and distribute
45%# those contributions and any derivatives thereof.
46%#
47%# END BPS TAGGED BLOCK }}}
48%# REST/1.0/Forms/queue/default
49%#
50<%ARGS>
51$id
52$format => 's'
53$fields => undef # these are the fields passed to the rt "-f" flag.
54$changes => {}
55</%ARGS>
56<%perl>
57my @comments;
58my ($c, $o, $k, $e) = ("", [], {}, 0);
59my %data = %$changes;
60my $queue = RT::Queue->new($session{CurrentUser});
320f0092
MKG
61
62my @fields =
63 qw(Name Description CorrespondAddress CommentAddress InitialPriority FinalPriority DefaultDueIn Disabled);
64if ( $fields && %$fields ) {
65 @fields = grep { exists $fields->{ lc $_ } } @fields;
66}
67
84fb5b46
MKG
68my %fields = map { lc $_ => $_ } @fields;
69
70if ($id ne 'new') {
71 $queue->Load($id);
72 if (!$queue->Id) {
73 return [ "# Queue $id does not exist.", [], {}, 1 ];
74 }
75}
76else {
77 if (keys %data == 0) {
78 return [
79 "# Required: Name",
80 [ "id", @fields ],
81 {
82 id => 'queue/new',
83 Name => '<queue name>',
84 Description => "",
85 CommentAddress => "",
86 CorrespondAddress => "",
87 InitialPriority => "",
88 FinalPriority => "",
89 DefaultDueIn => "",
90 },
91 0
92 ];
93 }
94 else {
95 my %v;
96 my %create = %fields;
97
98 foreach my $k (keys %data) {
99 if (exists $create{lc $k}) {
100 $v{$create{lc $k}} = delete $data{$k};
101 }
102 }
103
104 if ($v{Name} eq '<queue name>') {
105 my %o = keys %$changes;
106 delete @o{"id", @fields};
107 return [
108 "# Please set the queue name.",
109 [ "id", @fields, keys %o ], $changes, 1
110 ];
111 }
112
113 $queue->Create(%v);
114 unless ($queue->Id) {
115 return [ "# Could not create queue.", [], {}, 1 ];
116 }
117
118 delete $data{id};
119 $id = $queue->Id;
120 push(@comments, "# Queue $id created.");
121 goto DONE if keys %data == 0;
122 }
123}
124
125if ( keys %data == 0) {
126 my @data;
127
128 push @data, [ id => "queue/".$queue->Id ];
129 foreach my $key (@fields) {
130 push @data, [ $key => $queue->$key ];
131 }
132
133 # Custom fields
134 my $CustomFields = $queue->CustomFields;
135 while ( my $CustomField = $CustomFields->Next() ) {
136 next
137 unless ( !%$fields
138 || exists $fields->{ lc "CF-" . $CustomField->Name } );
139 next unless $CustomField->CurrentUserHasRight('SeeCustomField');
140 my $CFvalues = $queue->CustomFieldValues( $CustomField->Id );
141 my @CFvalues;
142 while ( my $CFvalue = $CFvalues->Next() ) {
143 push @CFvalues, $CFvalue->Content;
144 }
145 push @data, [ "CF-" . $CustomField->Name => \@CFvalues ];
146 }
147
148 my %k = map {@$_} @data;
149 $o = [ map {$_->[0]} @data ];
150 $k = \%k;
151}
152else {
153 my ($get, $set, $key, $val, $n, $s);
01e3b242 154 my $updated;
84fb5b46
MKG
155 foreach $key (keys %data) {
156 $val = $data{$key};
157 $key = lc $key;
158 $n = 1;
159
160 if (exists $fields{$key}) {
161 $key = $fields{$key};
162 $set = "Set$key";
163
164 next if $val eq $queue->$key;
165 ($n, $s) = $queue->$set($val);
166 }
167 elsif ($key ne 'id') {
168 $n = 0;
169 $s = "Unknown field.";
170 }
171
172 SET:
173 if ($n == 0) {
174 $e = 1;
175 push @comments, "# $key: $s";
176 unless (@$o) {
177 my %o = keys %$changes;
178 delete @o{"id", @fields};
179 @$o = ("id", @fields, keys %o);
180 $k = $changes;
181 }
182 }
01e3b242
MKG
183 else {
184 $updated ||= 1;
185 }
84fb5b46
MKG
186 }
187
01e3b242 188 push(@comments, "# Queue $id updated.") if $updated;
84fb5b46
MKG
189}
190
191DONE:
192$c ||= join("\n", @comments) if @comments;
193return [ $c, $o, $k, $e ];
194</%perl>