diff options
author | Byron Jones <bjones@mozilla.com> | 2013-06-11 15:54:27 +0200 |
---|---|---|
committer | Byron Jones <bjones@mozilla.com> | 2013-06-11 15:54:27 +0200 |
commit | b9915abd8c37fd3c48a84ab8463c9765b6e20814 (patch) | |
tree | ae9ca8ea2375f9021da027582bcfc6d8d0e9767f /extensions/BMO | |
parent | 66a43117a9e24a81c03ad2200f3f8d586cfa17fa (diff) | |
download | bugzilla-b9915abd8c37fd3c48a84ab8463c9765b6e20814.tar.gz bugzilla-b9915abd8c37fd3c48a84ab8463c9765b6e20814.tar.xz |
Bug 860810: Add a default search to new users' saved searches that appear in the footer
Diffstat (limited to 'extensions/BMO')
-rw-r--r-- | extensions/BMO/Extension.pm | 49 | ||||
-rw-r--r-- | extensions/BMO/lib/Data.pm | 11 |
2 files changed, 59 insertions, 1 deletions
diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index 311c3fe6a..4f4e4e82d 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -631,6 +631,55 @@ sub object_end_of_create_validators { } } +sub object_end_of_create { + my ($self, $args) = @_; + if ($args->{class} eq 'Bugzilla::User') { + # Add default searches to new user's footer + my $dbh = Bugzilla->dbh; + my $user = $args->{object}; + + my $sharer = Bugzilla::User->new({ name => 'nobody@mozilla.org' }) + or return; + my $group = Bugzilla::Group->new({ name => 'everyone' }) + or return; + + foreach my $definition (@default_named_queries) { + my ($namedquery_id) = _get_named_query($sharer->id, $group->id, $definition); + $dbh->do( + "INSERT INTO namedqueries_link_in_footer(namedquery_id,user_id) VALUES (?,?)", + undef, + $namedquery_id, $user->id + ); + } + } +} + +sub _get_named_query { + my ($sharer_id, $group_id, $definition) = @_; + my $dbh = Bugzilla->dbh; + # find existing namedquery + my ($namedquery_id) = $dbh->selectrow_array( + "SELECT id FROM namedqueries WHERE userid=? AND name=?", + undef, + $sharer_id, $definition->{name} + ); + return $namedquery_id if $namedquery_id; + # create namedquery + $dbh->do( + "INSERT INTO namedqueries(userid,name,query) VALUES (?,?,?)", + undef, + $sharer_id, $definition->{name}, $definition->{query} + ); + $namedquery_id = $dbh->bz_last_key(); + # and share it + $dbh->do( + "INSERT INTO namedquery_group_map(namedquery_id,group_id) VALUES (?,?)", + undef, + $namedquery_id, $group_id, + ); + return $namedquery_id; +} + # Automatically CC users to bugs based on group & product sub bug_end_of_create { my ($self, $args) = @_; diff --git a/extensions/BMO/lib/Data.pm b/extensions/BMO/lib/Data.pm index 3b0e94e5f..ff88b8ef7 100644 --- a/extensions/BMO/lib/Data.pm +++ b/extensions/BMO/lib/Data.pm @@ -38,7 +38,8 @@ our @EXPORT = qw( $cf_visible_in_products @always_fileable_groups %group_auto_cc %product_sec_groups - %create_bug_formats ); + %create_bug_formats + @default_named_queries ); # Which custom fields are visible in which products and components. # @@ -475,4 +476,12 @@ our %create_bug_formats = ( }, ); +# List of named queries which will be added to new users' footer +our @default_named_queries = ( + { + name => 'Bugs Filed Today', + query => 'query_format=advanced&chfieldto=Now&chfield=[Bug creation]&chfieldfrom=-24h&order=bug_id', + }, +); + 1; |