Allow to clear flags by trigger

3col
Vitaliy Filippov 2014-12-29 16:30:37 +03:00
parent d138086c51
commit b6917c7f08
4 changed files with 27 additions and 5 deletions

View File

@ -3046,7 +3046,7 @@ sub flags
{
my $self = shift;
# Don't cache it as it must be in sync with ->flag_types.
# FIXME (Is it true?) Don't cache it as it must be in sync with ->flag_types.
$self->{flags} = [ map { @{$_->{flags}} } @{$self->flag_types} ];
return $self->{flags};
}

View File

@ -177,7 +177,7 @@ sub except_fields
# { field_name => value }
# Change field 'field_name' to 'value'. For multivalued fields field_name may also
# by 'add_<field_name>' or 'remove_<field_name>', which means add or remove something.
# FIXME Now the only function supported is 'add_cc'
# FIXME Now the only functions supported are 'add_cc' and 'clear_flags'
sub triggers
{
my $self = shift;

View File

@ -249,15 +249,32 @@ sub run_triggers
my $checker = $bug->{failed_checkers}->[$i];
if ($checker->triggers)
{
# FIXME Only "add CC" and "clear flag" triggers are supported by now, but it's not that hard to support more
if ($checker->triggers->{add_cc})
{
# FIXME Only "add CC" trigger is supported by now, but it's not that hard to support more
for (split /[\s,]+/, $checker->triggers->{add_cc})
{
$bug->add_cc($_);
$modified = 1;
}
}
if ($checker->triggers->{clear_flags})
{
my %del_flags = map { $_ => 1 } split /[\s,]*,+[\s,]*/, $checker->triggers->{clear_flags};
for my $flag (@{$bug->flags})
{
if ($del_flags{$flag->name})
{
$bug->make_dirty;
Bugzilla::Flag->set_flag($bug, {
id => $flag->id,
status => 'X',
requestee => $flag->requestee && $flag->requestee->login,
});
$modified = 1;
}
}
}
}
# FIXME Show information about the applied trigger (use result_messages)
splice @{$bug->{failed_checkers}}, $i, 1;

View File

@ -156,6 +156,10 @@
<th>Добавить CC:</th>
<td><input type="text" id="triggers_add_cc" name="triggers_add_cc" value="[% checker.triggers.add_cc | html %]" /></td>
</tr>
<tr>
<th>Снять флаги (через ,):</th>
<td><input type="text" id="triggers_clear_flags" name="triggers_clear_flags" value="[% checker.triggers.clear_flags | html %]" /></td>
</tr>
</tbody>
<tbody>
<tr><td></td><td><input type="submit" value=" Сохранить " /></td></tr>
@ -204,9 +208,10 @@ function check_trigger()
{
var f = document.getElementById('is_trigger').checked;
var cc = document.getElementById('triggers_add_cc');
var fl = document.getElementById('triggers_clear_flags');
if (!f)
cc.value = '';
else if (!cc.value)
cc.value = fl.value = '';
else if (!cc.value && !fl.value)
{
alert('Задайте действие триггера!');
return false;