Commit f90a0b77 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 348518: grant / reject options for flag listbox should only appear if user…

Bug 348518: grant / reject options for flag listbox should only appear if user is a member of grantgroup - Patch by Frédéric Buclin <LpSolit@gmail.com> r/a=myk
parent 0fccdb26
...@@ -416,15 +416,12 @@ sub _validate { ...@@ -416,15 +416,12 @@ sub _validate {
} }
# Throw an error if the user won't be allowed to set the flag. # Throw an error if the user won't be allowed to set the flag.
if ($flag_type->grant_group $requestee->can_set_flag($flag_type)
&& !$requestee->in_group_id($flag_type->grant_group->id)) || ThrowUserError('flag_requestee_needs_privs',
{
ThrowUserError('flag_requestee_needs_privs',
{'requestee' => $requestee, {'requestee' => $requestee,
'flagtype' => $flag_type}); 'flagtype' => $flag_type});
} }
} }
}
# Make sure the user is authorized to modify flags, see bug 180879 # Make sure the user is authorized to modify flags, see bug 180879
# - The flag exists and is unchanged. # - The flag exists and is unchanged.
...@@ -433,12 +430,10 @@ sub _validate { ...@@ -433,12 +430,10 @@ sub _validate {
# - User in the request_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.
return if (($status eq 'X' || $status eq '?') return if (($status eq 'X' || $status eq '?')
&& (!$flag_type->request_group && $user->can_request_flag($flag_type));
|| $user->in_group_id($flag_type->request_group->id)));
# - User in the grant_group can set/clear flags, including "+" and "-". # - User in the grant_group can set/clear flags, including "+" and "-".
return if (!$flag_type->grant_group return if $user->can_set_flag($flag_type);
|| $user->in_group_id($flag_type->grant_group->id));
# - Any other flag modification is denied # - Any other flag modification is denied
ThrowUserError('flag_update_denied', ThrowUserError('flag_update_denied',
......
...@@ -642,6 +642,21 @@ sub get_enterable_products { ...@@ -642,6 +642,21 @@ sub get_enterable_products {
return $self->{enterable_products}; return $self->{enterable_products};
} }
sub can_request_flag {
my ($self, $flag_type) = @_;
return ($self->can_set_flag($flag_type)
|| !$flag_type->request_group
|| $self->in_group_id($flag_type->request_group->id)) ? 1 : 0;
}
sub can_set_flag {
my ($self, $flag_type) = @_;
return (!$flag_type->grant_group
|| $self->in_group_id($flag_type->grant_group->id)) ? 1 : 0;
}
# visible_groups_inherited returns a reference to a list of all the groups # visible_groups_inherited returns a reference to a list of all the groups
# whose members are visible to this user. # whose members are visible to this user.
sub visible_groups_inherited { sub visible_groups_inherited {
...@@ -1741,6 +1756,24 @@ method should be called in such a case to force reresolution of these groups. ...@@ -1741,6 +1756,24 @@ method should be called in such a case to force reresolution of these groups.
Returns: an array of product objects. Returns: an array of product objects.
=item C<can_request_flag($flag_type)>
Description: Checks whether the user can request flags of the given type.
Params: $flag_type - a Bugzilla::FlagType object.
Returns: 1 if the user can request flags of the given type,
0 otherwise.
=item C<can_set_flag($flag_type)>
Description: Checks whether the user can set flags of the given type.
Params: $flag_type - a Bugzilla::FlagType object.
Returns: 1 if the user can set flags of the given type,
0 otherwise.
=item C<get_userlist> =item C<get_userlist>
Returns a reference to an array of users. The array is populated with hashrefs Returns a reference to an array of users. The array is populated with hashrefs
......
...@@ -104,11 +104,18 @@ ...@@ -104,11 +104,18 @@
<select id="flag-[% flag.id %]" name="flag-[% flag.id %]" <select id="flag-[% flag.id %]" name="flag-[% flag.id %]"
title="[% type.description FILTER html %]" title="[% type.description FILTER html %]"
onchange="toggleRequesteeField(this);"> onchange="toggleRequesteeField(this);">
<option value="X"></option> [%# Only display statuses the user is allowed to set. %]
[% IF type.is_active %] [% IF type.is_active %]
[% IF user.can_request_flag(type) %]
<option value="X"></option>
[% END %]
[% IF user.can_set_flag(type) || flag.status == "+" %]
<option value="+" [% "selected" IF flag.status == "+" %]>+</option> <option value="+" [% "selected" IF flag.status == "+" %]>+</option>
[% END %]
[% IF user.can_set_flag(type) || flag.status == "-" %]
<option value="-" [% "selected" IF flag.status == "-" %]>-</option> <option value="-" [% "selected" IF flag.status == "-" %]>-</option>
[% IF type.is_requestable || flag.status == "?" %] [% END %]
[% IF (type.is_requestable && user.can_request_flag(type)) || flag.status == "?" %]
<option value="?" [% "selected" IF flag.status == "?" %]>?</option> <option value="?" [% "selected" IF flag.status == "?" %]>?</option>
[% END %] [% END %]
[% ELSE %] [% ELSE %]
...@@ -146,11 +153,14 @@ ...@@ -146,11 +153,14 @@
<td> <td>
<select id="flag_type-[% type.id %]" name="flag_type-[% type.id %]" <select id="flag_type-[% type.id %]" name="flag_type-[% type.id %]"
title="[% type.description FILTER html %]" title="[% type.description FILTER html %]"
[% " disabled=\"disabled\"" UNLESS user.can_request_flag(type) %]
onchange="toggleRequesteeField(this);"> onchange="toggleRequesteeField(this);">
<option value="X"></option> <option value="X"></option>
[% IF user.can_set_flag(type) %]
<option value="+">+</option> <option value="+">+</option>
<option value="-">-</option> <option value="-">-</option>
[% IF type.is_requestable %] [% END %]
[% IF type.is_requestable && user.can_request_flag(type) %]
<option value="?">?</option> <option value="?">?</option>
[% END %] [% END %]
</select> </select>
...@@ -186,11 +196,14 @@ ...@@ -186,11 +196,14 @@
<td> <td>
<select id="flag_type-[% type.id %]" name="flag_type-[% type.id %]" <select id="flag_type-[% type.id %]" name="flag_type-[% type.id %]"
title="[% type.description FILTER html %]" title="[% type.description FILTER html %]"
[% " disabled=\"disabled\"" UNLESS user.can_request_flag(type) %]
onchange="toggleRequesteeField(this);"> onchange="toggleRequesteeField(this);">
<option value="X"></option> <option value="X"></option>
[% IF user.can_set_flag(type) %]
<option value="+">+</option> <option value="+">+</option>
<option value="-">-</option> <option value="-">-</option>
[% IF type.is_requestable %] [% END %]
[% IF type.is_requestable && user.can_request_flag(type) %]
<option value="?">?</option> <option value="?">?</option>
[% END %] [% END %]
</select> </select>
......
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