Commit dee2aa71 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 967883: modify_keywords() shouldn't throw an error when an unprivileged user…

Bug 967883: modify_keywords() shouldn't throw an error when an unprivileged user doesn't alter the keywords list r=gerv a=justdave
parent 017ef4f7
...@@ -2782,31 +2782,23 @@ sub add_comment { ...@@ -2782,31 +2782,23 @@ sub add_comment {
push(@{$self->{added_comments}}, $params); push(@{$self->{added_comments}}, $params);
} }
# There was a lot of duplicate code when I wrote this as three separate
# functions, so I just combined them all into one. This is also easier for
# process_bug to use.
sub modify_keywords { sub modify_keywords {
my ($self, $keywords, $action) = @_; my ($self, $keywords, $action) = @_;
$action ||= 'set'; if (!$action || !grep { $action eq $_ } qw(add remove set)) {
if (!grep($action eq $_, qw(add remove set))) {
$action = 'set'; $action = 'set';
} }
$keywords = $self->_check_keywords($keywords); $keywords = $self->_check_keywords($keywords);
my @old_keywords = @{ $self->keyword_objects };
my @result;
my (@result, $any_changes);
if ($action eq 'set') { if ($action eq 'set') {
@result = @$keywords; @result = @$keywords;
# Check if anything was added or removed.
my @old_ids = map { $_->id } @{$self->keyword_objects};
my @new_ids = map { $_->id } @result;
my ($removed, $added) = diff_arrays(\@old_ids, \@new_ids);
$any_changes = scalar @$removed || scalar @$added;
} }
else { else {
# We're adding or deleting specific keywords. # We're adding or deleting specific keywords.
my %keys = map {$_->id => $_} @{$self->keyword_objects}; my %keys = map { $_->id => $_ } @old_keywords;
if ($action eq 'add') { if ($action eq 'add') {
$keys{$_->id} = $_ foreach @$keywords; $keys{$_->id} = $_ foreach @$keywords;
} }
...@@ -2814,8 +2806,14 @@ sub modify_keywords { ...@@ -2814,8 +2806,14 @@ sub modify_keywords {
delete $keys{$_->id} foreach @$keywords; delete $keys{$_->id} foreach @$keywords;
} }
@result = values %keys; @result = values %keys;
$any_changes = scalar @$keywords;
} }
# Check if anything was added or removed.
my @old_ids = map { $_->id } @old_keywords;
my @new_ids = map { $_->id } @result;
my ($removed, $added) = diff_arrays(\@old_ids, \@new_ids);
my $any_changes = scalar @$removed || scalar @$added;
# Make sure we retain the sort order. # Make sure we retain the sort order.
@result = sort {lc($a->name) cmp lc($b->name)} @result; @result = sort {lc($a->name) cmp lc($b->name)} @result;
......
...@@ -872,13 +872,13 @@ ...@@ -872,13 +872,13 @@
[% title = "Not allowed" %] [% title = "Not allowed" %]
You tried to change the You tried to change the
<strong>[% field_descs.$field FILTER html %]</strong> field <strong>[% field_descs.$field FILTER html %]</strong> field
[% IF oldvalue.defined %] [% IF oldvalue.defined AND oldvalue != "" %]
from <em>[% oldvalue.join(', ') FILTER html %]</em> from <em>[% oldvalue.join(', ') FILTER html %]</em>
[% END %] [% END %]
[% IF newvalue.defined %] [% IF newvalue.defined AND newvalue != "" %]
to <em>[% newvalue.join(', ') FILTER html %]</em> to <em>[% newvalue.join(', ') FILTER html %]</em>
[% END %] [% END %],
, but only but only
[% IF privs < constants.PRIVILEGES_REQUIRED_EMPOWERED %] [% IF privs < constants.PRIVILEGES_REQUIRED_EMPOWERED %]
the assignee the assignee
[% IF privs < constants.PRIVILEGES_REQUIRED_ASSIGNEE %] or reporter [% END %] [% IF privs < constants.PRIVILEGES_REQUIRED_ASSIGNEE %] or reporter [% END %]
......
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