]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1568695 - Allow to use merge date pronouns with changed before/after operator
authorKohei Yoshino <kohei.yoshino@gmail.com>
Fri, 2 Aug 2019 20:21:55 +0000 (16:21 -0400)
committerGitHub <noreply@github.com>
Fri, 2 Aug 2019 20:21:55 +0000 (16:21 -0400)
Bugzilla/Hook.pm
Bugzilla/Search.pm
Bugzilla/WebService/Constants.pm
extensions/BMO/Extension.pm
template/en/default/global/user-error.html.tmpl

index 22b15c876b9292d66a7bac95e91b37f97fd5e402..172ff905af29ef2853b08028a5d87fd6838a2135 100644 (file)
@@ -597,19 +597,18 @@ Params:
 
 =back
 
-=head2 search_timestamp_translate
+=head2 search_date_pronoun
 
-This happens in L<Bugzilla::Search/_timestamp_translate> and allows you to
-support pronouns for specific dates, such as a product release date. Check the
-`value` argument and replace it with actual date where needed.
+This happens in L<Bugzilla::Search/SqlifyDate> and allows you to support
+pronouns for specific dates, such as a product release date. Pronouns must be
+quoted with percent signs like C<%LAST_RELEASE_DATE%>.
 
 Params:
 
 =over
 
-=item C<search> - The L<Bugzilla::Search> object.
-
-=item C<args> - The original arguments including C<value>.
+=item C<pronoun> - A capitalized pronoun without percent signs can be found in
+the C<name>. Add an actual date back to the C<date> if it's a supported pronoun.
 
 =back
 
index 8155192f1defc30ba889b866bce3c07c8183fa2e..19b18b30a384c5149c12afeb19b7163d90c7a6da 100644 (file)
@@ -2257,11 +2257,7 @@ sub _timestamp_translate {
   my $value = $args->{value};
   my $dbh   = Bugzilla->dbh;
 
-  # Allow to support custom date pronouns
-  Bugzilla::Hook::process('search_timestamp_translate',
-    {search => $self, args => $args});
-
-  return if $value !~ /^(?:[\+\-]?\d+[hdwmy]s?|now)$/i;
+  return if $value !~ /^(?:[\+\-]?\d+[hdwmy]s?|now)$/i && $value !~ /^%\w+%$/;
 
   $value = SqlifyDate($value);
 
@@ -2306,6 +2302,16 @@ sub SqlifyDate {
     return sprintf("%4d-%02d-%02d 00:00:00", $year + 1900, $month + 1, $mday);
   }
 
+  # Allow to support custom date pronouns
+  if ($str =~ /^%(\w+)%$/) {
+    my $pronoun = {name => uc($1)};
+    Bugzilla::Hook::process('search_date_pronoun', {pronoun => $pronoun});
+    unless ($pronoun->{date}) {
+      ThrowUserError('illegal_date_pronoun', {pronoun => $str});
+    }
+    return $pronoun->{date};
+  }
+
   if ($str =~ /^(-|\+)?(\d+)([hdwmy])(s?)$/i) {    # relative date
     my ($sign, $amount, $unit, $startof, $date) = ($1, $2, lc $3, lc $4, time);
     my ($sec, $min, $hour, $mday, $month, $year, $wday) = localtime($date);
index 502db62d3ec7480724afe71ca1af56313ff6a878..7198dac2c9da3c36cf636858a6d1fcbbf646417d 100644 (file)
@@ -70,6 +70,7 @@ use constant WS_ERROR_CODE => {
   number_too_large      => 54,
   number_too_small      => 55,
   illegal_date          => 56,
+  illegal_date_pronoun  => 57,
 
   # Bug errors usually occupy the 100-200 range.
   improper_bug_id_field_value => 100,
index 89120d62e1631b6c518cfb54684793cbda975972..4c3430ffbe9eb09911a62c38323c0f7a1e5bd99a 100644 (file)
@@ -2738,18 +2738,16 @@ sub search_params_to_data_structure {
 
 # Allow to use Firefox release date pronouns, including `%LAST_MERGE_DATE%`,
 # `%LAST_RELEASE_DATE%` and `%LAST_SOFTFREEZE_DATE%`.
-sub search_timestamp_translate {
+sub search_date_pronoun {
   my ($self, $args) = @_;
-  $args = $args->{args};
-  my $key = uc($args->{value});
-  $key =~ s/^%([A-Z_]+)%$/$1/;
+  my $pronoun = $args->{pronoun};
+  my $key = $pronoun->{name};
   my $keys = ['LAST_MERGE_DATE', 'LAST_RELEASE_DATE', 'LAST_SOFTFREEZE_DATE'];
   return unless grep(/^$key$/, @$keys);
 
   my $date = _fetch_product_version_file('firefox')->{$key};
   ThrowUserError('product_date_pronouns_unavailable') unless $date;
-  $args->{value}  = $date;
-  $args->{quoted} = Bugzilla->dbh->quote($date);
+  $pronoun->{date} = $date;
 }
 
 sub tf_buglist_columns {
index eaca85822489a43bb968e90ee493742df4978513..b6aeeb054a7305fe657a5df39fca606e54a11338 100644 (file)
       Please use the format '<tt>[% format FILTER html %]</tt>'.
     [% END %]
 
+  [% ELSIF error == "illegal_date_pronoun" %]
+    [% title = "Illegal Date Pronoun" %]
+    '<code>[% pronoun FILTER html %]</code>' is not a legal date pronoun.
+
   [% ELSIF error == "illegal_email_address" %]
     [% title = "Invalid Email Address" %]
     The e-mail address you entered (<b>[% addr FILTER html %]</b>)