From b9915abd8c37fd3c48a84ab8463c9765b6e20814 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Tue, 11 Jun 2013 21:54:27 +0800 Subject: Bug 860810: Add a default search to new users' saved searches that appear in the footer --- extensions/BMO/Extension.pm | 49 +++++++++++++++++++++++++++++++++++++++++++++ extensions/BMO/lib/Data.pm | 11 +++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) (limited to 'extensions') 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; -- cgit v1.2.3-24-g4f1b