Software Freedom Law Center

root/tags/went-live-on-2006-03-14/stetsubs.pl

Revision 51, 11.2 kB (checked in by orion, 3 years ago)

release intensity highlighting

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 require "/var/www/stet/xmlpass.pl";
30
31 sub stripCrap($) {
32     my $crappy = shift;
33     $crappy =~ s/(.*)\?.*/$1/;
34     $crappy =~ s/.*\/([^\/]+)/$1/;
35     return $crappy;
36 }
37
38 sub cleanNoteSel($) {
39     my $item = shift;
40     my $noteSelection = $$item->FirstCustomFieldValue('NoteSelection');
41     $noteSelection =~ s/</&lt;/g;
42     $noteSelection =~ s/>/&gt;/g;
43     return $noteSelection;
44 }
45
46 sub showAgree($$) {
47     my $item = shift;
48     my $name = shift;
49     my $agr_vals;
50     my $showagree = '';
51     $agr_vals = $$item->CustomFieldValues(7);
52     if ($resp == 1) {
53         if (($name) && ($agr_vals->HasEntry("$name\n"))) {
54             $showagree = "unagree";
55         }
56         else {
57             $showagree = "agree";
58         }
59     }
60     else {
61         $showagree = "<a href=\"http://gplv3.fsf.org/login_form?came_from=/comments/\">login</a> to agree";
62     }
63 #    print STDERR "showagree is $showagree\n";
64     return $showagree, $agr_vals->Count;
65 }
66
67
68 sub showAgreeStr($) {
69     my $item = shift;
70     my $agr_vals;
71     our ($resp,$name);
72         my $showagree = '';     
73     $agr_vals = $$item->CustomFieldValues(7);
74         if ($resp == 1) {
75             while (my $value = $agr_vals->Next) {
76                 if (($name) && ($value->Content eq $name)) {
77 #                   $showagree = "<a label=\"you have indicated that you agree with this\" name=\"you have indicated that you agree with this\">unagree</a>";
78                     $showagree = "unagree";
79                 }
80             }
81             if (!$showagree) {
82                 $showagree = "agree";
83             }
84         }
85         else {
86             $showagree = "login";
87         }
88
89         return $showagree, $agr_vals->count;
90 }
91
92
93 my $server;
94 sub getUser($) {
95
96     my $CurrentUser = RT::CurrentUser->new;
97     my ($username, $password) = userpass();
98
99 #    print STDERR "entering getUser with external passwords.\n";
100     my $name;
101     our ($pass,$resp,$server);
102     if (($name, $pass) = split(/:/, decode_base64(CGI::cookie('__ac')))) {
103         $name =~ s/\"//g;
104         $server = Frontier::Client->new(url => 'http://'.$username.':'.$password.'@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 shortOrg ($) {
141     my $user = shift;
142     if ($user->Organization) {
143         if ($user->Organization =~ /[A-Z]/) {
144             return " (of ".$user->Organization.") ";
145         }
146         else {
147             return " (".$user->Organization.") ";
148         }
149     }
150 }
151 sub longOrg ($) {
152     my $user = shift;
153     if ($user->Organization) {
154         if ($user->Organization =~ /[A-Z]/) {
155             $X = $user->Organization;
156             return " (of Committee <a href=\"http://gplv3.fsf.org/comments/rt/readsay.html?Query='CF.DiscussionGroup'%20LIKE%20'".$X."'\">".$X."</a>) ";
157         }
158         else {
159             return " (".$user->Organization.") ";
160         }
161     }
162 }
163
164 sub createUser($$) {
165 my $name = shift;
166 my $pass = shift;
167 my $UserObj = RT::User->new(RT::CurrentUser->new('RT_System'));
168 our $server;
169 my $email = '';
170
171     eval{ $email = $server->call('getEmail',$name) };
172
173 if ($email) { print STDERR "got email $email\n"; }
174 else { $email = $name; }
175
176 my ($val, $msg) = $UserObj->Create(
177
178
179         Name                  => $name,
180         RealName              => $name,
181         ExternalContactInfoId => $name,
182         EmailAddress          => $email,
183         ContactInfoSystem     => "gnuxmlrpc",
184         Privileged           => 1,
185         Disabled            => 0,
186                                       );
187
188 #                                  %{ref($RT::AutoCreate) ? $RT::AutoCreate : {}},
189 #                                  Name   => $user,
190 #                                  Gecos  => $user,
191 #                                  Disabled => '0',
192 #                                  );
193
194 $UserObj->SetPassword($pass);
195
196     return ($val, $msg);
197 }
198
199 sub humanQuery {
200     $query = shift;
201     $query =~ s/'CF.NoteUrl' LIKE/in file/g;
202     $query =~ s/'CF.NoteUrl' NOT LIKE/not in file/g;
203 #    $query =~ s/'CF.NoteUrl' LIKE//g;
204 #    $query =~ s/'CF.NoteUrl' NOT LIKE//g;
205    
206     $query =~ s/'CF.NoteSelection' LIKE/selected text matches/g;
207     $query =~ s/'CF.NoteSelection' NOT LIKE/selected text does not match/g;
208     $query =~ s/'CF.NoteStartNodeId' LIKE/in section id/g;
209     $query =~ s/'CF.NoteStartNodeId' NOT LIKE/not in section id/g;
210     $query =~ s/'CF.Agreeers' LIKE/agreeers include/g;
211     $query =~ s/'CF.Agreeers' NOT LIKE/agreeers do not include/g;
212
213     $query =~ s/Requestor.Name LIKE/submitter matches/g;
214     $query =~ s/ AND /, and /g;
215     $query =~ s/ OR /, or /g;
216     return $query;
217 }
218
219 # {{{ sub myCFValueUpdater
220
221 sub myCFValueUpdater {
222             print STDERR "stetsubs.pl 157\n";
223     my %args = (
224         ARGSRef => undef,
225         @_
226     );
227
228     my @results;
229
230     my $ARGSRef = $args{'ARGSRef'};
231
232     # Build up a list of tickets that we want to work with
233     my %tickets_to_mod;
234     my %custom_fields_to_mod;
235     foreach my $arg ( keys %{$ARGSRef} ) {
236         if ( $arg =~ /^Ticket-(\d+)-CustomField-(\d+)-/ ) {
237
238             # For each of those tickets, find out what custom fields we want to work with.
239             $custom_fields_to_mod{$1}{$2} = 1;
240             print STDERR "Web.pm 1059 ticket $1 field $2\n";
241         }
242     }
243
244     # For each of those tickets
245     foreach my $tick ( keys %custom_fields_to_mod ) {
246         my $Ticket = $args{'TicketObj'};
247         if (!$Ticket or $Ticket->id != $tick) {
248             $Ticket = RT::Ticket->new( $session{'CurrentUser'} );
249             $Ticket->Load($tick);
250         }
251
252         # For each custom field 
253         foreach my $cf ( keys %{ $custom_fields_to_mod{$tick} } ) {
254
255             my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
256             $CustomFieldObj->LoadById($cf);
257
258             foreach my $arg ( keys %{$ARGSRef} ) {
259                 # since http won't pass in a form element with a null value, we need
260                 # to fake it
261                 if ($arg =~ /^(.*?)-Values-Magic$/ ) {
262                     # We don't care about the magic, if there's really a values element;
263                     next if (exists $ARGSRef->{$1.'-Values'}) ;
264
265                     $arg = $1."-Values";
266                     $ARGSRef->{$1."-Values"} = undef;
267                
268                 }
269                 next unless ( $arg =~ /^Ticket-$tick-CustomField-$cf-/ );
270                 my @values =
271                   ( ref( $ARGSRef->{$arg} ) eq 'ARRAY' )
272                   ? @{ $ARGSRef->{$arg} }
273                   : split /\n/, $ARGSRef->{$arg} ;
274
275                 #for poor windows boxen that pass in "\r\n"
276                 local $/ = "\r";
277                 chomp @values;
278
279                 if ( ( $arg =~ /-AddValue$/ ) || ( $arg =~ /-Value$/ ) ) {
280                     foreach my $value (@values) {
281                         next unless length($value);
282                         my ( $val, $msg ) = $Ticket->AddCustomFieldValue(
283                             Field => $cf,
284                             Value => $value
285                         );
286                         push ( @results, $msg );
287                     }
288                 }
289                 elsif ( $arg =~ /-DeleteValues$/ ) {
290                     foreach my $value (@values) {
291                         next unless length($value);
292                         my ( $val, $msg ) = $Ticket->DeleteCustomFieldValue(
293                             Field => $cf,
294                             Value => $value
295                         );
296                         push ( @results, $msg );
297                     }
298                 }
299                 elsif ( $arg =~ /-Values$/ and $CustomFieldObj->Type !~ /Entry/) {
300                     my $cf_values = $Ticket->CustomFieldValues($cf);
301
302                     my %values_hash;
303                     foreach my $value (@values) {
304                         next unless length($value);
305
306                         # build up a hash of values that the new set has
307                         $values_hash{$value} = 1;
308
309                         unless ( $cf_values->HasEntry($value) ) {
310                             my ( $val, $msg ) = $Ticket->AddCustomFieldValue(
311                                 Field => $cf,
312                                 Value => $value
313                             );
314                             push ( @results, $msg );
315                         }
316
317                     }
318                     while ( my $cf_value = $cf_values->Next ) {
319                         unless ( $values_hash{ $cf_value->Content } == 1 ) {
320                             my ( $val, $msg ) = $Ticket->DeleteCustomFieldValue(
321                                 Field => $cf,
322                                 Value => $cf_value->Content
323                             );
324                             push ( @results, $msg);
325
326                         }
327
328                     }
329                 }
330                 elsif ( $arg =~ /-Values$/ ) {
331                     my $cf_values = $Ticket->CustomFieldValues($cf);
332
333                     # keep everything up to the point of difference, delete the rest
334                     my $delete_flag;
335                     foreach my $old_cf (@{$cf_values->ItemsArrayRef}) {
336                         if (!$delete_flag and @values and $old_cf->Content eq $values[0]) {
337                             shift @values;
338                             next;
339                         }
340
341                         $delete_flag ||= 1;
342                         $old_cf->Delete;
343                     }
344
345                     # now add/replace extra things, if any
346                     foreach my $value (@values) {
347                         my ( $val, $msg ) = $Ticket->AddCustomFieldValue(
348                             Field => $cf,
349                             Value => $value
350                         );
351                         push ( @results, $msg );
352                     }
353                 }
354                 else {
355                     push ( @results, "User asked for an unknown update type for custom field " . $cf->Name . " for ticket " . $Ticket->id );
356                 }
357             }
358         }
359         return (@results);
360     }
361 }
362
363 # }}}
364
365
366 1;
Note: See TracBrowser for help on using the browser.

SFLC Main Page

[frdm] Support SFLC