Software Freedom Law Center

root/tags/went-live-on-2006-01-20/stetsubs.pl

Revision 14, 10.6 kB (checked in by orion, 3 years ago)


Line 
1 # Copyright (C) 2005   Software Freedom Law Center, Inc.
2 # Author: Orion Montoya <orion@mdcclv.com>
3 #
4 # This software gives you freedom; it is licensed to you under version
5 # 3 of the GNU Affero General Public License, along with the
6 # additional permission in the following paragraph.
7 #
8 # This notice constitutes a grant of such permission as is necessary
9 # to combine or link this software, or a modified version of it, with
10 # Request Tracker (RT), published by Jesse Vincent and Best Practical
11 # Solutions, LLC, or a derivative work of RT, and to copy, modify, and
12 # distribute the resulting work.  RT is licensed under version 2 of
13 # the GNU General Public License.
14
15 # This software is distributed WITHOUT ANY WARRANTY, without even the
16 # implied warranties of MERCHANTABILITY and FITNESS FOR A PARTICULAR
17 # PURPOSE.  See the GNU Affero General Public License for further
18 # details.
19
20 # You should have received a copy of the GNU Affero General Public
21 # License, version 3, and the GNU General Public License, version 2,
22 # along with this software.  If not, see <http://www.gnu.org/licenses/>.
23
24 use CGI qw/standard/;
25 use MIME::Base64;
26 use Frontier::Client;
27 use URI::Escape;
28
29 sub stripCrap($) {
30     my $crappy = shift;
31     $crappy =~ s/(.*)\?.*/$1/;
32     $crappy =~ s/.*\/([^\/]+)/$1/;
33     return $crappy;
34 }
35
36 sub cleanNoteSel($) {
37     my $item = shift;
38     my $noteSelection = $$item->FirstCustomFieldValue('NoteSelection');
39     $noteSelection =~ s/</&lt;/g;
40     $noteSelection =~ s/>/&gt;/g;
41     return $noteSelection;
42 }
43
44 sub showAgree($) {
45     my $item = shift;
46     my $agr_vals;
47     our ($resp,$name);
48     my $showagree = '';
49     $agr_vals = $$item->CustomFieldValues(7);
50     if ($resp == 1) {
51         while (my $value = $agr_vals->Next) {
52             if (($name) && ($value->Content eq $name)) {
53 #                   $showagree = "<a label=\"you have indicated that you agree with this\" name=\"you have indicated that you agree with this\">unagree</a>";
54                 $showagree = "unagree";
55             }
56         }
57         if (!$showagree) {
58             $showagree = "agree";
59         }
60     }
61     else {
62         $showagree = "<a href=\"http://gplv3.fsf.org/login_form?came_from=/comments/\">login</a> to agree";
63     }
64 #    print STDERR "showagree is $showagree\n";
65     return $showagree, $agr_vals->Count;
66 }
67
68
69 sub showAgreeStr($) {
70     my $item = shift;
71     my $agr_vals;
72     our ($resp,$name);
73         my $showagree = '';     
74     $agr_vals = $$item->CustomFieldValues(7);
75         if ($resp == 1) {
76             while (my $value = $agr_vals->Next) {
77                 if (($name) && ($value->Content eq $name)) {
78 #                   $showagree = "<a label=\"you have indicated that you agree with this\" name=\"you have indicated that you agree with this\">unagree</a>";
79                     $showagree = "unagree";
80                 }
81             }
82             if (!$showagree) {
83                 $showagree = "agree";
84             }
85         }
86         else {
87             $showagree = "login";
88         }
89
90         return $showagree, $agr_vals->count;
91 }
92
93
94
95 sub getUser($) {
96
97     my $CurrentUser = RT::CurrentUser->new;
98     print STDERR "entering getUser with external passwords\n";
99     do "xmlpass.pl";
100     my $name;
101     our ($pass,$resp);
102     if (($name, $pass) = split(/:/, decode_base64(CGI::cookie('__ac')))) {
103         $name =~ s/\"//g;
104         my $server = Frontier::Client->new(url => 'http://stet_auth:fai1Iegh@gplv3.fsf.org:8800/launch/acl_users/Users/acl_users',
105                                            username => $username,
106                                            password =>  $password);
107         my $respref = $server->call('authRemoteUser',$name,$pass);
108         $resp = $$respref;
109     }
110     else {
111         $resp = 0;
112     }
113 #    print STDERR "resp to getUser was $resp\n";
114    
115 # mangle name for testing:
116 #       $name = $name."createtest2"; # have used 1, 45
117 #    print STDERR "name is $name and currentuser hash is ".$CurrentUser."\n";
118 # authorized users get privileges
119     if ($resp == 1) {
120         $CurrentUser->LoadByName($name);
121         print STDERR "current $resp a user is ".$CurrentUser->id."(".$CurrentUser->Name.")\n";
122     }
123     if (($resp ==1) && (!$CurrentUser->id)) {
124         my ($val, $msg) = createUser($name,$pass);
125         print STDERR "trying to create a user $name, got \"$val : $msg\"\n";
126         $CurrentUser->LoadByName($name);
127         print STDERR "created current $resp b user is ".$CurrentUser->id."(".$CurrentUser->Name.")\n";
128     }
129     elsif (!$CurrentUser->id) {
130 # unauthorized users get to see the public queues
131         $CurrentUser->LoadByName("public");
132         print STDERR "current $resp c user is ".$CurrentUser->id."(".$CurrentUser->Name.")\n";
133     }
134     $session->{'CurrentUser'} = $CurrentUser;
135     return ($CurrentUser, $resp, $name);
136 }
137
138 #}
139
140 sub createUser($$) {
141 my $name = shift;
142 my $pass = shift;
143 my $UserObj = RT::User->new(RT::CurrentUser->new('RT_System'));
144
145 my ($val, $msg) = $UserObj->Create(
146
147
148         Name                  => $name,
149         RealName              => $name,
150         ExternalContactInfoId => $name,
151         EmailAddress          => $name,
152         ContactInfoSystem     => "gnuxmlrpc",
153         Privileged           => 1,
154         Disabled            => 0,
155                                       );
156
157 #                                  %{ref($RT::AutoCreate) ? $RT::AutoCreate : {}},
158 #                                  Name   => $user,
159 #                                  Gecos  => $user,
160 #                                  Disabled => '0',
161 #                                  );
162
163 $UserObj->SetPassword($pass);
164
165     return ($val, $msg);
166 }
167
168 sub humanQuery {
169     $query = shift;
170     $query =~ s/'CF.NoteUrl' LIKE/in file/g;
171     $query =~ s/'CF.NoteUrl' NOT LIKE/not in file/g;
172 #    $query =~ s/'CF.NoteUrl' LIKE//g;
173 #    $query =~ s/'CF.NoteUrl' NOT LIKE//g;
174    
175     $query =~ s/'CF.NoteSelection' LIKE/selected text matches/g;
176     $query =~ s/'CF.NoteSelection' NOT LIKE/selected text does not match/g;
177     $query =~ s/'CF.NoteStartNodeId' LIKE/in section id/g;
178     $query =~ s/'CF.NoteStartNodeId' NOT LIKE/not in section id/g;
179     $query =~ s/'CF.Agreeers' LIKE/agreeers include/g;
180     $query =~ s/'CF.Agreeers' NOT LIKE/agreeers do not include/g;
181
182     $query =~ s/Requestor.Name LIKE/submitter matches/g;
183     $query =~ s/ AND /, and /g;
184     $query =~ s/ OR /, or /g;
185     return $query;
186 }
187
188 # {{{ sub myCFValueUpdater
189
190 sub myCFValueUpdater {
191             print STDERR "stetsubs.pl 157\n";
192     my %args = (
193         ARGSRef => undef,
194         @_
195     );
196
197     my @results;
198
199     my $ARGSRef = $args{'ARGSRef'};
200
201     # Build up a list of tickets that we want to work with
202     my %tickets_to_mod;
203     my %custom_fields_to_mod;
204     foreach my $arg ( keys %{$ARGSRef} ) {
205         if ( $arg =~ /^Ticket-(\d+)-CustomField-(\d+)-/ ) {
206
207             # For each of those tickets, find out what custom fields we want to work with.
208             $custom_fields_to_mod{$1}{$2} = 1;
209             print STDERR "Web.pm 1059 ticket $1 field $2\n";
210         }
211     }
212
213     # For each of those tickets
214     foreach my $tick ( keys %custom_fields_to_mod ) {
215         my $Ticket = $args{'TicketObj'};
216         if (!$Ticket or $Ticket->id != $tick) {
217             $Ticket = RT::Ticket->new( $session{'CurrentUser'} );
218             $Ticket->Load($tick);
219         }
220
221         # For each custom field 
222         foreach my $cf ( keys %{ $custom_fields_to_mod{$tick} } ) {
223
224             my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
225             $CustomFieldObj->LoadById($cf);
226
227             foreach my $arg ( keys %{$ARGSRef} ) {
228                 # since http won't pass in a form element with a null value, we need
229                 # to fake it
230                 if ($arg =~ /^(.*?)-Values-Magic$/ ) {
231                     # We don't care about the magic, if there's really a values element;
232                     next if (exists $ARGSRef->{$1.'-Values'}) ;
233
234                     $arg = $1."-Values";
235                     $ARGSRef->{$1."-Values"} = undef;
236                
237                 }
238                 next unless ( $arg =~ /^Ticket-$tick-CustomField-$cf-/ );
239                 my @values =
240                   ( ref( $ARGSRef->{$arg} ) eq 'ARRAY' )
241                   ? @{ $ARGSRef->{$arg} }
242                   : split /\n/, $ARGSRef->{$arg} ;
243
244                 #for poor windows boxen that pass in "\r\n"
245                 local $/ = "\r";
246                 chomp @values;
247
248                 if ( ( $arg =~ /-AddValue$/ ) || ( $arg =~ /-Value$/ ) ) {
249                     foreach my $value (@values) {
250                         next unless length($value);
251                         my ( $val, $msg ) = $Ticket->AddCustomFieldValue(
252                             Field => $cf,
253                             Value => $value
254                         );
255                         push ( @results, $msg );
256                     }
257                 }
258                 elsif ( $arg =~ /-DeleteValues$/ ) {
259                     foreach my $value (@values) {
260                         next unless length($value);
261                         my ( $val, $msg ) = $Ticket->DeleteCustomFieldValue(
262                             Field => $cf,
263                             Value => $value
264                         );
265                         push ( @results, $msg );
266                     }
267                 }
268                 elsif ( $arg =~ /-Values$/ and $CustomFieldObj->Type !~ /Entry/) {
269                     my $cf_values = $Ticket->CustomFieldValues($cf);
270
271                     my %values_hash;
272                     foreach my $value (@values) {
273                         next unless length($value);
274
275                         # build up a hash of values that the new set has
276                         $values_hash{$value} = 1;
277
278                         unless ( $cf_values->HasEntry($value) ) {
279                             my ( $val, $msg ) = $Ticket->AddCustomFieldValue(
280                                 Field => $cf,
281                                 Value => $value
282                             );
283                             push ( @results, $msg );
284                         }
285
286                     }
287                     while ( my $cf_value = $cf_values->Next ) {
288                         unless ( $values_hash{ $cf_value->Content } == 1 ) {
289                             my ( $val, $msg ) = $Ticket->DeleteCustomFieldValue(
290                                 Field => $cf,
291                                 Value => $cf_value->Content
292                             );
293                             push ( @results, $msg);
294
295                         }
296
297                     }
298                 }
299                 elsif ( $arg =~ /-Values$/ ) {
300                     my $cf_values = $Ticket->CustomFieldValues($cf);
301
302                     # keep everything up to the point of difference, delete the rest
303                     my $delete_flag;
304                     foreach my $old_cf (@{$cf_values->ItemsArrayRef}) {
305                         if (!$delete_flag and @values and $old_cf->Content eq $values[0]) {
306                             shift @values;
307                             next;
308                         }
309
310                         $delete_flag ||= 1;
311                         $old_cf->Delete;
312                     }
313
314                     # now add/replace extra things, if any
315                     foreach my $value (@values) {
316                         my ( $val, $msg ) = $Ticket->AddCustomFieldValue(
317                             Field => $cf,
318                             Value => $value
319                         );
320                         push ( @results, $msg );
321                     }
322                 }
323                 else {
324                     push ( @results, "User asked for an unknown update type for custom field " . $cf->Name . " for ticket " . $Ticket->id );
325                 }
326             }
327         }
328         return (@results);
329     }
330 }
331
332 # }}}
333
334
335 1;
Note: See TracBrowser for help on using the browser.

SFLC Main Page

[frdm] Support SFLC