From 5db6eeb9cf4bf82d785dd193703b46b2139247e5 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Tue, 21 Apr 2015 14:00:18 +0800 Subject: Bug 579089: Change default Hardware / OS values to be "Unspecified/Unspecified" --- Bugzilla/Bug.pm | 13 ++- Bugzilla/UserAgent.pm | 4 +- Bugzilla/WebService/Product.pm | 3 + enter_bug.cgi | 10 +- extensions/BMO/Extension.pm | 120 +++++++++++++++++++-- .../params/editparams-current_panel.html.tmpl | 16 ++- .../hook/admin/products/edit-common-rows.html.tmpl | 35 ++++++ .../hook/admin/products/updated-changes.html.tmpl | 14 +++ .../default/hook/bug/edit-after_op_sys.html.tmpl | 45 ++++++++ .../template/en/default/bug_modal/edit.html.tmpl | 8 ++ .../template/en/default/guided/guided.html.tmpl | 2 - extensions/GuidedBugEntry/web/js/guided.js | 15 +-- template/en/default/bug/create/create.html.tmpl | 53 +++++---- template/en/default/bug/edit.html.tmpl | 2 + 14 files changed, 283 insertions(+), 57 deletions(-) create mode 100644 extensions/BMO/template/en/default/hook/admin/products/edit-common-rows.html.tmpl create mode 100644 extensions/BMO/template/en/default/hook/admin/products/updated-changes.html.tmpl create mode 100644 extensions/BMO/template/en/default/hook/bug/edit-after_op_sys.html.tmpl diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index e1f533274..6dbcffe34 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -702,10 +702,15 @@ sub create { unless defined $params->{bug_severity}; $params->{priority} = Bugzilla->params->{defaultpriority} unless defined $params->{priority}; - $params->{op_sys} = Bugzilla->params->{defaultopsys} - unless defined $params->{op_sys}; - $params->{rep_platform} = Bugzilla->params->{defaultplatform} - unless defined $params->{rep_platform}; + + # BMO - per-product hw/os defaults + if (!defined $params->{rep_platform} || !defined $params->{op_sys}) { + if (my $product = Bugzilla::Product->new({ name => $params->{product}, cache => 1 })) { + $params->{rep_platform} //= $product->default_product; + $params->{op_sys} //= $product->default_op_sys; + } + } + # Make sure a comment is always defined. $params->{comment} = '' unless defined $params->{comment}; diff --git a/Bugzilla/UserAgent.pm b/Bugzilla/UserAgent.pm index 62d6115a9..9c8686f0c 100644 --- a/Bugzilla/UserAgent.pm +++ b/Bugzilla/UserAgent.pm @@ -183,7 +183,7 @@ use constant OS_MAP => ( ); sub detect_platform { - my $userAgent = $ENV{'HTTP_USER_AGENT'} || ''; + my $userAgent = shift || Bugzilla->cgi->user_agent || ''; my @detected; my $iterator = natatime(2, PLATFORMS_MAP); while (my($re, $ra) = $iterator->()) { @@ -195,7 +195,7 @@ sub detect_platform { } sub detect_op_sys { - my $userAgent = $ENV{'HTTP_USER_AGENT'} || ''; + my $userAgent = shift || Bugzilla->cgi->user_agent || ''; my @detected; my $iterator = natatime(2, OS_MAP); while (my($re, $ra) = $iterator->()) { diff --git a/Bugzilla/WebService/Product.pm b/Bugzilla/WebService/Product.pm index be082c778..b7484327f 100644 --- a/Bugzilla/WebService/Product.pm +++ b/Bugzilla/WebService/Product.pm @@ -202,6 +202,9 @@ sub _product_to_hash { $self->_milestone_to_hash($_, $params) } @{$product->milestones}]; } + # BMO - add default hw/os + $field_data->{default_platform} = $self->type('string', $product->default_platform); + $field_data->{default_op_sys} = $self->type('string', $product->default_op_sys); return filter($params, $field_data); } diff --git a/enter_bug.cgi b/enter_bug.cgi index 171b4566f..56f1061c8 100755 --- a/enter_bug.cgi +++ b/enter_bug.cgi @@ -313,10 +313,12 @@ else { $default{'component_'} = formvalue('component'); $default{'priority'} = formvalue('priority', Bugzilla->params->{'defaultpriority'}); $default{'bug_severity'} = formvalue('bug_severity', Bugzilla->params->{'defaultseverity'}); - $default{'rep_platform'} = formvalue('rep_platform', - Bugzilla->params->{'defaultplatform'} || detect_platform()); - $default{'op_sys'} = formvalue('op_sys', - Bugzilla->params->{'defaultopsys'} || detect_op_sys()); + + # BMO - use per-product default hw/os + $default{'rep_platform'} = formvalue('rep_platform', $product->default_platform // detect_platform()); + $default{'op_sys'} = formvalue('op_sys', $product->default_op_sys // detect_op_sys()); + $vars->{'rep_platform'} = detect_platform(); + $vars->{'rep_op_sys'} = detect_op_sys(); $vars->{'alias'} = formvalue('alias'); $vars->{'short_desc'} = formvalue('short_desc'); diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index 06c07cc83..717f347de 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -31,12 +31,13 @@ use Bugzilla::Error; use Bugzilla::Field; use Bugzilla::Field::Choice; use Bugzilla::Group; +use Bugzilla::Install::Filesystem; use Bugzilla::Mailer; use Bugzilla::Product; use Bugzilla::Status; use Bugzilla::Token; -use Bugzilla::Install::Filesystem; use Bugzilla::User; +use Bugzilla::UserAgent qw(detect_platform detect_op_sys); use Bugzilla::User::Setting; use Bugzilla::Util; @@ -62,12 +63,17 @@ our $VERSION = '0.1'; # BEGIN { - *Bugzilla::Bug::last_closed_date = \&_last_closed_date; - *Bugzilla::Product::default_security_group = \&_default_security_group; - *Bugzilla::Product::default_security_group_obj = \&_default_security_group_obj; - *Bugzilla::Product::group_always_settable = \&_group_always_settable; + *Bugzilla::Bug::last_closed_date = \&_last_closed_date; + *Bugzilla::Bug::reporters_hw_os = \&_bug_reporters_hw_os; + *Bugzilla::Product::default_security_group = \&_default_security_group; + *Bugzilla::Product::default_security_group_obj = \&_default_security_group_obj; + *Bugzilla::Product::group_always_settable = \&_group_always_settable; + *Bugzilla::Product::default_platform_id = \&_product_default_platform_id; + *Bugzilla::Product::default_op_sys_id = \&_product_default_op_sys_id; + *Bugzilla::Product::default_platform = \&_product_default_platform; + *Bugzilla::Product::default_op_sys = \&_product_default_op_sys; *Bugzilla::check_default_product_security_group = \&_check_default_product_security_group; - *Bugzilla::Attachment::is_bounty_attachment = \&_is_bounty_attachment; + *Bugzilla::Attachment::is_bounty_attachment = \&_is_bounty_attachment; } sub template_before_process { @@ -641,6 +647,43 @@ sub quicksearch_map { } } +sub object_columns { + my ($self, $args) = @_; + return unless $args->{class}->isa('Bugzilla::Product'); + push @{ $args->{columns} }, qw( default_platform_id default_op_sys_id ); +} + +sub object_update_columns { + my ($self, $args) = @_; + return unless $args->{object}->isa('Bugzilla::Product'); + push @{ $args->{columns} }, qw( default_platform_id default_op_sys_id ); +} + +sub object_before_create { + my ($self, $args) = @_; + return unless $args->{class}->isa('Bugzilla::Product'); + + my $cgi = Bugzilla->cgi; + my $params = $args->{params}; + foreach my $field (qw( default_platform_id default_op_sys_id )) { + $params->{$field} = $cgi->param($field); + } +} + +sub object_end_of_set_all { + my ($self, $args) = @_; + my $object = $args->{object}; + return unless $object->isa('Bugzilla::Product'); + + my $cgi = Bugzilla->cgi; + my $params = $args->{params}; + foreach my $field (qw( default_platform_id default_op_sys_id )) { + my $value = $cgi->param($field); + detaint_natural($value); + $object->set($field, $value); + } +} + sub object_end_of_create { my ($self, $args) = @_; my $class = $args->{class}; @@ -675,6 +718,52 @@ sub object_end_of_create { } } +sub _bug_reporters_hw_os { + my ($self) = @_; + return $self->{ua_hw_os} if exists $self->{ua_hw_os}; + my $memcached = Bugzilla->memcached; + my $hw_os = $memcached->get({ key => 'bug.ua.' . $self->id }); + if (!$hw_os) { + (my $ua) = Bugzilla->dbh->selectrow_array( + "SELECT user_agent FROM bug_user_agent WHERE bug_id = ?", + undef, + $self->id); + $hw_os = $ua + ? [ detect_platform($ua), detect_op_sys($ua) ] + : []; + $memcached->set({ key => 'bug.ua.' . $self->id, value => $hw_os }); + } + return $self->{ua_hw_os} = $hw_os; +} + +sub _product_default_platform_id { $_[0]->{default_platform_id} } +sub _product_default_op_sys_id { $_[0]->{default_op_sys_id} } + +sub _product_default_platform { + my ($self) = @_; + if (!exists $self->{default_platform}) { + $self->{default_platform} = $self->default_platform_id + ? Bugzilla::Field::Choice + ->type('rep_platform') + ->new($_[0]->{default_platform_id}) + ->name + : undef; + } + return $self->{default_platform}; +} +sub _product_default_op_sys { + my ($self) = @_; + if (!exists $self->{default_op_sys}) { + $self->{default_op_sys} = $self->default_op_sys_id + ? Bugzilla::Field::Choice + ->type('op_sys') + ->new($_[0]->{default_op_sys_id}) + ->name + : undef; + } + return $self->{default_op_sys}; +} + sub _get_named_query { my ($sharer_id, $group_id, $definition) = @_; my $dbh = Bugzilla->dbh; @@ -701,11 +790,11 @@ sub _get_named_query { return $namedquery_id; } -# Automatically CC users to bugs based on group & product sub bug_end_of_create { my ($self, $args) = @_; my $bug = $args->{'bug'}; + # automatically CC users to bugs based on group & product foreach my $group_name (keys %group_auto_cc) { my $group_obj = Bugzilla::Group->new({ name => $group_name }); if ($group_obj && $bug->in_group($group_obj)) { @@ -717,6 +806,21 @@ sub bug_end_of_create { } } } + + # store user-agent + if (my $ua = Bugzilla->cgi->user_agent) { + trick_taint($ua); + Bugzilla->dbh->do( + "INSERT INTO bug_user_agent (bug_id, user_agent) VALUES (?, ?)", + undef, + $bug->id, $ua + ); + } +} + +sub db_sanitize { + print "deleting reporter's user-agents...\n"; + Bugzilla->dbh->do("TRUNCATE TABLE bug_user_agent"); } # bugs in an ASSIGNED state must be assigned to a real person @@ -872,7 +976,7 @@ sub db_schema_abstract_schema { REFERENCES => { TABLE => 'bugs', COLUMN => 'bug_id', - DELETE => 'cascade', + DELETE => 'CASCADE', }, }, user_agent => { diff --git a/extensions/BMO/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl b/extensions/BMO/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl index 39f063464..9b251431c 100644 --- a/extensions/BMO/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl +++ b/extensions/BMO/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl @@ -6,8 +6,14 @@ # defined by the Mozilla Public License, v. 2.0. #%] -[% IF panel.name == "groupsecurity" %] - [% panel.param_descs.delete_comments_group = - 'The name of the group of users who can delete comments by using the "deleted" comment tag.' - %] -[% END -%] +[% +IF panel.name == "groupsecurity"; + panel.param_descs.delete_comments_group = + 'The name of the group of users who can delete comments by using the "deleted" comment tag.'; + +ELSIF panel.name == "bugfields"; + panel.param_descs.defaultplatform = "This parameter is ignored on BMO, use per-product defaults instead."; + panel.param_descs.defaultopsys = "This parameter is ignored on BMO, use per-product defaults instead."; + +END; +%] diff --git a/extensions/BMO/template/en/default/hook/admin/products/edit-common-rows.html.tmpl b/extensions/BMO/template/en/default/hook/admin/products/edit-common-rows.html.tmpl new file mode 100644 index 000000000..7093bcfc6 --- /dev/null +++ b/extensions/BMO/template/en/default/hook/admin/products/edit-common-rows.html.tmpl @@ -0,0 +1,35 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + + + Default Platform + + [% INCLUDE default_select + field_name = 'default_platform_id' + field_value = product.default_platform_id + field_values = bug_fields.rep_platform.legal_values + %] + [%= INCLUDE default_select + field_name = 'default_op_sys_id' + field_value = product.default_op_sys_id + field_values = bug_fields.op_sys.legal_values + %] + + + +[% BLOCK default_select %] + +[% END %] diff --git a/extensions/BMO/template/en/default/hook/admin/products/updated-changes.html.tmpl b/extensions/BMO/template/en/default/hook/admin/products/updated-changes.html.tmpl new file mode 100644 index 000000000..af480134e --- /dev/null +++ b/extensions/BMO/template/en/default/hook/admin/products/updated-changes.html.tmpl @@ -0,0 +1,14 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + +[% IF changes.default_platform_id.defined %] +

Default Platform updated

+[% END %] +[% IF changes.default_op_sys_id.defined %] +

Default Op-Sys updated

+[% END %] diff --git a/extensions/BMO/template/en/default/hook/bug/edit-after_op_sys.html.tmpl b/extensions/BMO/template/en/default/hook/bug/edit-after_op_sys.html.tmpl new file mode 100644 index 000000000..b5c3a722b --- /dev/null +++ b/extensions/BMO/template/en/default/hook/bug/edit-after_op_sys.html.tmpl @@ -0,0 +1,45 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + +[%# because the "from reporter" button adds likely unnecessary noise to a bug, + # we only show it on unconfirmed or untriaged bugs %] +[% + RETURN UNLESS + (bug.status.value == "UNCONFIRMED" || bug.component == "Untriaged") + && bug.check_can_change_field('op_sys', 0, 1); + hw_os = bug.reporters_hw_os; + RETURN UNLESS hw_os.size; + RETURN IF bug.rep_platform == hw_os.0 && bug.op_sys == hw_os.1; + + title = "Set platform to reporter's: " _ hw_os.0 _ " / " _ hw_os.1; +%] + +[% onclick = BLOCK %] + $('#rep_platform').val('[% hw_os.0 FILTER js FILTER html %]'); + $('#op_sys').val('[% hw_os.1 FILTER js FILTER html %]'); + $('#rep_hw_os').hide(); +[% END %] +[% + IF bug_modal; + INCLUDE modal; + ELSE; + INCLUDE classic; + END; +%] + +[% BLOCK classic %] + + (from reporter) + +[% END %] + +[% BLOCK modal %] + +[% END %] diff --git a/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl index 75f4747ea..3f6330423 100644 --- a/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl @@ -9,6 +9,8 @@ [% USE Bugzilla; + bug_modal = 1; + # only edit one bug UNLESS bug.defined; bug = bugs.0; @@ -620,6 +622,12 @@ field_type = constants.FIELD_TYPE_SINGLE_SELECT inline = 1 %] + [% WRAPPER bug_modal/field.html.tmpl + container = 1 + inline = 1 + %] + [% Hook.process("after_op_sys", 'bug/edit.html.tmpl') %] + [% END %] [% END %] [%# keywords %] diff --git a/extensions/GuidedBugEntry/template/en/default/guided/guided.html.tmpl b/extensions/GuidedBugEntry/template/en/default/guided/guided.html.tmpl index c3119810b..47614a636 100644 --- a/extensions/GuidedBugEntry/template/en/default/guided/guided.html.tmpl +++ b/extensions/GuidedBugEntry/template/en/default/guided/guided.html.tmpl @@ -55,8 +55,6 @@ YAHOO.util.Dom.removeClass('loading', 'hidden');