Commit 5ecf8a50 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 343810: Remove Bugzilla::FlagType::get() and implement real flagtype objects…

Bug 343810: Remove Bugzilla::FlagType::get() and implement real flagtype objects - Patch by Frédéric Buclin <LpSolit@gmail.com> a=myk
parent 43dd0fc1
...@@ -104,9 +104,9 @@ Returns the status '+', '-', '?' of the flag. ...@@ -104,9 +104,9 @@ Returns the status '+', '-', '?' of the flag.
=cut =cut
sub id { return $_[0]->{'id'}; } sub id { return $_[0]->{'id'}; }
sub name { return $_[0]->type->{'name'}; } sub name { return $_[0]->type->name; }
sub status { return $_[0]->{'status'}; } sub status { return $_[0]->{'status'}; }
############################### ###############################
#### Methods #### #### Methods ####
...@@ -118,7 +118,7 @@ sub status { return $_[0]->{'status'}; } ...@@ -118,7 +118,7 @@ sub status { return $_[0]->{'status'}; }
=item C<type> =item C<type>
Returns the type of the flag, as pseudo Bugzilla::FlagType object. Returns the type of the flag, as a Bugzilla::FlagType object.
=item C<setter> =item C<setter>
...@@ -136,7 +136,7 @@ Bugzilla::User object. ...@@ -136,7 +136,7 @@ Bugzilla::User object.
sub type { sub type {
my $self = shift; my $self = shift;
$self->{'type'} ||= Bugzilla::FlagType::get($self->{'type_id'}); $self->{'type'} ||= new Bugzilla::FlagType($self->{'type_id'});
return $self->{'type'}; return $self->{'type'};
} }
...@@ -291,7 +291,7 @@ sub validate { ...@@ -291,7 +291,7 @@ sub validate {
# as is. # as is.
if ($status eq '?' if ($status eq '?'
&& $flag->status ne '?' && $flag->status ne '?'
&& !$flag->type->{is_requestable}) && !$flag->type->is_requestable)
{ {
ThrowCodeError("flag_status_invalid", ThrowCodeError("flag_status_invalid",
{ id => $id, status => $status }); { id => $id, status => $status });
...@@ -302,7 +302,7 @@ sub validate { ...@@ -302,7 +302,7 @@ sub validate {
# the flag became specifically unrequestable, don't let the user # the flag became specifically unrequestable, don't let the user
# change the requestee, but let the user remove it by entering # change the requestee, but let the user remove it by entering
# an empty string for the requestee. # an empty string for the requestee.
if ($status eq '?' && !$flag->type->{is_requesteeble}) { if ($status eq '?' && !$flag->type->is_requesteeble) {
my $old_requestee = $flag->requestee ? $flag->requestee->login : ''; my $old_requestee = $flag->requestee ? $flag->requestee->login : '';
my $new_requestee = join('', @requestees); my $new_requestee = join('', @requestees);
if ($new_requestee && $new_requestee ne $old_requestee) { if ($new_requestee && $new_requestee ne $old_requestee) {
...@@ -314,7 +314,7 @@ sub validate { ...@@ -314,7 +314,7 @@ sub validate {
# Make sure the user didn't enter multiple requestees for a flag # Make sure the user didn't enter multiple requestees for a flag
# that can't be requested from more than one person at a time. # that can't be requested from more than one person at a time.
if ($status eq '?' if ($status eq '?'
&& !$flag->type->{is_multiplicable} && !$flag->type->is_multiplicable
&& scalar(@requestees) > 1) && scalar(@requestees) > 1)
{ {
ThrowUserError("flag_not_multiplicable", { type => $flag->type }); ThrowUserError("flag_not_multiplicable", { type => $flag->type });
...@@ -323,7 +323,7 @@ sub validate { ...@@ -323,7 +323,7 @@ sub validate {
# Make sure the requestees are authorized to access the bug. # Make sure the requestees are authorized to access the bug.
# (and attachment, if this installation is using the "insider group" # (and attachment, if this installation is using the "insider group"
# feature and the attachment is marked private). # feature and the attachment is marked private).
if ($status eq '?' && $flag->type->{is_requesteeble}) { if ($status eq '?' && $flag->type->is_requesteeble) {
my $old_requestee = $flag->requestee ? $flag->requestee->login : ''; my $old_requestee = $flag->requestee ? $flag->requestee->login : '';
foreach my $login (@requestees) { foreach my $login (@requestees) {
next if $login eq $old_requestee; next if $login eq $old_requestee;
...@@ -365,20 +365,19 @@ sub validate { ...@@ -365,20 +365,19 @@ sub validate {
# - The flag is unchanged # - The flag is unchanged
next if ($status eq $flag->status); next if ($status eq $flag->status);
# - User in the $request_gid group can clear pending requests and set flags # - User in the request_group can clear pending requests and set flags
# and can rerequest set flags. # and can rerequest set flags.
next if (($status eq 'X' || $status eq '?') next if (($status eq 'X' || $status eq '?')
&& (!$flag->type->{request_gid} && (!$flag->type->request_group
|| $user->in_group_id($flag->type->{request_gid}))); || $user->in_group_id($flag->type->request_group->id)));
# - User in the $grant_gid group can set/clear flags, # - User in the grant_group can set/clear flags, including "+" and "-".
# including "+" and "-" next if (!$flag->type->grant_group
next if (!$flag->type->{grant_gid} || $user->in_group_id($flag->type->grant_group->id));
|| $user->in_group_id($flag->type->{grant_gid}));
# - Any other flag modification is denied # - Any other flag modification is denied
ThrowUserError("flag_update_denied", ThrowUserError("flag_update_denied",
{ name => $flag->type->{name}, { name => $flag->type->name,
status => $status, status => $status,
old_status => $flag->status }); old_status => $flag->status });
} }
...@@ -391,7 +390,7 @@ sub snapshot { ...@@ -391,7 +390,7 @@ sub snapshot {
'attach_id' => $attach_id }); 'attach_id' => $attach_id });
my @summaries; my @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->login . ")" if $flag->requestee; $summary .= "(" . $flag->requestee->login . ")" if $flag->requestee;
push(@summaries, $summary); push(@summaries, $summary);
} }
...@@ -524,7 +523,7 @@ sub create { ...@@ -524,7 +523,7 @@ sub create {
$dbh->do('INSERT INTO flags (type_id, bug_id, attach_id, requestee_id, $dbh->do('INSERT INTO flags (type_id, bug_id, attach_id, requestee_id,
setter_id, status, creation_date, modification_date) setter_id, status, creation_date, modification_date)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)', VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
undef, ($flag->{'type'}->{'id'}, $bug->bug_id, undef, ($flag->{'type'}->id, $bug->bug_id,
$attach_id, $requestee_id, $flag->{'setter'}->id, $attach_id, $requestee_id, $flag->{'setter'}->id,
$flag->{'status'}, $timestamp, $timestamp)); $flag->{'status'}, $timestamp, $timestamp));
...@@ -571,6 +570,8 @@ sub modify { ...@@ -571,6 +570,8 @@ sub modify {
my @flags; my @flags;
foreach my $id (@ids) { foreach my $id (@ids) {
my $flag = new Bugzilla::Flag($id); my $flag = new Bugzilla::Flag($id);
# If the flag no longer exists, ignore it.
next unless $flag;
my $status = $cgi->param("flag-$id"); my $status = $cgi->param("flag-$id");
...@@ -582,7 +583,7 @@ sub modify { ...@@ -582,7 +583,7 @@ sub modify {
my $requestee_email; my $requestee_email;
if ($status eq "?" if ($status eq "?"
&& scalar(@requestees) > 1 && scalar(@requestees) > 1
&& $flag->type->{is_multiplicable}) && $flag->type->is_multiplicable)
{ {
# The first person, for which we'll reuse the existing flag. # The first person, for which we'll reuse the existing flag.
$requestee_email = shift(@requestees); $requestee_email = shift(@requestees);
...@@ -616,7 +617,7 @@ sub modify { ...@@ -616,7 +617,7 @@ sub modify {
my $requestee_changed = my $requestee_changed =
($status eq "?" && ($status eq "?" &&
$flag->type->{'is_requesteeble'} && $flag->type->is_requesteeble &&
$old_requestee ne $requestee_email); $old_requestee ne $requestee_email);
next unless ($status_changed || $requestee_changed); next unless ($status_changed || $requestee_changed);
...@@ -770,7 +771,7 @@ sub FormToNewFlags { ...@@ -770,7 +771,7 @@ sub FormToNewFlags {
my @flags; my @flags;
foreach my $flag_type (@$flag_types) { foreach my $flag_type (@$flag_types) {
my $type_id = $flag_type->{'id'}; my $type_id = $flag_type->id;
# We are only interested in flags the user tries to create. # We are only interested in flags the user tries to create.
next unless scalar(grep { $_ == $type_id } @type_ids); next unless scalar(grep { $_ == $type_id } @type_ids);
...@@ -784,7 +785,7 @@ sub FormToNewFlags { ...@@ -784,7 +785,7 @@ sub FormToNewFlags {
# Do not create a new flag of this type if this flag type is # Do not create a new flag of this type if this flag type is
# not multiplicable and already has a flag set. # not multiplicable and already has a flag set.
next if (!$flag_type->{'is_multiplicable'} && $has_flags); next if (!$flag_type->is_multiplicable && $has_flags);
my $status = $cgi->param("flag_type-$type_id"); my $status = $cgi->param("flag_type-$type_id");
trick_taint($status); trick_taint($status);
...@@ -796,7 +797,7 @@ sub FormToNewFlags { ...@@ -796,7 +797,7 @@ sub FormToNewFlags {
setter => $setter , setter => $setter ,
status => $status , status => $status ,
requestee => Bugzilla::User->new_from_login($login) }); requestee => Bugzilla::User->new_from_login($login) });
last if !$flag_type->{'is_multiplicable'}; last unless $flag_type->is_multiplicable;
} }
} }
else { else {
...@@ -829,7 +830,7 @@ sub notify { ...@@ -829,7 +830,7 @@ sub notify {
my $template = Bugzilla->template; my $template = Bugzilla->template;
# There is nobody to notify. # There is nobody to notify.
return unless ($flag->{'addressee'} || $flag->type->{'cc_list'}); return unless ($flag->{'addressee'} || $flag->type->cc_list);
my $attachment_is_private = $attachment ? $attachment->isprivate : undef; my $attachment_is_private = $attachment ? $attachment->isprivate : undef;
...@@ -839,7 +840,7 @@ sub notify { ...@@ -839,7 +840,7 @@ sub notify {
# not in those groups or email addresses that don't have an account. # not in those groups or email addresses that don't have an account.
if ($bug->groups || $attachment_is_private) { if ($bug->groups || $attachment_is_private) {
my @new_cc_list; my @new_cc_list;
foreach my $cc (split(/[, ]+/, $flag->type->{'cc_list'})) { foreach my $cc (split(/[, ]+/, $flag->type->cc_list)) {
my $ccuser = Bugzilla::User->new_from_login($cc) || next; my $ccuser = Bugzilla::User->new_from_login($cc) || next;
next if ($bug->groups && !$ccuser->can_see_bug($bug->bug_id)); next if ($bug->groups && !$ccuser->can_see_bug($bug->bug_id));
...@@ -852,11 +853,11 @@ sub notify { ...@@ -852,11 +853,11 @@ sub notify {
} }
# If there is nobody left to notify, return. # If there is nobody left to notify, return.
return unless ($flag->{'addressee'} || $flag->type->{'cc_list'}); return unless ($flag->{'addressee'} || $flag->type->cc_list);
# Process and send notification for each recipient # Process and send notification for each recipient
foreach my $to ($flag->{'addressee'} ? $flag->{'addressee'}->email : '', foreach my $to ($flag->{'addressee'} ? $flag->{'addressee'}->email : '',
split(/[, ]+/, $flag->type->{'cc_list'})) split(/[, ]+/, $flag->type->cc_list))
{ {
next unless $to; next unless $to;
my $vars = { 'flag' => $flag, my $vars = { 'flag' => $flag,
......
...@@ -980,7 +980,7 @@ sub match_field { ...@@ -980,7 +980,7 @@ sub match_field {
elsif ($field_name =~ /^requestee_type-(\d+)$/) { elsif ($field_name =~ /^requestee_type-(\d+)$/) {
require Bugzilla::FlagType; require Bugzilla::FlagType;
$expanded_fields->{$field_name}->{'flag_type'} = $expanded_fields->{$field_name}->{'flag_type'} =
Bugzilla::FlagType::get($1); new Bugzilla::FlagType($1);
} }
} }
} }
......
...@@ -713,8 +713,7 @@ sub enter ...@@ -713,8 +713,7 @@ sub enter
'product_id' => $product_id, 'product_id' => $product_id,
'component_id' => $component_id}); 'component_id' => $component_id});
$vars->{'flag_types'} = $flag_types; $vars->{'flag_types'} = $flag_types;
$vars->{'any_flags_requesteeble'} = grep($_->{'is_requesteeble'}, $vars->{'any_flags_requesteeble'} = grep($_->is_requesteeble, @$flag_types);
@$flag_types);
print $cgi->header(); print $cgi->header();
...@@ -835,11 +834,11 @@ sub edit { ...@@ -835,11 +834,11 @@ sub edit {
'product_id' => $product_id , 'product_id' => $product_id ,
'component_id' => $component_id }); 'component_id' => $component_id });
foreach my $flag_type (@$flag_types) { foreach my $flag_type (@$flag_types) {
$flag_type->{'flags'} = Bugzilla::Flag::match({ 'type_id' => $flag_type->{'id'}, $flag_type->{'flags'} = Bugzilla::Flag::match({ 'type_id' => $flag_type->id,
'attach_id' => $attachment->id }); 'attach_id' => $attachment->id });
} }
$vars->{'flag_types'} = $flag_types; $vars->{'flag_types'} = $flag_types;
$vars->{'any_flags_requesteeble'} = grep($_->{'is_requesteeble'}, @$flag_types); $vars->{'any_flags_requesteeble'} = grep($_->is_requesteeble, @$flag_types);
$vars->{'attachment'} = $attachment; $vars->{'attachment'} = $attachment;
$vars->{'bugsummary'} = $bugsummary; $vars->{'bugsummary'} = $bugsummary;
$vars->{'isviewable'} = $isviewable; $vars->{'isviewable'} = $isviewable;
......
...@@ -238,24 +238,24 @@ sub flag_handler { ...@@ -238,24 +238,24 @@ sub flag_handler {
# If this is the case, we will only match the first one. # If this is the case, we will only match the first one.
my $ftype; my $ftype;
foreach my $f ( @{$flag_types} ) { foreach my $f ( @{$flag_types} ) {
if ( $f->{'name'} eq $name) { if ( $f->name eq $name) {
$ftype = $f; $ftype = $f;
last; last;
} }
} }
if ($ftype) { # We found the flag in the list if ($ftype) { # We found the flag in the list
my $grant_gid = $ftype->{'grant_gid'}; my $grant_group = $ftype->grant_group;
if (( $status eq '+' || $status eq '-' ) if (( $status eq '+' || $status eq '-' )
&& $grant_gid && !$setter->in_group_id($grant_gid)) { && $grant_group && !$setter->in_group_id($grant_group->id)) {
$err = "Setter $setter_login on $type flag $name "; $err = "Setter $setter_login on $type flag $name ";
$err .= "is not in the Grant Group\n"; $err .= "is not in the Grant Group\n";
$err .= " Dropping flag $name\n"; $err .= " Dropping flag $name\n";
return $err; return $err;
} }
my $request_gid = $ftype->{'request_gid'}; my $request_group = $ftype->request_group;
if ($request_gid if ($request_group
&& $status eq '?' && !$setter->in_group_id($request_gid)) { && $status eq '?' && !$setter->in_group_id($request_group->id)) {
$err = "Setter $setter_login on $type flag $name "; $err = "Setter $setter_login on $type flag $name ";
$err .= "is not in the Request Group\n"; $err .= "is not in the Request Group\n";
$err .= " Dropping flag $name\n"; $err .= " Dropping flag $name\n";
...@@ -263,9 +263,7 @@ sub flag_handler { ...@@ -263,9 +263,7 @@ sub flag_handler {
} }
# Take the first flag_type that matches # Take the first flag_type that matches
my $ftypeid = $ftype->{'id'}; unless ($ftype->is_active) {
my $is_active = $ftype->{'is_active'};
unless ($is_active) {
$err = "Flag $name is not active in this database\n"; $err = "Flag $name is not active in this database\n";
$err .= " Dropping flag $name\n"; $err .= " Dropping flag $name\n";
return $err; return $err;
...@@ -275,7 +273,7 @@ sub flag_handler { ...@@ -275,7 +273,7 @@ sub flag_handler {
(type_id, status, bug_id, attach_id, creation_date, (type_id, status, bug_id, attach_id, creation_date,
setter_id, requestee_id) setter_id, requestee_id)
VALUES (?, ?, ?, ?, ?, ?, ?)", undef, VALUES (?, ?, ?, ?, ?, ?, ?)", undef,
($ftypeid, $status, $bugid, $attachid, $timestamp, ($ftype->id, $status, $bugid, $attachid, $timestamp,
$setter_id, $requestee_id)); $setter_id, $requestee_id));
} }
else { else {
......
...@@ -198,14 +198,10 @@ sub queue { ...@@ -198,14 +198,10 @@ sub queue {
if (defined $form_type && !grep($form_type eq $_, ("", "all"))) { if (defined $form_type && !grep($form_type eq $_, ("", "all"))) {
# Check if any matching types are for attachments. If not, don't show # Check if any matching types are for attachments. If not, don't show
# the attachment column in the report. # the attachment column in the report.
my $types = Bugzilla::FlagType::match({ 'name' => $form_type }); my $has_attachment_type =
my $has_attachment_type = 0; Bugzilla::FlagType::count({ 'name' => $form_type,
foreach my $type (@$types) { 'target_type' => 'attachment' });
if ($type->{'target_type'} eq "attachment") {
$has_attachment_type = 1;
last;
}
}
if (!$has_attachment_type) { push(@excluded_columns, 'attachment') } if (!$has_attachment_type) { push(@excluded_columns, 'attachment') }
my $quoted_form_type = $dbh->quote($form_type); my $quoted_form_type = $dbh->quote($form_type);
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
%] %]
<p> <p>
There are [% flag_count %] flags of type [% name FILTER html %]. There are [% flag_type.flag_count %] flags of type [% name FILTER html %].
If you delete this type, those flags will also be deleted. Note that If you delete this type, those flags will also be deleted. Note that
instead of deleting the type you can instead of deleting the type you can
<a href="editflagtypes.cgi?action=deactivate&amp;id=[% flag_type.id %]">deactivate it</a>, <a href="editflagtypes.cgi?action=deactivate&amp;id=[% flag_type.id %]">deactivate it</a>,
......
...@@ -192,7 +192,7 @@ ...@@ -192,7 +192,7 @@
<td> <td>
the group allowed to grant/deny flags of this type the group allowed to grant/deny flags of this type
(to allow all users to grant/deny these flags, select no group)<br> (to allow all users to grant/deny these flags, select no group)<br>
[% PROCESS select selname = "grant_gid" %] [% PROCESS select selname = "grant_group" %]
</td> </td>
</tr> </tr>
...@@ -202,7 +202,7 @@ ...@@ -202,7 +202,7 @@
if flags of this type are requestable, the group allowed to request them if flags of this type are requestable, the group allowed to request them
(to allow all users to request these flags, select no group)<br> (to allow all users to request these flags, select no group)<br>
Note that the request group alone has no effect if the grant group is not defined!<br> Note that the request group alone has no effect if the grant group is not defined!<br>
[% PROCESS select selname = "request_gid" %] [% PROCESS select selname = "request_group" %]
</td> </td>
</tr> </tr>
...@@ -232,7 +232,8 @@ ...@@ -232,7 +232,8 @@
<option value="">(no group)</option> <option value="">(no group)</option>
[% FOREACH group = groups %] [% FOREACH group = groups %]
<option value="[% group.name FILTER html %]" <option value="[% group.name FILTER html %]"
[% " selected" IF type.${selname} == group.name %]>[% group.name FILTER html %] [% " selected" IF (type.${selname} && type.${selname}.name == group.name) %]>
[%- group.name FILTER html %]
</option> </option>
[% END %] [% END %]
</select> </select>
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<p> <p>
You can restrict the list of flag types to those available for a given product You can restrict the list of flag types to those available for a given product
and component. If a product is selected with no component, only flag types and component. If a product is selected with no component, only flag types
which are available to ALL components of the product are shown. which are available to at least one component of the product are shown.
</p> </p>
<form action="editflagtypes.cgi" method="get"> <form action="editflagtypes.cgi" method="get">
...@@ -59,8 +59,8 @@ ...@@ -59,8 +59,8 @@
<tr> <tr>
<th><label for="product">Product:</label></th> <th><label for="product">Product:</label></th>
<td> <td>
<select name="product" onchange="selectProduct(this.form, 'product', 'component', '__All__');"> <select name="product" onchange="selectProduct(this.form, 'product', 'component', '__Any__');">
<option value="">__All__</option> <option value="">__Any__</option>
[% FOREACH prod = products %] [% FOREACH prod = products %]
<option value="[% prod.name FILTER html %]" <option value="[% prod.name FILTER html %]"
[% " selected" IF selected_product == prod.name %]> [% " selected" IF selected_product == prod.name %]>
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
<th><label for="component">Component:</label></th> <th><label for="component">Component:</label></th>
<td> <td>
<select name="component"> <select name="component">
<option value="">__All__</option> <option value="">__Any__</option>
[% FOREACH comp = components %] [% FOREACH comp = components %]
<option value="[% comp FILTER html %]" <option value="[% comp FILTER html %]"
[% " selected" IF selected_component == comp %]> [% " selected" IF selected_component == comp %]>
...@@ -152,8 +152,8 @@ ...@@ -152,8 +152,8 @@
<span class="multiplicable">multiplicable</span> <span class="multiplicable">multiplicable</span>
[% END %] [% END %]
</td> </td>
<td>[% type.grant_group_name FILTER html %]</td> <td>[% IF type.grant_group %][% type.grant_group.name FILTER html %][% END %]</td>
<td>[% type.request_group_name FILTER html %]</td> <td>[% IF type.request_group %][% type.request_group.name FILTER html %][% END %]</td>
<td> <td>
<a href="editflagtypes.cgi?action=copy&amp;id=[% type.id %]">Copy</a> <a href="editflagtypes.cgi?action=copy&amp;id=[% type.id %]">Copy</a>
| <a href="editflagtypes.cgi?action=confirmdelete&amp;id=[% type.id %]" | <a href="editflagtypes.cgi?action=confirmdelete&amp;id=[% type.id %]"
......
...@@ -527,7 +527,7 @@ ...@@ -527,7 +527,7 @@
], ],
'admin/flag-type/confirm-delete.html.tmpl' => [ 'admin/flag-type/confirm-delete.html.tmpl' => [
'flag_count', 'flag_type.flag_count',
'flag_type.id', 'flag_type.id',
], ],
......
...@@ -227,10 +227,6 @@ ...@@ -227,10 +227,6 @@
[% END %] [% END %]
is invalid. is invalid.
[% ELSIF error == "flag_type_id_invalid" %]
The flag type ID <em>[% id FILTER html %]</em> is not
a positive integer.
[% ELSIF error == "flag_type_inactive" %] [% ELSIF error == "flag_type_inactive" %]
[% title = "Inactive Flag Types" %] [% title = "Inactive Flag Types" %]
Some flag types are inactive and cannot be used to create new flags. Some flag types are inactive and cannot be used to create new flags.
......
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