Commit be1bdf39 authored by myk%mozilla.org's avatar myk%mozilla.org

Fix for bug 179334: updates the setter consistently. also fixes numerous other…

Fix for bug 179334: updates the setter consistently. also fixes numerous other bugs in the RT code. r=bbaetz a=myk
parent 46761257
...@@ -183,6 +183,7 @@ sub process { ...@@ -183,6 +183,7 @@ sub process {
my @old_summaries; my @old_summaries;
foreach my $flag (@$flags) { foreach my $flag (@$flags) {
my $summary = $flag->{'type'}->{'name'} . $flag->{'status'}; my $summary = $flag->{'type'}->{'name'} . $flag->{'status'};
$summary .= "($flag->{'requestee'}->{'nick'})" if $flag->{'requestee'};
push(@old_summaries, $summary); push(@old_summaries, $summary);
} }
...@@ -221,6 +222,7 @@ sub process { ...@@ -221,6 +222,7 @@ sub process {
my @new_summaries; my @new_summaries;
foreach my $flag (@$flags) { foreach my $flag (@$flags) {
my $summary = $flag->{'type'}->{'name'} . $flag->{'status'}; my $summary = $flag->{'type'}->{'name'} . $flag->{'status'};
$summary .= "($flag->{'requestee'}->{'nick'})" if $flag->{'requestee'};
push(@new_summaries, $summary); push(@new_summaries, $summary);
} }
...@@ -268,8 +270,10 @@ sub create { ...@@ -268,8 +270,10 @@ sub create {
$timestamp)"); $timestamp)");
# Send an email notifying the relevant parties about the flag creation. # Send an email notifying the relevant parties about the flag creation.
if ($flag->{'requestee'} && $flag->{'requestee'}->email_prefs->{'FlagRequestee'} if ($flag->{'requestee'}
|| $flag->{'type'}->{'cc_list'}) { && ($flag->{'requestee'}->email_prefs->{'FlagRequestee'}
|| $flag->{'type'}->{'cc_list'}))
{
notify($flag, "request/created-email.txt.tmpl"); notify($flag, "request/created-email.txt.tmpl");
} }
} }
...@@ -299,15 +303,21 @@ sub modify { ...@@ -299,15 +303,21 @@ sub modify {
# Extract a list of flags from the form data. # Extract a list of flags from the form data.
my @ids = map(/^flag-(\d+)$/ ? $1 : (), keys %$data); my @ids = map(/^flag-(\d+)$/ ? $1 : (), keys %$data);
# Loop over flags and update their record in the database. # Loop over flags and update their record in the database if necessary.
# Two kinds of changes can happen to a flag: it can be set to a different
# state, and someone else can be asked to set it. We take care of both
# those changes.
my @flags; my @flags;
foreach my $id (@ids) { foreach my $id (@ids) {
my $flag = get($id); my $flag = get($id);
my $status = $data->{"flag-$id"}; my $status = $data->{"flag-$id"};
my $requestee_email = $data->{"requestee-$id"};
# Ignore flags the user didn't change. # Ignore flags the user didn't change.
next if $status eq $flag->{'status'}; next if ($status eq $flag->{'status'} && $flag->{'requestee'}
&& $requestee_email eq $flag->{'requestee'}->{'email'});
# Since the status is validated, we know it's safe, but it's still # Since the status is validated, we know it's safe, but it's still
# tainted, so we have to detaint it before using it in a query. # tainted, so we have to detaint it before using it in a query.
&::trick_taint($status); &::trick_taint($status);
...@@ -315,6 +325,7 @@ sub modify { ...@@ -315,6 +325,7 @@ sub modify {
if ($status eq '+' || $status eq '-') { if ($status eq '+' || $status eq '-') {
&::SendSQL("UPDATE flags &::SendSQL("UPDATE flags
SET setter_id = $::userid , SET setter_id = $::userid ,
requestee_id = NULL ,
status = '$status' , status = '$status' ,
modification_date = $timestamp modification_date = $timestamp
WHERE id = $flag->{'id'}"); WHERE id = $flag->{'id'}");
...@@ -328,10 +339,28 @@ sub modify { ...@@ -328,10 +339,28 @@ sub modify {
} }
} }
elsif ($status eq '?') { elsif ($status eq '?') {
# Get the requestee, if any.
my $requestee_id = "NULL";
if ($requestee_email) {
$requestee_id = &::DBname_to_id($requestee_email);
$flag->{'requestee'} = new Bugzilla::User($requestee_id);
}
# Update the database with the changes.
&::SendSQL("UPDATE flags &::SendSQL("UPDATE flags
SET status = '$status' , SET setter_id = $::userid ,
requestee_id = $requestee_id ,
status = '$status' ,
modification_date = $timestamp modification_date = $timestamp
WHERE id = $flag->{'id'}"); WHERE id = $flag->{'id'}");
# Send an email notifying the relevant parties about the request.
if ($flag->{'requestee'}
&& ($flag->{'requestee'}->email_prefs->{'FlagRequestee'}
|| $flag->{'type'}->{'cc_list'}))
{
notify($flag, "request/created-email.txt.tmpl");
}
} }
# The user unset the flag, so delete it from the database. # The user unset the flag, so delete it from the database.
elsif ($status eq 'X') { elsif ($status eq 'X') {
...@@ -390,12 +419,12 @@ sub FormToNewFlags { ...@@ -390,12 +419,12 @@ sub FormToNewFlags {
status => $status status => $status
}; };
my $requestee_str = $data->{"requestee-$type_id"} || $data->{'requestee'}; if ($status eq "?") {
if ($requestee_str) { my $requestee = $data->{"requestee_type-$type_id"};
my $requestee_id = &::DBname_to_id($requestee_str); if ($requestee) {
$requestee_id my $requestee_id = &::DBname_to_id($requestee);
|| &::ThrowUserError("invalid_username", {name => $requestee_str}); $flag->{'requestee'} = new Bugzilla::User($requestee_id);
$flag->{'requestee'} = new Bugzilla::User($requestee_id); }
} }
# Add the flag to the array of flags. # Add the flag to the array of flags.
......
...@@ -234,10 +234,15 @@ sub match_field { ...@@ -234,10 +234,15 @@ sub match_field {
$expanded_fields->{$field_name} = $expanded_fields->{$field_name} =
{ type => $fields->{$field_pattern}->{'type'} }; { type => $fields->{$field_pattern}->{'type'} };
# The field is a requestee field; in order for its name to show # The field is a requestee field; in order for its name
# up correctly on the confirmation page, we need to find out # to show up correctly on the confirmation page, we need
# the name of its flag type. # to find out the name of its flag type.
if ($field_name =~ /^requestee-(\d+)$/) { if ($field_name =~ /^requestee-(\d+)$/) {
my $flag = Bugzilla::Flag::get($1);
$expanded_fields->{$field_name}->{'flag_type'} =
$flag->{'type'};
}
elsif ($field_name =~ /^requestee_type-(\d+)$/) {
$expanded_fields->{$field_name}->{'flag_type'} = $expanded_fields->{$field_name}->{'flag_type'} =
Bugzilla::FlagType::get($1); Bugzilla::FlagType::get($1);
} }
......
...@@ -110,7 +110,8 @@ elsif ($action eq "update") ...@@ -110,7 +110,8 @@ elsif ($action eq "update")
validateContentType() unless $::FORM{'ispatch'}; validateContentType() unless $::FORM{'ispatch'};
validateIsObsolete(); validateIsObsolete();
validatePrivate(); validatePrivate();
Bugzilla::User::match_field({ '^requestee-(\d+)$' => { 'type' => 'single' } }); Bugzilla::User::match_field({ '^requestee(_type)?-(\d+)$' =>
{ 'type' => 'single' } });
Bugzilla::Flag::validate(\%::FORM); Bugzilla::Flag::validate(\%::FORM);
Bugzilla::FlagType::validate(\%::FORM); Bugzilla::FlagType::validate(\%::FORM);
update(); update();
......
...@@ -91,10 +91,10 @@ scalar(@idlist) || ThrowUserError("no_bugs_chosen"); ...@@ -91,10 +91,10 @@ scalar(@idlist) || ThrowUserError("no_bugs_chosen");
# do a match on the fields if applicable # do a match on the fields if applicable
&Bugzilla::User::match_field({ &Bugzilla::User::match_field({
'qa_contact' => { 'type' => 'single' }, 'qa_contact' => { 'type' => 'single' },
'newcc' => { 'type' => 'multi' }, 'newcc' => { 'type' => 'multi' },
'assigned_to' => { 'type' => 'single' }, 'assigned_to' => { 'type' => 'single' },
'^requestee-(\d+)$' => { 'type' => 'single' }, '^requestee(_type)?-(\d+)$' => { 'type' => 'single' },
}); });
# If we are duping bugs, let's also make sure that we can change # If we are duping bugs, let's also make sure that we can change
......
...@@ -20,33 +20,53 @@ ...@@ -20,33 +20,53 @@
#%] #%]
<script type="text/javascript"> <script type="text/javascript">
// Enables or disables a requestee field depending on whether // Enables or disables a requestee field depending on whether or not
// the user is requesting that flag type. // the user is requesting the corresponding flag.
function toggleRequesteeField(selectField) function toggleRequesteeField(flagField)
{ {
var flagID = selectField.name.replace(/flag_type-(\d+)/, "$1"); // Convert the ID of the flag field into the ID of its corresponding
var requesteeField = document.getElementById("requestee-" + flagID); // requestee field and then use the ID to get the field.
var id = flagField.name.replace(/flag(_type)?-(\d+)/, "requestee$1-$2");
var requesteeField = document.getElementById(id);
if (!requesteeField) return; if (!requesteeField) return;
if (selectField.value == "?") requesteeField.disabled = false;
else requesteeField.disabled = true; // Enable or disable the requestee field based on the value
// of the flag field.
if (flagField.value == "?") requesteeField.disabled = false;
else requesteeField.disabled = true;
} }
// Disables requestee fields when the window is loaded since they // Disables requestee fields when the window is loaded since they shouldn't
// shouldn't be enabled until the user requests that flag type. // be enabled until the user requests that flag type.
function disableRequesteeFields() function disableRequesteeFields()
{ {
var inputElements = document.getElementsByTagName("input"); var inputElements = document.getElementsByTagName("input");
var inputElement; var inputElement, id, flagField;
for ( var i=0 ; i<inputElements.length ; i++ ) for ( var i=0 ; i<inputElements.length ; i++ )
{ {
inputElement = inputElements.item(i); inputElement = inputElements.item(i);
if (inputElement.name.search(/^requestee-(\d+)$/) != -1) if (inputElement.name.search(/^requestee(_type)?-(\d+)$/) != -1)
inputElement.disabled = true; {
// Convert the ID of the requestee field into the ID of its corresponding
// flag field and then use the ID to get the field.
id = inputElement.name.replace(/requestee(_type)?-(\d+)/, "flag$1-$2");
flagField = document.getElementById(id);
if (flagField && flagField.value != "?")
inputElement.disabled = true;
}
} }
} }
window.onload = disableRequesteeFields; window.onload = disableRequesteeFields;
</script> </script>
[%# We list flags by looping twice over the flag types relevant for the bug.
# In the first loop, we display existing flags and then, for active types,
# we display UI for adding new flags. In the second loop, we display UI
# for adding additional new flags for those types for which a flag already
# exists but which are multiplicable (can have multiple flags of the type
# on a single bug/attachment).
#%]
<table id="flags"> <table id="flags">
[% FOREACH type = flag_types %] [% FOREACH type = flag_types %]
...@@ -59,7 +79,8 @@ ...@@ -59,7 +79,8 @@
[% type.name FILTER html %] [% type.name FILTER html %]
</td> </td>
<td> <td>
<select name="flag-[% flag.id %]" onchange="toggleRequesteeField(this);"> <select id="flag-[% flag.id %]" name="flag-[% flag.id %]"
onchange="toggleRequesteeField(this);">
<option value="X"></option> <option value="X"></option>
[% IF type.is_active %] [% IF type.is_active %]
<option value="+" [% "selected" IF flag.status == "+" %]>+</option> <option value="+" [% "selected" IF flag.status == "+" %]>+</option>
...@@ -73,12 +94,15 @@ ...@@ -73,12 +94,15 @@
</select> </select>
</td> </td>
<td> <td>
[% IF flag.status == "?" %] [% IF type.is_active && type.is_requestable %]
[% IF flag.requestee %]([% flag.requestee.nick FILTER html %])[% END %]
[% ELSIF type.is_requestable && type.is_active %]
<span style="white-space: nowrap;"> <span style="white-space: nowrap;">
(<input type="text" id="requestee-[% type.id %]" (<input type="text" size="8" maxlength="255"
name="requestee-[% type.id %]" size="8" maxlength="255">) id="requestee-[% flag.id %]"
name="requestee-[% flag.id %]"
[% IF flag.status == "?" && flag.requestee %]
value="[% flag.requestee.email FILTER html %]"
[% END %]
>)
</span> </span>
[% END %] [% END %]
</td> </td>
...@@ -89,7 +113,8 @@ ...@@ -89,7 +113,8 @@
<td>&nbsp;</td> <td>&nbsp;</td>
<td>[% type.name %]</td> <td>[% type.name %]</td>
<td> <td>
<select name="flag_type-[% type.id %]" onchange="toggleRequesteeField(this);"> <select id="flag_type-[% type.id %]" name="flag_type-[% type.id %]"
onchange="toggleRequesteeField(this);">
<option value="X"></option> <option value="X"></option>
<option value="+">+</option> <option value="+">+</option>
<option value="-">-</option> <option value="-">-</option>
...@@ -100,8 +125,9 @@ ...@@ -100,8 +125,9 @@
</td> </td>
<td> <td>
<span style="white-space: nowrap;"> <span style="white-space: nowrap;">
(<input type="text" id="requestee-[% type.id %]" (<input type="text" size="8" maxlength="255"
name="requestee-[% type.id %]" size="8" maxlength="255">) id="requestee_type-[% type.id %]"
name="requestee_type-[% type.id %]">)
</span> </span>
</td> </td>
</tr> </tr>
...@@ -117,7 +143,8 @@ ...@@ -117,7 +143,8 @@
<tr> <tr>
<td colspan="2">addl. [% type.name %]</td> <td colspan="2">addl. [% type.name %]</td>
<td> <td>
<select name="flag_type-[% type.id %]" onchange="toggleRequesteeField(this);"> <select id="flag_type-[% type.id %]" name="flag_type-[% type.id %]"
onchange="toggleRequesteeField(this);">
<option value="X"></option> <option value="X"></option>
<option value="+">+</option> <option value="+">+</option>
<option value="-">-</option> <option value="-">-</option>
...@@ -129,8 +156,9 @@ ...@@ -129,8 +156,9 @@
<td> <td>
[% IF type.is_requestable && type.is_requesteeble %] [% IF type.is_requestable && type.is_requesteeble %]
<span style="white-space: nowrap;"> <span style="white-space: nowrap;">
(<input type="text" id="requestee-[% type.id %]" (<input type="text" size="8" maxlength="255"
name="requestee-[% type.id %]" size="8" maxlength="255">) id="requestee_type-[% type.id %]"
name="requestee_type-[% type.id %]">)
</span> </span>
[% END %] [% END %]
</td> </td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment